API的问题
程序代码:
form1中的代码: Dim WindowHandle As Long Private Sub Form_Click() SendMessage WindowHandle, WM_CLOSE, 0, 0 End Sub Private Sub Form_Load() WindowHandle = FindWindow(vbNullString, "新建 文本文档 - 记事本") Debug.Print WindowHandle pWndProc = GetWindowLong(WindowHandle, GWL_WNDPROC) '获取当前窗口的消息地址 SetWindowLong WindowHandle, GWL_WNDPROC, AddressOf WindowProc '把地址指向模块中的 WindowProc 回调函数 End Sub Private Sub Form_Unload(Cancel As Integer) SetWindowLong WindowHandle, GWL_WNDPROC, pWndProc '不在处理窗体默认的消息时应该返回给系统 End Sub 模块modulel中的代码: Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 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 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 Const WM_CLOSE = &H10 Public Const GWL_WNDPROC = (-4) Public pWndProc As Long '把它当然指针来使用 Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Debug.Print Hex$(Msg) '以十六进制的方式查看当前的消息情况 If Msg = WM_CLOSE Then '处理 WM_CLOSE 窗口关闭消息 WindowProc = 1 Exit Function End If WindowProc = CallWindowProc(pWndProc, hwnd, Msg, wParam, lParam) '把不需要处理的消息返回给系统(是把已处理的消息按 lpPrevWndFunc(原窗口消息地址) 返回给该地址) End Function这个程序怎么拦截不了关闭消息,纠结中,麻烦大家帮忙解答。
[ 本帖最后由 nbaqqqq 于 2010-5-2 11:12 编辑 ]