PctGL SERIES  
http://pctgl.cnblogs.com
Option Explicit

Private Const PM_REMOVE = &H1  ‘将截获的消息从消息队列移除
Private Type Msg               ‘消息内容结构体
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As Currency ‘原本为 PointAPI 结果体,此处被修改过
End Type

Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private Const WM_LBUTTONDOWN = &H201  ’鼠标左键按下
Private Const WM_LBUTTONUP = &H202    ’鼠标右键松开 本程序弃用它了

Private Sub MsgHook()
Dim MsgType As Msg

Do Until DoEvents = 0
WaitMessage
If PeekMessage(MsgType, hWnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) Then
MsgBox "WM_LBUTTONDOWN"
End If
Loop
End Sub

Private Sub Form_Load()
Show
MsgHook
End Sub

1.
WaitMessage  当某 Hwnd 接收到消息时,则被截获,如为空,则放弃控制权
2.PeekMessage  可获取最后一次某 Hwnd 接收到的消息,自消息队列里面取
3.MsgHook      必须在 Form show 后才可以使用,否则程序会因窗体无循环消息而被
              
WaitMessage 将窗口线程终止。

4.一个简单的子类做出来了,运行试试。。。。鼠标点击一下窗口,弹出了接收的消息的提示
  还算不错吧。
5.这种子类的好处是,不用空等消息的传入,在有消息传入的时候,首先被
WaitMessage
  截获并不发送到执行单元,先由 PeekMessage 自消息队列中取出,加以运算后,根据参数设置,
  是否将
消息返回原地址.
posted on 2009-08-06 14:30  PctGL  阅读(482)  评论(0编辑  收藏  举报