import pymxs, PySide2
rt = pymxs.runtime
##rt.clearListener()
mxsstr = '''
rollout mbtest "Matbuttons"
(
materialButton mb1 "Test1" width:80 height:80 across:2
materialButton mb2 "Test2" width:80 height:80
on mbtest open do
(
mb1.material = Standard name:#MAT_RED diffuse:red
mb2.material = Standard name:#MAT_GRN diffuse:green
)
)
createdialog mbtest width:200
cui.RegisterDialogBar mbtest
'''
print(mxsstr)
rt.execute(mxsstr)
import ctypes, ctypes.wintypes
_LPARAM = ctypes.wintypes.LPARAM
_WPARAM = ctypes.wintypes.WPARAM
_HWND = ctypes.wintypes.HWND
_UINT = ctypes.wintypes.UINT
_LPCWSTR = ctypes.wintypes.LPCWSTR
_LONG_PTR = _LPARAM
_LRESULT = _LONG_PTR
_LPCWSTR = ctypes.wintypes.LPCWSTR
_WNDPROC = ctypes.WINFUNCTYPE(_LRESULT, # return Value
_HWND, # First Param, the handle
_UINT, # second Param, message id
_WPARAM, # third param, additional message info (depends on message id)
_LPARAM, # fourth param, additional message info (depends on message id)
)
_SetWindowLongPtr = ctypes.windll.user32.SetWindowLongPtrA
_SetWindowLongPtr.argtypes = (_HWND, ctypes.c_int, _WNDPROC)
_SetWindowLongPtr.restypes = _WNDPROC
_CallWindowProc = ctypes.windll.user32.CallWindowProcA
_CallWindowProc.argtypes = (_WNDPROC, _HWND, _UINT, _WPARAM, _LPARAM)
_CallWindowProc.restypes = _LRESULT
_DefWindowProc = ctypes.windll.user32.DefWindowProcA
'''
@_WNDPROC
def _WndCallback(hwnd, msg, wparam, lparam):
print(hwnd, msg, wparam, lparam)
return _CallWindowProc(_old_wndproc, hwnd, msg, wparam, lparam)
'''
# constants
GWLP_WNDPROC = -4
WM_COMMAND = 0x0111
class winproc_hook():
def __init__(self, parent_hwnd, child_hwnd = None):
self.window = parent_hwnd
self.control = child_hwnd
# need to hold a reference to WINFUNCTYPE wrappers
self.new_winproc = _WNDPROC(self.winproc_monitor)
self.old_winproc = _WNDPROC(_SetWindowLongPtr(self.window, GWLP_WNDPROC, self.new_winproc))
def winproc_monitor(self, hWnd, uMsg, wParam, lParam):
##print (uMsg,wParam,lParam)
if (uMsg == WM_COMMAND):
return _DefWindowProc(hWnd, uMsg, wParam, lParam)
return _CallWindowProc(self.old_winproc, hWnd, uMsg, wParam, lParam)
maxWindow = PySide2.QtWidgets.QWidget.find(rt.windows.getMaxHWnd())
def procCh(wd):
chArr = wd.children()
for cch in chArr:
if type(cch) == PySide2.QtWidgets.QDockWidget:
if cch.windowTitle() == 'Matbuttons':
return cch
rw = procCh(maxWindow)
for i in rt.mbtest.controls:
chwnd = i.hwnd[0]
print('hwnd:{0} control:{1} (by name >> {2}) mat:{3}'.format(chwnd, i, getattr(rt.mbtest, getattr(i, 'name')) ,getattr(i,'Material')))
##print(''.format(chwnd, i, '==', getattr(rt.mbtest, getattr(i, 'name')) , 'mat:', getattr(i,'Material'))
stuctArr = rw.children()
class CBrowser(PySide2.QtWidgets.QMainWindow):
def __init__(self, parent = maxWindow):
super(CBrowser, self).__init__(parent)
self.setCentralWidget(stuctArr[5])
self.resize(850, 600)
cWindow = CBrowser()
xx = winproc_hook (getattr(rt.mbtest, 'hwnd'))
cWindow.show()
ok... looks like works... must be cleaned, but it's your problem now 😎