简体   繁体   English

如何检测非活动 Win32 应用程序中的最小化?

[英]How do I detect minimization in an inactive Win32 app?

My app should always minimize to the system tray, instead of to the task bar.我的应用程序应该始终最小化到系统托盘,而不是任务栏。

To do so, I handle WM_SYSCOMMAND / SC_MINIMIZE :为此,我处理WM_SYSCOMMAND / SC_MINIMIZE

case WM_SYSCOMMAND:
    switch (wParam)
    {
        case SC_MINIMIZE:
            minimizeToTray();
            return FALSE;
        ...

This, however, does not cover events where the window gets minimized without a WM_SYSCOMMAND .但是,这不包括窗口在没有WM_SYSCOMMAND情况下最小化的事件。

For example: I can minimize the window by using Win+D (show desktop).例如:我可以使用Win+D (显示桌面)最小化窗口。

To cover this case, I handle WM_ACTIVATE / WA_INACTIVE :为了涵盖这种情况,我处理WM_ACTIVATE / WA_INACTIVE

case WM_ACTIVATE:
{
    if (LOWORD(wParam) == WA_INACTIVE && HIWORD(wParam) != 0)
    {
        minimizeToTray();
    }
    ...

Which seems to only work if the window is active before showing the desktop.这似乎只有在显示桌面之前窗口处于活动状态时才有效。


Problems:问题:

When the window is already inactive, no WM_ACTIVATE comes in to detect minimization.当窗口已经处于非活动状态时,没有WM_ACTIVATE进来检测最小化。 Which message tells me that the inactive window gets minimized?哪条消息告诉我非活动窗口被最小化?

EDIT: It seems that WM_WINDOWPOSCHANGED is the right place to check if the window is minimized, when it is not active.编辑:似乎WM_WINDOWPOSCHANGED是检查窗口是否最小化的正确位置,当它不活动时。

Furthermore, when I activate some other app that is maximized, fully covering my own app, I also want to minimize to tray, but don't know if there's a message to handle in that case.此外,当我激活其他一些最大化的应用程序,完全覆盖我自己的应用程序时,我也想最小化到托盘,但不知道这种情况下是否有消息要处理。 The high word of the wParam for WM_ACTIVATE is 0 in that case (like it would also be if the window was just deactivated but still visible).在这种情况下, WM_ACTIVATEwParam的高位字为0 (就像窗口刚刚停用但仍然可见时一样)。

调用 IsIconic(hWnd) 以获取当前状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM