mdeforge
mdeforge

Reputation: 874

Odd conditional statement behavior in my windowProc function

I'm having a strange issue where the switch/case will reach HandleEvent but the message won't reach the appropriate IF statement.

For example, with HandleEvent as it is, my window won't close when I hit the red X. The message will be WM_CLOSE (I checked), but for some reason the if statement isn't handled correctly.

At first I thought the WM_CLOSE case was never being reached, but if I comment out the other cases, it still doesn't work. HOWEVER, if I take out the IF statements for WM_ACTIVATEAPP and WM_SHOWWINDOW, the correct statement will execute. Even if I remove the "else if" and just make them regular IF's it doesn't work either. WHY would the correct not IF statement be selected here? The message is what the message is, you know? I don't understand... it should reach the right one!

LRESULT CALLBACK foo::WindowProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) {

switch(message) {
    case WM_ACTIVATEAPP:
    case WM_SHOWWINDOW:
    case WM_CLOSE:
                // Test for window
        if ((window == fooWindow) && (foo->HandleEvent(message, wparam, lparam)))
        {
            return ( 0 );
        }

        break;
    }

    return DefWindowProcW(window, message, wparam, lparam);
}    

bool foo::HandleEvent(UINT message, WPARAM wparam, LPARAM lparam) {

    if ( message == WM_ACTIVATEAPP ) {
        if ( wparam ) 
        {
            // Stuff
            ShowWindow(fooWindow, SW_RESTORE); 
        } else {
            // Stuff
            ShowWindow(fooWindow, SW_MINIMIZE); 
        }
    } else if ( message = WM_SHOWWINDOW ) {
        if ( wparam ) 
            // Stuff
        else
            // Stuff 
    } else if ( message == WM_CLOSE ) {
        // Stuff
    }

    return (true);
}

Upvotes: 0

Views: 60

Answers (1)

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145359

message = WM_SHOWWINDOW

oops.


A good way to avoid this is to use const.

Sprinkle it liberally all over the code.

Where it's practical to do it.

Upvotes: 2

Related Questions