稍微麻烦一点。以下代码什么消息都能处理<br><br>主题:VB中消息的处理<br>建一模块,把以下代码放入模块中:<br>Option Explicit<br><br>Private Const GWL_WNDPROC = -4<br>Public Const GWL_USERDATA = (-21)<br>Public Const WM_SIZE = &H5<br>Public Const WM_USER = &H400<br>Public Const WM_GETMINMAXINFO = &H24<br><br>Type POINTAPI<br> x As Long<br> y As Long<br>End Type<br><br>Type MINMAXINFO<br> ptReserved As POINTAPI<br> ptMaxSize As POINTAPI<br> ptMaxPosition As POINTAPI<br> ptMinTrackSize As POINTAPI<br> ptMaxTrackSize As POINTAPI<br>End Type<br><br>Private Declare Function CallWindowProc Lib "user32" Alias _<br> "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _<br> ByVal hwnd As Long, ByVal Msg As Long, _<br> ByVal wParam As Long, ByVal lParam As Long) As Long<br><br>Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _<br> (ByVal hwnd As Long, ByVal nIndex As Long) As Long<br>Private Declare Function SetWindowLong Lib "user32" Alias _<br> "SetWindowLongA" (ByVal hwnd As Long, _<br> ByVal nIndex As Long, ByVal dwNewLong As Long) As Long<br>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<br>Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)<br> <br>Public Function Hook(ByVal hwnd As Long) As Long<br> Dim pOld As Long<br> '指定自定义的窗口过程<br> pOld = SetWindowLong(hwnd, GWL_WNDPROC, _<br> AddressOf WindowProc)<br> '保存原来默认的窗口过程指针<br> SetWindowLong hwnd, GWL_USERDATA, pOld<br> Hook = pOld<br>End Function<br><br>Public Sub Unhook(ByVal hwnd As Long, ByVal lpWndProc As Long)<br> Dim temp As Long<br> 'Cease subclassing.<br> temp = SetWindowLong(hwnd, GWL_WNDPROC, lpWndProc)<br>End Sub<br><br>Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _<br> ByVal wParam As Long, ByVal lParam As Long) As Long<br> If uMsg = WM_SIZE Then<br> '处理WM_SIZE消息<br> 'MsgBox "SIZE"<br> End If<br> If uMsg = WM_USER + 1 Then<br> MsgBox wParam<br> End If<br> <br> If uMsg = WM_GETMINMAXINFO Then '你的设置在这个if 中进行<br> Dim MinMax As MINMAXINFO<br> <br> CopyMemory MinMax, ByVal lParam, Len(MinMax)<br> MinMax.ptMinTrackSize.x = 3975 / Screen.TwipsPerPixelX<br> MinMax.ptMinTrackSize.y = 1740 / Screen.TwipsPerPixelY<br> MinMax.ptMaxTrackSize.x = Screen.Width / Screen.TwipsPerPixelX / 2<br> MinMax.ptMaxTrackSize.y = 3480 / Screen.TwipsPerPixelY<br> CopyMemory ByVal lParam, MinMax, Len(MinMax)<br> WindowProc = 1<br> Exit Function<br> End If<br> <br> Dim lpPrevWndProc As Long<br> '查询原来默认的窗口过程指针<br> lpPrevWndProc = GetWindowLong(hw, GWL_USERDATA)<br> '调用原来的窗口过程<br> WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)<br>End Function<br><br><br>Form单元中:<br><br>Option Explicit<br>Dim wParam As Long<br> Dim lParam As Long<br> Dim lResult As Long<br><br>Private Sub Command1_Click()<br> wParam = 12345<br> lResult = SendMessage(Me.hwnd, WM_USER + 1, wParam, lParam)<br> End Sub<br><br> Private Sub Form_Load()<br> Me.Tag = Hook(Me.hwnd)<br> End Sub<br> Private Sub Form_Unload(Cancel As Integer)<br> Unhook Me.hwnd, Me.Tag<br> End Sub<br><br>