c# – 无法使用pinvoke将WM_CLOSE发送到Windows资源管理器窗口

c# – 无法使用pinvoke将WM_CLOSE发送到Windows资源管理器窗口,第1张

概述我有一个C#应用程序,它使用SendMessage pinvoke方法向应用程序外的各个窗口发送“关闭窗口”消息(WM_CLOSE / 16).这很有效,除非有问题的窗口是 Windows资源管理器窗口.我没有异常,但窗口没有关闭. 这是签名: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] i 我有一个C#应用程序,它使用SendMessage pinvoke方法向应用程序外的各个窗口发送“关闭窗口”消息(WM_CLOSE / 16).这很有效,除非有问题的窗口是 Windows资源管理器窗口.我没有异常,但窗口没有关闭.

这是签名:

[Dllimport("user32.dll",CharSet = CharSet.auto,SetLastError = false)]    internal static extern IntPtr SendMessage(HandleRef hWnd,uint Msg,IntPtr wParam,IntPtr lParam);

我需要将不同的消息发送到windows资源管理器窗口吗?或者另一种方法来实现这一目标?

解决方法 另一种解决方案是使用PostMessage win API调用而不是SendMessage,下面是一个适合我的例子(我正在使用winXP sp3):

[Dllimport("user32.dll",SetLastError = true)]static extern IntPtr FinDWindow(string lpClassname,string lpWindowname);[Dllimport("user32.Dll")]public static extern int PostMessage(IntPtr hWnd,UInt32 msg,int wParam,int lParam);private const UInt32 WM_CLOSE          = 0x0010;...    IntPtr hWnd = FinDWindow("ExploreWClass",null);    if (hWnd.ToInt32()!=0) PostMessage(hWnd,WM_CLOSE,0);

PostMessage和SendMessage API调用之间的差异在这里描述:http://msdn.microsoft.com/en-us/magazine/cc301431.aspx

总结

以上是内存溢出为你收集整理的c# – 无法使用pinvoke将WM_CLOSE发送到Windows资源管理器窗口全部内容,希望文章能够帮你解决c# – 无法使用pinvoke将WM_CLOSE发送到Windows资源管理器窗口所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1221462.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存