3
votes

My app should always minimize to the system tray, instead of to the task bar.

To do so, I handle 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.

For example: I can minimize the window by using Win+D (show desktop).

To cover this case, I handle 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. 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.

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).

1
Huh, seems that Win+D not sending the minimize signal is kind of an oversight on MS part.Bartek Banachewicz
Well yes, that's MS for ya... I'll have to make due with the current state of affairs though.T. J. Evers
Related: What is the difference between Win + D (Show Desktop) and Win + M (Minimize All) keyboard shortcuts in Windows: "When you press Win + M, the OS sends a special message, WM_MINIMIZE, to all windows, and they should get minimized to the taskbar... when you press Win + D, the operating system will hide windows which cannot be minimized"Remy Lebeau

1 Answers

-1
votes

Call IsIconic(hWnd) to get the current state.