向 WPF 应用程序发送消息

发布于 2024-11-06 08:08:35 字数 627 浏览 0 评论 0原文

我正在尝试向 WPF 应用程序发送消息以使其最小化,然后恢复

我正在执行的操作

//Import the SetForeground API to activate it
[DllImportAttribute("User32.dll")]
private static extern IntPtr SetForegroundWindow(int hWnd);

[DllImportAttribute("User32.dll")]
//private static extern IntPtr SendMessage(int hWnd, int Msg, bool wParam, int lParam);
private static extern IntPtr SendMessage(int hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
....


 SetForegroundWindow(hWnd); //Activate it

 //in here I minimize the window manually
 SendMessage(hWnd, 0x0018, (UIntPtr)0, (IntPtr)0); //trying to restore

不起作用

任何想法

I am trying to send a message to a WPF application to have it Minimize and then to restore

I am doing

//Import the SetForeground API to activate it
[DllImportAttribute("User32.dll")]
private static extern IntPtr SetForegroundWindow(int hWnd);

[DllImportAttribute("User32.dll")]
//private static extern IntPtr SendMessage(int hWnd, int Msg, bool wParam, int lParam);
private static extern IntPtr SendMessage(int hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
....


 SetForegroundWindow(hWnd); //Activate it

 //in here I minimize the window manually
 SendMessage(hWnd, 0x0018, (UIntPtr)0, (IntPtr)0); //trying to restore

it does not work

Any ideas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2024-11-13 08:08:35

您可能最好导入 ShowWindow 而不是仅导入 SendMessage:

[DllImportAttribute("User32.dll")] 
private static extern IntPtr ShowWindow(int hWnd, int showFlag);

public const int SW_MINIMIZE = 0x06;
pubilc const int SW_RESTORE = 0x09;
public const int SW_FORCEMINIMIZE = 0x0B;

然后您应该可以说 ShowWindow(hWnd, SW_MINIMIZE); 等。

You're probably better off importing ShowWindow rather than just SendMessage:

[DllImportAttribute("User32.dll")] 
private static extern IntPtr ShowWindow(int hWnd, int showFlag);

public const int SW_MINIMIZE = 0x06;
pubilc const int SW_RESTORE = 0x09;
public const int SW_FORCEMINIMIZE = 0x0B;

You should then just be able to say ShowWindow(hWnd, SW_MINIMIZE); etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文