| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1264 人关注过本帖
标题:急!用Hook获取Windows系统消息WM_PASTE出错
只看楼主 加入收藏
dyh2222
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-1-22
收藏
 问题点数:0 回复次数:0 
急!用Hook获取Windows系统消息WM_PASTE出错
模块代码如下:
Imports System.Runtime.InteropServices
Module modGetWinMsg
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As GetWinMsgDelete, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer

Private Declare Function CallNextHookEx Lib "user32" Alias "CallNextHookEx" (ByVal hHook As Integer, ByVal ncode As Integer, ByVal wParam As Integer, ByVal lParam As MSG) As Integer

Private Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal hHook As Integer) As Integer

Private Const WH_GETMESSAGE As Integer = 3

Private Const WM_PASTE As Integer = &H302

Dim hRet As Integer

Public Structure MSG
Public hwnd As Integer
Public message As Integer
Public wParam As Integer
Public lParam As Integer
Public time As Integer
Public pt As POINTAPI
End Structure

Public Structure POINTAPI
Private x As Integer
Private y As Integer
End Structure

Private Delegate Function GetWinMsgDelete(ByVal nCode As Integer, _
ByVal wParam As Integer, _
ByVal lParam As MSG) As Integer
Private Function proGetWinMsg(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As MSG) As Integer
Debug.WriteLine("Message Callback. Code=" & nCode)
If nCode = 0 Then
If lParam.message = WM_PASTE Then
MessageBox.Show("asdfsad")
Return 1
End If
Return CallNextHookEx(hRet, nCode, wParam, lParam)
End If
End Function
Public Sub GetMsg()
hRet = SetWindowsHookEx(WH_GETMESSAGE, AddressOf proGetWinMsg, Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
End Sub
Public Sub Unhook()
If hRet <> 0 Then
UnhookWindowsHookEx(hRet)
hRet = 0
End If
End Sub
End Module
窗体代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GetMsg()
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Unhook()
End Sub
但是却总是捕捉不到WM_PASTE消息,这是为什么?
搜索更多相关主题的帖子: 系统 获取 Windows Hook PASTE 
2006-01-22 13:51
快速回复:急!用Hook获取Windows系统消息WM_PASTE出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012707 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved