保持窗口看起来活跃

发布于 2024-08-15 09:03:43 字数 472 浏览 6 评论 0原文

我正在为辅助监视器开发任务栏。我让它运行得相当好。我还可以使用空气动力学模糊外观。但我的问题可能与航空方面的东西无关。

我想要做的是让我的任务栏窗口始终显示为焦点/激活状态。它不需要真正聚焦或激活,我只是希望它看起来像那样。您只需在应用程序空闲时调用 setforgroundwindow 即可看到我想要的效果。但我不能使用它,因为我真的不希望它像那样抓住焦点。我只是希望它始终保持焦点时的样子。

我尝试过各种 WM_XXX 消息调用,包括捕获和发送,我尝试过 setwindowpos 调用,等等。唯一有效的方法是调用 Mouse_Event(MOUSEEVENTF_LEFTDOWN ,然后调用 Mouse_Event(MOUSEEVENTF_LEFTUP )。虽然我不喜欢这个解决方案,因为它对我想做的事情来说是一个非常俗气的黑客/解决方法。但是使用 Mouse_Event 调用的任何内容本质上都是我只需要在不实际单击我的应用程序或向其发送 Mouse_Event 调用的情况下实现这一点。

I'm working on a taskbar for secondary monitors. I have it working fairly well. I've also got the aero blur look working as well. But my question is probably not related to the aero stuff.

What i want to do is to have my taskbar window to always appear focused/activated. It does not need to actually be focused or activated, I just want it to look that way. You can see the effect I'm after by just putting a setforgroundwindow call in the app idle. But I can't use that as I don't really want it grabbing the focus like that. I just want it to always look the way it does when it does have focus.

I've tried all sorts of WM_XXX message calls, both trapping and sending, I've tried setwindowpos calls, and on and on. The only thing that has worked is calling Mouse_Event(MOUSEEVENTF_LEFTDOWN and then Mouse_Event(MOUSEEVENTF_LEFTUP. I don't like this solution though as it's a really cheesy hack/workaround to what I want to do. But whatever gets called with the Mouse_Event is essentially what I need to make happen only without actually clicking on my app or sending it Mouse_Event calls.

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

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

发布评论

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

评论(1

猫性小仙女 2024-08-22 09:03:43

您没有说明您正在使用什么语言,也没有说明这是托管代码还是非托管代码。

对于 C++ 非托管代码,您只需处理 WM_NCACTIVATE 消息并强制它始终看起来处于活动状态,如下所示:

case WM_NCACTIVATE:
   {
   // wParam tells us whether we are active or inactive, but we are going to ignore
   // that and always pass active down to DefWindowProc so it will draw us active.
   DefWindowProc(hwnd, uMsg, TRUE, lParam);
   //return FALSE; // returning false here prevents actual deactivation
   return TRUE; // return true allows deactivation (even though we draw as active)
   }
   break;

编辑:delphi 代码中的解决方案(从注释中移出以使其更具可读性)

procedure TForm1.WndProc(var Message: TMessage); 
begin inherited; 
  if (Message.Msg = WM_NCACTIVATE) then 
  begin 
    DefWindowProc(handle, Message.Msg, 1, Message.LParam ); 
    Message.Result := 1; 
  end; 
end;

You don't say what language you are working in or whether this is managed or unmanaged code.

For C++ unmanaged code, you just handle the WM_NCACTIVATE message and force it to always seem active, like this:

case WM_NCACTIVATE:
   {
   // wParam tells us whether we are active or inactive, but we are going to ignore
   // that and always pass active down to DefWindowProc so it will draw us active.
   DefWindowProc(hwnd, uMsg, TRUE, lParam);
   //return FALSE; // returning false here prevents actual deactivation
   return TRUE; // return true allows deactivation (even though we draw as active)
   }
   break;

edit: the solution in delphi code (moved from comment to make it more readable)

procedure TForm1.WndProc(var Message: TMessage); 
begin inherited; 
  if (Message.Msg = WM_NCACTIVATE) then 
  begin 
    DefWindowProc(handle, Message.Msg, 1, Message.LParam ); 
    Message.Result := 1; 
  end; 
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文