如果应用程序设置为默认 Windows 桌面 Shell,为什么我的 WndProc 收不到 Shell Hook 消息?
uMsgNotify = WinApi.RegisterWindowMessage("SHELLHOOK");
WinApi.RegisterShellHookWindow(this.Handle);
在我的 Form 构造函数中
,在我重写的 WndProc 中:
protected override void WndProc(ref System.Windows.Forms.Message m)
{
IntPtr handle;
if (m.Msg == uMsgNotify)
{
switch (m.WParam.ToInt32())
{
case WinApi.HSHELL_WINDOWCREATED:
handle = m.LParam;
string windowName = GetWindowName(handle);
MessageBox.Show(windowName+" "+handle.ToString());
break;
case WinApi.HSHELL_WINDOWDESTROYED:
handle = m.LParam;
MessageBox.Show(handle.ToString());
break;
}
}
base.WndProc(ref m);
}
所以当默认的 Windows shell 是 explorer.exe 时,这个 Win Form 可以正常工作。我可以获得所有事件所有创建和销毁的窗口及其名称。当我将 app.exe 设置为默认 Windows Shell 时。它不接收消息。
我是否必须使用 dll 函数注入、单独的 dll 文件进行挂钩? 我试图获得更简单、更容易的解决方案。
有什么想法吗?
谢谢
uMsgNotify = WinApi.RegisterWindowMessage("SHELLHOOK");
WinApi.RegisterShellHookWindow(this.Handle);
in my Form constructor
and this in my overrided WndProc:
protected override void WndProc(ref System.Windows.Forms.Message m)
{
IntPtr handle;
if (m.Msg == uMsgNotify)
{
switch (m.WParam.ToInt32())
{
case WinApi.HSHELL_WINDOWCREATED:
handle = m.LParam;
string windowName = GetWindowName(handle);
MessageBox.Show(windowName+" "+handle.ToString());
break;
case WinApi.HSHELL_WINDOWDESTROYED:
handle = m.LParam;
MessageBox.Show(handle.ToString());
break;
}
}
base.WndProc(ref m);
}
So this Win Form Works fine when default windows shell is explorer.exe. I can get all events All created and destroyed windows and their names. When i set my app.exe as defaul windows Shell. It doesn't receive messages.
Do I have to use dll function injection, separate dll file for hooking?
I was trying to get simplier and easier solution.
Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WH_SHELL
文档明确指出:The
WH_SHELL
documentation explicitly states: