Public Declare Function SetWindowLong Lib "user32" _Īlias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function FindWindow Lib "user32" _Īlias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongĪlias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, _īyVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function SetWindowLongPtr Lib "user32" _Īlias "SetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" _Īlias "SetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr Public Declare Function CallWindowProc Lib "user32" _Īlias "CallWindowProcA" (ByVal lpPrevWndFunc As LongPtr, ByVal hWnd As LongPtr, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare PtrSafe Function FindWindow Lib "user32" _Īlias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr MyWindowProc = CallWindowProc(lPrevWnd, Hwnd, Msg, wParam, ByVal lParam)Īndd finally UserForm1 needs the following code: ' Default handling for messages we have not handled = wParam And &HFFFF ' low wordĬall SetWindowLong(Hwnd, GWL_WNDPROC, lPrevWnd) ' an unhandled error in message loop may crash xl so let's ignore it (normally not best practice)Ĭase WM_ACTIVATE ' sent when window activates OR deactivates
Public Function myWindowProc(ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long