WM_NOTIFY and CBN_SELCHANGE

I have recently written a section of code, and was all psyched for the runtime test. during the aforementioned test, though, the section of code was not even called because my app did not realize that my app was notifying it that it had to do something. why doesn't this code work?:
[code]
LRESULT CALLBACK MessageHandlerEnvr( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
int temp;
switch ( msg ) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM_COMMAND:
switch( HIWORD( wParam ) ) {
case CBN_SELCHANGE:
temp = SendMessage( MoveCmbo, CB_GETCURSEL, 0, 0 );

if ( temp != 0 ) {
if ( temp - 1 < myGUI.CurObjIndx() )
myGUI.Move( temp - 1 );
if ( temp - 1 >= myGUI.CurObjIndx() )
myGUI.Move( temp );

// Refill Move:
SendMessage( MoveCmbo, CB_RESETCONTENT, 0, 0 );
SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)" - - - - - - - - - - - - - - - - - " );

temp = myGUI.CurCell().NumObjects();
for ( int i = 0; i < temp; i++ ) {
if ( myGUI.CurCell()[i].Name() != "trap" && i != myGUI.CurObjIndx() )
SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)myGUI.CurCell()[i].Name().c_str() );
}

SendMessage( MoveCmbo, CB_SETCURSEL, 0, 0 );
}
break;
}
break;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
[/code]
Ideally, everything between and is fine ( no build errors or anything ). the only problem is aparrently in triggering the CBN_SELCHANGE event. Any ideas why this would not work?

~[red]PhoeniX[/red]

