Persist state between WM_COMMAND and WM_LBUTTONDOWN

I have a question about WM_COMMAND.

Is it possible to change a variable xin case branches for WM_COMMANDto get this new value in case branches for WM_LBUTTONDOWN? I always get 0into branches WM_LBUTTONDOWNand 1into branches WM_COMMAND.

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
{
    int x = 0;
    switch (message)
    {
        case WM_CREATE:
            break;

        case WM_COMMAND:
            x = 1;
            cout << x;
            break;

        case WM_LBUTTONDOWN:
            cout << x;
            break;

        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;

        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}
+4
source share
1 answer

xis a local variable that you initialize to 0 each time it is called WindowProcedure.

Announce xout WindowProcedureor make it static.

+6
source

Source: https://habr.com/ru/post/1692144/


All Articles