BitBlt() experiment

Pages: 12
I'm pretty sure you can't grey out the X.

Also, clicking the X does not send WM_DESTROY, it sends WM_SYSCOMMAND + SC_CLOSE. WM_SYSCOMMAND in turn sends a slew of other messages, each of which may send other messages (somewhere in that process, WM_DESTROY is sent).


I typically do this:

1
2
3
4
5
6
7
8
9
10
// bQuit has a larger scope than this function -- 
//   I also access it in my WndProc
while (!bQuit)
    {
        while(PeekMessage (&messages, NULL, 0, 0,PM_REMOVE))
        {
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
    }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_SYSCOMMAND:
            if(wParam & 0xFFF0 == SC_CLOSE)
            {
                if( you_really_want_to_close_the_program )
                    bQuit = true;
                else  // veto the quit
                    return 0;
            }
            break;

            // no need for WM_DESTROY or WM_QUIT
    }

    // ALWAYS call DefWindowProc -- not just for messages you didn't process
    //  The only time you don't want to call it is if you want to alter the normal behavior
    //  of your window (ie:  stopping the close button from closing it -- which is why I return 0
    //  above to "veto" the window closing)
    return DefWindowProc (hwnd, message, wParam, lParam);
}
closed account (3pj6b7Xj)
beutiful it works! that makes a lot more sense now. When you specify wParam & 0xFFF0 are you directly checking the address at an specific point in wParam for the value SC_CLOSE, that is how I understand that code.

Nevermind, i FOUND the asnwer; In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator.

Thanks for the great help. :)
Last edited on
Glad to hear it's working. =)
Topic archived. No new replies allowed.
Pages: 12