Hello,
I have a strange behaviour in one of my dialogs (c++, VS2005). I have 3 radio buttons that are mutually exclusive.
My dialog refresh function is something like:
void myDialog::refresh()
{
m_button1.SetCheck(getMode()==1);
m_button2.SetCheck(getMode()==2);
m_button3.SetCheck(getMode()==3);
}
The event handler functions ("radio button clicked") look like:
void myDialog::OnBnClickedButton1()
{
setMode(1)
refresh();
}
(similar to the two other functions, except for setMode(2) and setMode(3))
The resource file for the radio buttons looks like:
CONTROL "set mode 1",IDC_BUTTON1,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,277,151,83,10
CONTROL "set mode 2",IDC_BUTTON2,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,363,151,83,10
CONTROL "set mode 3",IDC_BUTTON3,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,449,151,83,10
When I click button 3 for example, mode becomes 3 and the 3 radio buttons reflect that (buttons 1 & 2 are not checked, button 3 is checked). When I programatically then set mode to 1 (while the focus goes to another dialog), my 3 radio buttons reflect correctly the new state (button 1 checked, buttons 2 & 3 not checked). However when I then simply click the dialog border of the dialog that contains my radio buttons to bring it to the front, then OnBnClickedButton3 is magically called. I cannot figure out where that call originates. Looking at the debug info, this is what I have:
v_rep.dll!CMyDialog::OnBnClickedButton3() Line 1086
v_rep.dll!_AfxDispatchCmdMsg(CCmdTarget * pTarget=0x00edc940, unsigned int nID=1063, int nCode=0, void (void)* pfn=0x103ddd8b, void * pExtra=0x00000000, unsigned int nSig=56, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 82
v_rep.dll!CCmdTarget::OnCmdMsg(unsigned int nID=1063, int nCode=0, void * pExtra=0x00000000, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 381 + 0x27 bytes
v_rep.dll!CDialog::OnCmdMsg(unsigned int nID=1063, int nCode=0, void * pExtra=0x00000000, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 85 + 0x18 bytes
v_rep.dll!CWnd::OnCommand(unsigned int wParam=1063, long lParam=69026) Line 2300
v_rep.dll!CWnd::OnWndMsg(unsigned int message=273, unsigned int wParam=1063, long lParam=69026, long * pResult=0x0012ed9c) Line 1755 + 0x1e bytes
...
Basically I cannot trace back where that call originated from. But the debug call stack is exactly the same as when I click that radio button. But since I didn't physically click that radio button, it seems like a mystery to me.
EDIT: maybe I should have mentioned: my application is entirely wrapped in a dll, and my message loop looks like this:
if (PeekMessage(&aMessage,NULL,0,0,PM_REMOVE)!=0)
{ // We have a message
if (aMessage.message!=WM_QUIT)
{
DWORD myPid=GetCurrentProcessId();
HWND hwndFg=GetForegroundWindow();
DWORD pid=0;
bool translateAndDispatch=true;
if (hwndFg&&GetWindowThreadProcessId(hwndFg,&pid)&&(pid==myPid)&&(GetClassLong(hwndFg,GCW_ATOM)==32770))
{ // this is special for dialogs of my dll (not main window)
if (IsDialogMessage(hwndFg,&aMessage))
translateAndDispatch=false;
}
if (translateAndDispatch)
{
TranslateMessage(&aMessage);
DispatchMessage(&aMessage);
}
}
}
When I physically click the radio button the message is WM_LBUTTONUP. If the button clicked routine gets called because the dialog gets the focus again, the message is WM_NCLBUTTONDOWN (or there is no message at all if I click another "regular, i.e. not radio button" button of the dialog to bring it to front)
[Edited by - floatingwoods on March 19, 2010 5:18:58 AM]