Jump to content
  • Advertisement
Sign in to follow this  

Radio button gets magically clicked!

This topic is 3017 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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()

The event handler functions ("radio button clicked") look like:
void myDialog::OnBnClickedButton1()
(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))
			if (translateAndDispatch)

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]

Share this post

Link to post
Share on other sites
Maybe when setting the radio state by program, the item becomes active/current/mouse_on/whatever, then a mouse up message will trigger it (that's why button 3, the lastly set radio gets triggered).
Try to set the active item (if possible) to nothing selected, after the setting code.

Maybe WM_NCLBUTTONDOWN goes with WM_LBUTTONUP (DispatchMessage)

Share this post

Link to post
Share on other sites
Thank you szecs,

I temporarily solved the problem by putting a flag up/down when message WM_LBUTTONUP is seen in the message loop, then in the event handling routine I check for that flag... not very elegant, but works nicely

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!