WH_CALLWNDPROC and WH_CALLWNDPROCRET HooksThe WH_CALLWNDPROC and WH_CALLWNDPROCRET hooks enable you to monitor messages sent to window procedures. The system calls a WH_CALLWNDPROC hook procedure before passing the message to the receiving window procedure, and calls the WH_CALLWNDPROCRET hook procedure after the window procedure has processed the message.The WH_CALLWNDPROCRET hook passes a pointer to a CWPRETSTRUCT structure to the hook procedure. The structure contains the return value from the window procedure that processed the message, as well as the message parameters associated with the message. Subclassing the window does not work for messages set between processes.For more information, see the CallWndProc and CallWndRetProc functions. 抱歉,似乎没有 无法使用全局钩子捕获到WH_CALLWNDPROC消息 的描述 ... ..
全局勾子还有这个限制? 我去查查MSDN看看
发现有对Clipboard操作时,先getforeground得到当前活动窗体的句柄HWND,
最后枚举所有的进程进行比较,找到后显示操作Clipboard的文件的路径
System.Diagnostics.Process[] pro=System.Diagnostics.Process.GetProcesses();
foreach(System.Diagnostics.Process p1 in pro)
{
if (p1.MainWindowHandle==HWND)
{
MessageBox.Show(p1.MainModule.FileName);
}
}
不会吧?
用全局钩子,就要用要DLL,你是用 C#写 DLL 还是 C++?
4楼的朋友提供的思路我正在尝试中,非常感谢你!
{ //MessageBox.Show(Clipboard.GetText()); textBox1.Text += Clipboard.GetText() + "\n"; }
protected override void WndProc(ref Message m)
{ if (m.Msg != 0)
textBox2.Text = m.Msg.ToString(); const int WM_DRAWCLPBORAD = 0x308; const int WM_CHANGCBCHAIN = 0X030D; //if (!textBox2.Text.Contains(m.Msg.ToString()))
// textBox2.Text = m.Msg.ToString(); switch (m.Msg)
{ case WM_DRAWCLPBORAD: if (Clipboard.ContainsText())
{//包含文本格式 ShowNotify(); }
SendMessage(hNextClipboardViewer, m.Msg, m.WParam, m.LParam); break; case WM_CHANGCBCHAIN: if (hNextClipboardViewer == m.WParam)
{//更新要发送消息的下一个窗口的句柄 hNextClipboardViewer = m.LParam; } else
{ SendMessage(hNextClipboardViewer, m.Msg, m.WParam, m.LParam); } break; case 0x46:
//string[] strs = Clipboard.GetData(DataFormats.FileDrop) as string[];
//if (strs != null)
//textBox1.Text += (Clipboard.GetData(DataFormats.FileDrop) as string[])[0];
//if (strs != null)
// foreach (string i in strs)
// {
// //if (!textBox1.Text.Contains(i))
// textBox1.Text += i + "\n";
// } break; default: base.WndProc(ref m); break; } }
//textBox1.Text += (Clipboard.GetData(DataFormats.FileDrop) as string[])[0];
//if (strs != null)
// foreach (string i in strs)
// {
// //if (!textBox1.Text.Contains(i))
// textBox1.Text += i + "\n";
// }
取消注释可以实现部分功能。只是有些缺点。没解决。希望楼主看了帮忙解决下
//string[] strs = Clipboard.GetData(DataFormats.FileDrop) as string[];
//if (strs != null)
//textBox1.Text += (Clipboard.GetData(DataFormats.FileDrop) as string[])[0];
//if (strs != null)
// foreach (string i in strs)
// {
// //if (!textBox1.Text.Contains(i))
// textBox1.Text += i + "\n";
// }
string[] strs = Clipboard.GetData(DataFormats.FileDrop) as string[];
//if (strs != null)
//textBox1.Text += (Clipboard.GetData(DataFormats.FileDrop) as string[])[0];
if (strs != null)
foreach (string i in strs)
{
if (!textBox1.Text.Contains(i))
textBox1.Text += i + "\n";
}