关于VB中的CallWindowProc函数

Eddy 发布于2009-11-5 20:0:57 分类: 程序设计 已浏览loading 网友评论0条 我要评论

解释:

API Explanation
The CallWindowProc function passes message information to the specified window procedure.

Parameter Information
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

· lpPrevWndFunc
Pointer to the previous window procedure.
If this value is obtained by calling the GetWindowLong function with the nIndex parameter set to GWL_WNDPROC or DWL_DLGPROC, it is actually either the address of a window or dialog box procedure, or a handle representing that address.

· hWnd
Identifies the window procedure to receive the message.

· Msg
Specifies the message.

· wParam
Specifies additional message-specific information. The contents of this parameter depend on the value of the Msg parameter.

· lParam
Specifies additional message-specific information. The contents of this parameter depend on the value of the Msg parameter.

The return value specifies the result of the message processing and depends on the message sent.

代码:

'Create a new project, add a module to it
'Add a command button to Form1
'In the form
Private Sub Form_Load()
'Subclass this form
HookForm Me
'Register this form as a Clipboardviewer
SetClipboardViewer Me.hwnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Unhook the form
UnHookForm Me
End Sub

Private Sub Command1_Click()
'Change the clipboard
Clipboard.Clear
Clipboard.SetText "Hello !"
End Sub

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal _
nIndex As Long, ByVal dwNewLong 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
Declare Function SetClipboardViewer Lib "user32" (ByVal hwnd As Long) As Long
Public Const WM_DRAWCLIPBOARD = &H308
Public Const GWL_WNDPROC = (-4)
Dim PrevProc As Long

Public Sub HookForm(F As Form)   '将窗口的默认例程函数编程自定义的WindowProc
PrevProc = SetWindowLong(F.hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub UnHookForm(F As Form) '还原
SetWindowLong F.hwnd, GWL_WNDPROC, PrevProc
End Sub

Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam)
If uMsg = WM_DRAWCLIPBOARD Then '相应剪贴板内容改变
MsgBox "Clipboard changed ..."
End If
End Function

已经有(0)位网友发表了评论,你也评一评吧!
原创文章如转载,请注明:转载自Eddy Blog
原文地址:http://www.rrgod.com/program/69.html     欢迎订阅Eddy Blog

关于 VB  CallWindowProc  的相关文章

记住我的信息,下次不用再输入 欢迎给Eddy Blog留言