Comments

  • : I have recently written a section of code, and was all psyched for the runtime test. during the aforementioned test, though, the section of code was not even called because my app did not realize that my app was notifying it that it had to do something. why doesn't this code work?:
    : [code]
    : LRESULT CALLBACK MessageHandlerEnvr( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
    : int temp;
    : switch ( msg ) {
    : case WM_DESTROY:
    : PostQuitMessage(0);
    : return 0;
    : break;
    : case WM_COMMAND:
    : switch( HIWORD( wParam ) ) {
    : case CBN_SELCHANGE:
    : temp = SendMessage( MoveCmbo, CB_GETCURSEL, 0, 0 );
    :
    : if ( temp != 0 ) {
    : if ( temp - 1 < myGUI.CurObjIndx() )
    : myGUI.Move( temp - 1 );
    : if ( temp - 1 >= myGUI.CurObjIndx() )
    : myGUI.Move( temp );
    :
    : // Refill Move:
    : SendMessage( MoveCmbo, CB_RESETCONTENT, 0, 0 );
    : SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)" - - - - - - - - - - - - - - - - - " );
    :
    : temp = myGUI.CurCell().NumObjects();
    : for ( int i = 0; i < temp; i++ ) {
    : if ( myGUI.CurCell()[i].Name() != "trap" && i != myGUI.CurObjIndx() )
    : SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)myGUI.CurCell()[i].Name().c_str() );
    : }
    :
    : SendMessage( MoveCmbo, CB_SETCURSEL, 0, 0 );
    : }
    : break;
    : }
    : break;
    : }
    : return DefWindowProc( hWnd, msg, wParam, lParam );
    : }
    : [/code]
    : Ideally, everything between and is fine ( no build errors or anything ). the only problem is aparrently in triggering the CBN_SELCHANGE event. Any ideas why this would not work?
    :
    : ~[red]PhoeniX[/red]
    :
    [blue]Why you connecting the WM_NOTIFY and CBN_SELCHANGE? They are diff. messages for diff. controls. Also, CBN_SELCHANGE maybe not triggered for a few reasons:

    1. The window whose message proc. you provided here IS NOT an owner of a combo-box you are trying to service here. I do not see where you creating that combo-box.

    2. If that procedure is a dialog procedure, then of course we can assume that Win32 created all controls for you. But, then why call [italic]DefWindowProc()[/italic]? Dialogs do not need that. Also, have you noticed that WM_COMMAND [b]break[/b]s and calls [italic]DefWindowProc()[/italic] in any event?
    [/blue]
  • : : I have recently written a section of code, and was all psyched for the runtime test. during the aforementioned test, though, the section of code was not even called because my app did not realize that my app was notifying it that it had to do something. why doesn't this code work?:
    : : [code]
    : : LRESULT CALLBACK MessageHandlerEnvr( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
    : : int temp;
    : : switch ( msg ) {
    : : case WM_DESTROY:
    : : PostQuitMessage(0);
    : : return 0;
    : : break;
    : : case WM_COMMAND:
    : : switch( HIWORD( wParam ) ) {
    : : case CBN_SELCHANGE:
    : : temp = SendMessage( MoveCmbo, CB_GETCURSEL, 0, 0 );
    : :
    : : if ( temp != 0 ) {
    : : if ( temp - 1 < myGUI.CurObjIndx() )
    : : myGUI.Move( temp - 1 );
    : : if ( temp - 1 >= myGUI.CurObjIndx() )
    : : myGUI.Move( temp );
    : :
    : : // Refill Move:
    : : SendMessage( MoveCmbo, CB_RESETCONTENT, 0, 0 );
    : : SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)" - - - - - - - - - - - - - - - - - " );
    : :
    : : temp = myGUI.CurCell().NumObjects();
    : : for ( int i = 0; i < temp; i++ ) {
    : : if ( myGUI.CurCell()[i].Name() != "trap" && i != myGUI.CurObjIndx() )
    : : SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)myGUI.CurCell()[i].Name().c_str() );
    : : }
    : :
    : : SendMessage( MoveCmbo, CB_SETCURSEL, 0, 0 );
    : : }
    : : break;
    : : }
    : : break;
    : : }
    : : return DefWindowProc( hWnd, msg, wParam, lParam );
    : : }
    : : [/code]
    : : Ideally, everything between and is fine ( no build errors or anything ). the only problem is aparrently in triggering the CBN_SELCHANGE event. Any ideas why this would not work?
    : :
    : : ~[red]PhoeniX[/red]
    : :
    : [blue]Why you connecting the WM_NOTIFY and CBN_SELCHANGE? They are diff. messages for diff. controls. Also, CBN_SELCHANGE maybe not triggered for a few reasons:
    :
    : 1. The window whose message proc. you provided here IS NOT an owner of a combo-box you are trying to service here. I do not see where you creating that combo-box.
    :
    : 2. If that procedure is a dialog procedure, then of course we can assume that Win32 created all controls for you. But, then why call [italic]DefWindowProc()[/italic]? Dialogs do not need that. Also, have you noticed that WM_COMMAND [b]break[/b]s and calls [italic]DefWindowProc()[/italic] in any event?
    : [/blue]

    in the subject line, i didn't mean notify, i meant wm_command. the other thing, defwindowproc(), does it make any difference in whether or not CBN_selchange is called, i don't think it should.
    ~[red]PhoeniX[/red]

  • : : : I have recently written a section of code, and was all psyched for the runtime test. during the aforementioned test, though, the section of code was not even called because my app did not realize that my app was notifying it that it had to do something. why doesn't this code work?:
    : : : [code]
    : : : LRESULT CALLBACK MessageHandlerEnvr( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
    : : : int temp;
    : : : switch ( msg ) {
    : : : case WM_DESTROY:
    : : : PostQuitMessage(0);
    : : : return 0;
    : : : break;
    : : : case WM_COMMAND:
    : : : switch( HIWORD( wParam ) ) {
    : : : case CBN_SELCHANGE:
    : : : temp = SendMessage( MoveCmbo, CB_GETCURSEL, 0, 0 );
    : : :
    : : : if ( temp != 0 ) {
    : : : if ( temp - 1 < myGUI.CurObjIndx() )
    : : : myGUI.Move( temp - 1 );
    : : : if ( temp - 1 >= myGUI.CurObjIndx() )
    : : : myGUI.Move( temp );
    : : :
    : : : // Refill Move:
    : : : SendMessage( MoveCmbo, CB_RESETCONTENT, 0, 0 );
    : : : SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)" - - - - - - - - - - - - - - - - - " );
    : : :
    : : : temp = myGUI.CurCell().NumObjects();
    : : : for ( int i = 0; i < temp; i++ ) {
    : : : if ( myGUI.CurCell()[i].Name() != "trap" && i != myGUI.CurObjIndx() )
    : : : SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)myGUI.CurCell()[i].Name().c_str() );
    : : : }
    : : :
    : : : SendMessage( MoveCmbo, CB_SETCURSEL, 0, 0 );
    : : : }
    : : : break;
    : : : }
    : : : break;
    : : : }
    : : : return DefWindowProc( hWnd, msg, wParam, lParam );
    : : : }
    : : : [/code]
    : : : Ideally, everything between and is fine ( no build errors or anything ). the only problem is aparrently in triggering the CBN_SELCHANGE event. Any ideas why this would not work?
    : : :
    : : : ~[red]PhoeniX[/red]
    : : :
    : : [blue]Why you connecting the WM_NOTIFY and CBN_SELCHANGE? They are diff. messages for diff. controls. Also, CBN_SELCHANGE maybe not triggered for a few reasons:
    : :
    : : 1. The window whose message proc. you provided here IS NOT an owner of a combo-box you are trying to service here. I do not see where you creating that combo-box.
    : :
    : : 2. If that procedure is a dialog procedure, then of course we can assume that Win32 created all controls for you. But, then why call [italic]DefWindowProc()[/italic]? Dialogs do not need that. Also, have you noticed that WM_COMMAND [b]break[/b]s and calls [italic]DefWindowProc()[/italic] in any event?
    : : [/blue]
    :
    : in the subject line, i didn't mean notify, i meant wm_command. the other thing, defwindowproc(), does it make any difference in whether or not CBN_selchange is called, i don't think it should.
    : ~[red]PhoeniX[/red]
    :
    :
    [blue]I see. No, it does not make any diff. - defwindowproc() will just skip the WM_COMMAND - useless call. You should try to debug the code. Also: "if ( temp != 0 ) {" - what is you trying to check here? When the selection does not exist at all temp will be negative. temp==0 will be if the very first item in a list is selected. So, you will go inside that IF() when nothing selected and if selected any item EXCEPT the first one... is this your intention?[/blue]
  • : : : : I have recently written a section of code, and was all psyched for the runtime test. during the aforementioned test, though, the section of code was not even called because my app did not realize that my app was notifying it that it had to do something. why doesn't this code work?:
    : : : : [code]
    : : : : LRESULT CALLBACK MessageHandlerEnvr( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
    : : : : int temp;
    : : : : switch ( msg ) {
    : : : : case WM_DESTROY:
    : : : : PostQuitMessage(0);
    : : : : return 0;
    : : : : break;
    : : : : case WM_COMMAND:
    : : : : switch( HIWORD( wParam ) ) {
    : : : : case CBN_SELCHANGE:
    : : : : temp = SendMessage( MoveCmbo, CB_GETCURSEL, 0, 0 );
    : : : :
    : : : : if ( temp != 0 ) {
    : : : : if ( temp - 1 < myGUI.CurObjIndx() )
    : : : : myGUI.Move( temp - 1 );
    : : : : if ( temp - 1 >= myGUI.CurObjIndx() )
    : : : : myGUI.Move( temp );
    : : : :
    : : : : // Refill Move:
    : : : : SendMessage( MoveCmbo, CB_RESETCONTENT, 0, 0 );
    : : : : SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)" - - - - - - - - - - - - - - - - - " );
    : : : :
    : : : : temp = myGUI.CurCell().NumObjects();
    : : : : for ( int i = 0; i < temp; i++ ) {
    : : : : if ( myGUI.CurCell()[i].Name() != "trap" && i != myGUI.CurObjIndx() )
    : : : : SendMessage( MoveCmbo, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)myGUI.CurCell()[i].Name().c_str() );
    : : : : }
    : : : :
    : : : : SendMessage( MoveCmbo, CB_SETCURSEL, 0, 0 );
    : : : : }
    : : : : break;
    : : : : }
    : : : : break;
    : : : : }
    : : : : return DefWindowProc( hWnd, msg, wParam, lParam );
    : : : : }
    : : : : [/code]
    : : : : Ideally, everything between and is fine ( no build errors or anything ). the only problem is aparrently in triggering the CBN_SELCHANGE event. Any ideas why this would not work?
    : : : :
    : : : : ~[red]PhoeniX[/red]
    : : : :
    : : : [blue]Why you connecting the WM_NOTIFY and CBN_SELCHANGE? They are diff. messages for diff. controls. Also, CBN_SELCHANGE maybe not triggered for a few reasons:
    : : :
    : : : 1. The window whose message proc. you provided here IS NOT an owner of a combo-box you are trying to service here. I do not see where you creating that combo-box.
    : : :
    : : : 2. If that procedure is a dialog procedure, then of course we can assume that Win32 created all controls for you. But, then why call [italic]DefWindowProc()[/italic]? Dialogs do not need that. Also, have you noticed that WM_COMMAND [b]break[/b]s and calls [italic]DefWindowProc()[/italic] in any event?
    : : : [/blue]
    : :
    : : in the subject line, i didn't mean notify, i meant wm_command. the other thing, defwindowproc(), does it make any difference in whether or not CBN_selchange is called, i don't think it should.
    : : ~[red]PhoeniX[/red]
    : :
    : :
    : [blue]I see. No, it does not make any diff. - defwindowproc() will just skip the WM_COMMAND - useless call. You should try to debug the code. Also: "if ( temp != 0 ) {" - what is you trying to check here? When the selection does not exist at all temp will be negative. temp==0 will be if the very first item in a list is selected. So, you will go inside that IF() when nothing selected and if selected any item EXCEPT the first one... is this your intention?[/blue]

    Yes, that's what i'm trying to do. The combo box holds the titles of other objects in the same room as the character. the first item, though, is just " - - - - - - ", so that the user can look at the items in the list, but if they don't want to move anywhere, they can just select that item. Anyway, I have no idea what i did, but i was fiddling around with the code ( clearing up some 'junk' code that was left over from when i tried doing something else differently ) earlier today, and it sporadically started working, so I think i've solved that problem for now. a new problem has become aparrent though. Now, i'm trying to send messages to an edit box, so that it can list messages generated by the game, and i think i found out how to do it, by sifting through the msdn library. the only problem is that when i build, the compilier doesn't know what EDITSTRUCT and other key identifiers are. if i try including richedit.h, though, i get about 70 more errors which exist in the header file itself. I can't figure out how to do it, so if you happen to know how to change the text in the edit box, please help me...it would relieve a lot of stress. Thanks for all your help.
    ~[red]PhoeniX[/red]

  • [blue]Why do you need richedit? Just to be multi-lined?
    You can set that flag into normal edit box and send text
    to it like that:
    [code]
    SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) "Line #1
    ");
    SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) "Line #2
    ");
    SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) "Line #3
    ");
    [/code]That will give three lines in the control.
    [/blue]
  • : [blue]Why do you need richedit? Just to be multi-lined?
    : You can set that flag into normal edit box and send text
    : to it like that:
    : [code]
    : SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) "Line #1
    ");
    : SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) "Line #2
    ");
    : SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) "Line #3
    ");
    : [/code]That will give three lines in the control.
    : [/blue]

    when i need to do something in api, the main source of my information is the msdn library. the only way i could figure out how to do it was by using richedit. I'll try doing it this way. Thanks for all your help...very much appreciated.
    ~[red]PhoeniX[/red]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories