The principle of sub-classification technology: To get the original window procedure address, record it, and then set all the messages are transferred to the message we write process, we filter the message sent over to find a specific message for processing, the rest of the system, the system decided how to deal with. When we do not need to process these specific messages, we cancel the interception of the message, that is, abort the subcategory process. It generally requires three processes: Start the interception, message processing, stop interception.
The program requires a module, which is declared as follows in the module:
' API functions Declare function SetWindowLong Lib "user32" Alias "Setwindowlonga" _
(ByVal hwnd As Long, ByVal nindex as Long, ByVal Dwnewlong as Long) A 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 constant Public Const GWL_WNDPROC = ( -4) Public Const WM_MOUSEMOVE = &h200 Public Const WM_RBUTTONDOWN = &h204
' global variable, holding control's flag data public Prewinproc as Long
' This function is the public function WndProc of the message that was intercepted when the subcategory was received (ByVal hwnd as Long, ByVal Msg as Long, _
ByVal WParam as Long, ByVal LParam as Long) as
Long
The intercepted message is stored in the MSG parameter.
If Msg=wm_rbuttondown Then
' The right mouse click message is detected, and here we can add our processing code such as:
MsgBox "Hello, mouse right click Message!"
' Note that if you don't add any code here, it's equivalent to eating this message. Else
' If we're not the message we need to process, we'll send it back to the original program.
WndProc = CallWindowProc (Prewinproc, hwnd, MSG, WParam, LParam) endif end Function
++++++++++++++++++++++++++++++++++++++++++++++++++++