如何防止窗口被停用?

发布于 2024-10-19 08:11:12 字数 59 浏览 6 评论 0原文

有什么办法可以防止窗口被停用吗?该窗口的进程与我的不同。

这是针对 Windows 的。

Is there any way to prevent a window from being deactivated? The window is in a different process then mine.

This is for Windows.

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

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

发布评论

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

评论(2

归途 2024-10-26 08:11:12

这样做可能很危险,但解决方案是处理 WM_ACTIVATE 消息并检查 wParam 是否为 WA_INACTIVE。这意味着该窗口已被停用。发生这种情况时,您只需重新激活它即可。

为了对另一个进程的窗口执行此操作,您需要使用 SetWindowsHookEx 安装消息挂钩。

然而,另一个应用程序可能会做同样的事情,使彼此陷入激活/停用的无限循环中。

这也是在个人计算机上运行的软件绝对不应该做的事情。

Doing this can be dangerous, but the solution is to handle the WM_ACTIVATE message and check if the wParam is WA_INACTIVE. This means the window has been deactivated. When this happens, you can just reactivate it.

In order to do this for another process's window, you will need to install a message hook with SetWindowsHookEx.

However, it is possible that another application could do the same thing, putting each other in an endless loop of activation/deactivation.

This is also something that should never be done by software that is meant to run on a personal computer.

牵强ㄟ 2024-10-26 08:11:12

您可以捕获 WM_ACTIVATEAPP 像这样:

protected override void WndProc(ref Message m) {
  // Trap WM_ACTIVATEAPP
  if ((m.Msg == 0x1c) && (m.WParam == IntPtr.Zero))
  {
     // If WM_ACTIVATEAPP and WParam is deactivated, return
     return;
  }
  base.WndProc(ref m);
}

You can trap the WM_ACTIVATEAPP like this:

protected override void WndProc(ref Message m) {
  // Trap WM_ACTIVATEAPP
  if ((m.Msg == 0x1c) && (m.WParam == IntPtr.Zero))
  {
     // If WM_ACTIVATEAPP and WParam is deactivated, return
     return;
  }
  base.WndProc(ref m);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文