dro873
February 14th, 2005, 10:37 PM
I have a very basic question: If I have a modal dialog box with a button(s), does the BN_CLICKED message only work with MFC and the class wizard, or will it work with WinAPI as well?
|
Click to See Complete Forum and Search --> : Button Message in Modal Dialog dro873 February 14th, 2005, 10:37 PM I have a very basic question: If I have a modal dialog box with a button(s), does the BN_CLICKED message only work with MFC and the class wizard, or will it work with WinAPI as well? NoHero February 15th, 2005, 04:01 AM I have a very basic question: If I have a modal dialog box with a button(s), does the BN_CLICKED message only work with MFC and the class wizard, or will it work with WinAPI as well? Hmm... If it works in MFC it will work on WinAPI too, since the MFC is just a wrapper for the WinAPI. LRESULT CALLBACK DlgProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch ( msg ) { case WM_COMMAND: { if ( LOWORD(wParam) == IDC_MYBUTTON ) { // code goes here } } break; } return 0; } Assuming that IDC_MYBUTTON is the ID of the button you created. dro873 February 15th, 2005, 01:01 PM Hmm... If it works in MFC it will work on WinAPI too, since the MFC is just a wrapper for the WinAPI. In that case, I have 2 follow-up questions: 1.) Aren't there some things like ActiveX controls that can only be employed through MFC? 2.) Why won't BN_CLICKED work in my code? Here's the process: BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_COMMAND: switch(LOWORD(wParam)) { case BN_CLICKED: // Do something break; } default: return FALSE: } return TRUE; } The buttons in question are radio button controls. I looked on msdn and the description led me to believe that if the user clicks a radio button, a BN_CLICKED message is sent to its parent window. Unfortunately, the BN_CLICKED message never gets sent :( . It's an easily circumvented problem, but I'd just like to know why it doesn't work. Thanx. NoHero February 16th, 2005, 02:37 AM 1. ActiveX will also work without MFC. MFC makes it only easier to handle this. 2. the lowest word of wParam specifies the ID of the button pressend and the highes word the action to be taken. BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_BUTTON1: // Id of the button if ( HIWORD(wParam) == BN_CLICKED ) { // the button got clicked } break; } default: return FALSE: } return TRUE; } codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |