How to receive custom messages in the VB routine

zhaozj2021-02-12  181

How to receive a custom message (Entry Date: 2002.06.08 Read: 2141) reprinted in VB routine unknown Author: unknown

How to receive custom messages in the VB routine You can use the API function setWindowlong to specify the Window Procedure for the Window ProCedure to customize the WindowProc, capture the message ID as a custom message or system message for WM_USER 1. Also, in order to ensure that the window can respond correctly, you need to save the original default window process and call in the custom function WindowProc.

Such as the following example, send custom messages in the button event, WindowProc capture system-defined messages and user-defined messages and display user-defined messages, and add the following code in Moduel, Option Explicit Private Const GWL_WndProc = -4 Public Const GWL_USERDATA = (-21) Public Const WM_SIZE = & H5 Public Const WM_USER = & H400 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 GetWindowLong Lib "user32" Alias ​​"GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias ​​_ "SetWindowLongA" (ByVal hwnd As Long, _ ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function SendMessage Lib "user32" Alias ​​"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, LPARAM AS Any) As long hwnd as long "Specifies custom window process POLD = SETWINDOWL ong (hwnd, GWL_WNDPROC, _ AddressOf WindowProc) 'save the original default window procedure pointer SetWindowLong hwnd, GWL_USERDATA, pOld Hook = pOld End Function Public Sub Unhook (ByVal hwnd As Long, ByVal lpWndProc As Long) Dim temp As Long NOTE: Cease subclassing. temp = SetWindowLong (hwnd, GWL_WNDPROC, lpWndProc) End Sub Function WindowProc (ByVal hw As Long, ByVal uMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long If uMsg = WM_SIZE Then 'process WM_SIZE message MsgBox "Size" end if if umsg = WM_USER

转载请注明原文地址:https://www.9cbs.com/read-6241.html

New Post(0)