ON_CONTROL_RANGE and BN_PUSHED
-
Darn, sometimes something that should be easy gets complicated. I have a modeless dialog that send messages to its parent window. These are WM_COMMAND messages for BN_CLICKED, BN_PUSHED, and BN_UNPUSHED. e.g.
GetParent()->SendMessage(WM_COMMAND,(WPARAM)(BN_PUSHED<<16|nID),0);
To the parent window's message map I have added the entries:
ON_CONTROL_RANGE(BN_CLICKED,ID_0,ID_N,OnClickX)
ON_CONTROL_RANGE(BN_PUSHED,ID_0,ID_N,OnPushedX)
ON_CONTROL_RANGE(BN_UNPUSHED,ID_0,ID_N,OnUnpushedX)However, OnClickX is called to for BN_CLICKED, BN_PUSHED, and BN_UNPUSHED. I walked through with the debugger and the correct message is sent (WM_COMMAND with BN_CLICKED, BN_PUSHED, or BN_CLICKED) but the wrong handler is invoked. (I stopped short of trying to walk through the CCmdTarget's use of the message map (that is some seriously ugly code to walk through.) in the hope that someone will have some knowledge here. Am I doing something wrong? missing something here? I tried changing the order of the message map entries in case there was a problem
-
Darn, sometimes something that should be easy gets complicated. I have a modeless dialog that send messages to its parent window. These are WM_COMMAND messages for BN_CLICKED, BN_PUSHED, and BN_UNPUSHED. e.g.
GetParent()->SendMessage(WM_COMMAND,(WPARAM)(BN_PUSHED<<16|nID),0);
To the parent window's message map I have added the entries:
ON_CONTROL_RANGE(BN_CLICKED,ID_0,ID_N,OnClickX)
ON_CONTROL_RANGE(BN_PUSHED,ID_0,ID_N,OnPushedX)
ON_CONTROL_RANGE(BN_UNPUSHED,ID_0,ID_N,OnUnpushedX)However, OnClickX is called to for BN_CLICKED, BN_PUSHED, and BN_UNPUSHED. I walked through with the debugger and the correct message is sent (WM_COMMAND with BN_CLICKED, BN_PUSHED, or BN_CLICKED) but the wrong handler is invoked. (I stopped short of trying to walk through the CCmdTarget's use of the message map (that is some seriously ugly code to walk through.) in the hope that someone will have some knowledge here. Am I doing something wrong? missing something here? I tried changing the order of the message map entries in case there was a problem
Ah, I found the problem. If I didn't pass the button's window handle in the lParam, then the CWnd's OnCommand handler, zeros the nCode parameter, effectively making everything into a BN_CLICKED. So I need to do:
GetParent()->SendMessage(WM_COMMAND,(WPARAM)(BN_PUSHED<<16|nID),hBtn);
Should I have known that? (i.e. what purpose does that zeroing serve in OnCommand?)