What message is sent when you minimize a window?

Viewed 406

I'm catching WindowProc and looking for WM_SYSCOMMAND / SC_MINIMIZE, but it only fires the message when I minimize the window by clicking in its taskbar icon.

When I click in the window's minimize button the message isn't fired.

switch (Msg)
{
case WM_SYSCOMMAND:
    switch (wParam)
    {
    case SC_MINIMIZE:
        {
            OutputDebugStringW(L"Window minimized!");
            //return TRUE;
        }
    }
    break;
}

I noticed that my window was not sending the WM_SIZE message, then while searching i have found this:

By default, the DefWindowProc function sends the WM_SIZE and WM_MOVE messages to the window. The WM_SIZE and WM_MOVE messages are not sent if an application handles the WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient to perform any move or size change processing during the WM_WINDOWPOSCHANGED message without calling DefWindowProc.

I confirmed that its sending WM_WINDOWPOSCHANGED when i try to minimize by clicking in the minimize button.

    case WM_WINDOWPOSCHANGING:

        tagWINDOWPOS * wp    = reinterpret_cast<tagWINDOWPOS *>(lParam);
        wp->x = ...;
        wp->y = ...;
        wp->cx = ...;
        wp->cy = ...;

        LPARAM lp    = reinterpret_cast<LPARAM>(wp);

I have tried to set x, y, cx, cy values to the current ones, but the window still got minimized.

1 Answers

The WM_SIZE message is sent to a window when its size has been changed; if that size change was to minimize the window, then the wParam argument will be SIZE_MINIMIZED. (This WM_SIZE will also be sent after the WM_SYSCOMMAND/SC_MINIMIZE combination, so you can detect the minimize operation, no matter what user action triggered it.)

So, your code in the WndProc would be along these lines:

    switch (Msg) {
        case WM_SIZE:
            switch (wParam) {
                case SIZE_MINIMIZED:
                    OutputDebugStringW(L"Window minimized!");
                //  return TRUE;
                    break;
                //...
            }
            break;

            //...
    }
Related