The principle of sub-classification technology: First get the address where the original window procedure is located, record it, then set all the messages to the message processing we have written, we filter the news, find specific The message is processed, the rest of the return system is determined by the system how to handle it. When we don't need to deal with these specific messages, the interception of the message is canceled, that is, the intercourse classification process.
It usually requires three processes: starting interception, message processing, abort intercept. Program requires a module, declare below the module: 'API function declare function setwindowlong lib "user32" Alias "setwindowlonga" _ (Byval HWnd As Long, Byval Nindex As Long, ByVal dwNewLong As Long) A s Long Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As Long 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 'define the constant Public Const GWL_WNDPROC = (-4) Public Const WM_MOUSEMOVE = & H200 Public Const WM_RBUTTONDOWN = & H204' globally Variables, storage control landmark data public preWinProc as long "Public Function WndProc (Byval Hwnd As Long, Byval WParam As Long, BYVAL LONPARAM As Long, BYVAL LPAR AS Long As long 'intercepted the message stored in the MSG parameter. If msg = wm_rbuttondown life' detected the mouse to the message, here you can join our processing code such as: msgbox "Hello, the mouse right click on the message!" If you don't add any code here, it is equivalent to eating this message. Else 'If we are not the news we need to handle, then send it back to the original program. WndProc = CallWindowProc (PrewinProc, HWND, MSG, WPARAM, LPARAM) Endif End Function 'The following code is in the form:' This example takes a message to intercept a ComboBox control, assume that the name of the 'control is: Comb1 private subduSS () Dim ret As Long 'Window procedure recorded address preWinProc = GetWindowLong (comb1.hwnd, GWL_WNDPROC)' intercepts the message and starts, during the processing and referred wndproc message. ret = SetWindowLong (comb1.hwnd, GWL_WNDPROC, AddressOf wndproc) End Sub Private Sub endsubclass () DIM RET As long 'cancels the message interception, end sub-classification process. Ret = setWindowlong (comb1.hwnd, gwl_wndproc, preWinProc) End sub' When you intercept other controls, you only need to use the subclass and endsubclass process. COMB1.H WND is replaced with the control of the control. HWND can. '