Re: Unexplained WM_COMMAND messages in modeless dialog
OK, I had exactly the same problem. I had a dialog and no matter what
the radio button was getting selected on dialog initialization. I
think I know the reason, but bear with me because I'm doing this
totally form memory and may be using wrong terms.
The radio button in question was the first in the z-order. MFC somehow
selects a "default" button, control... and it is the first one in the
z-order. I do not remember if it can be set by properties. When MFC is
initializing the dialog it sends out all sorts of messages to assure
that the "default" is selected. My solution was to change the z-order
so that a standard button (but not OK, or Cancel) was the first one in
the z-order. That solved the problem.
Cheers,
Henryk
Joseph M. Newcomer <newcomer@flounder.com> wrote:
See below...
On Sat, 17 Jan 2009 00:06:28 -0800 (PST), Woody <ols6000@sbcglobal.net> wrote:
I am using a modeless MFC dialog. The dialog, designed using the
dialog editor, contains 2 group boxes, and each group box "contains" a
group of 3 radio buttons. Each radio button has a handler invoked when
the button is clicked.
When the dialog is created, one of the radio buttons (the one with the
lowest ID) receives several unexpected WM_COMMAND messages. No button
has been clicked at the time this occurs. I need to get rid of these,
as they interfere with the proper operation of the dialog.
After the initial flurry of unexplained WM_COMMAND messages for
IDC_TicksX, clicking on any radio button, including IDC_TicksX,
produces the expected single WM_COMMAND, dispatched to the
corresponding On-function.
Here is the code:
[in a class derived from CWnd]
if(pFitGrid==NULL)
{
pFitGrid=new CFitGridWindow(this);
pFitGrid->Create(IDD_FitGridWindow,this);
}
[in FitGridWindow.cpp]
BEGIN_MESSAGE_MAP(CFitGridWindow, CDialog)
ON_BN_CLICKED(IDC_TicksX, OnTicksX)
ON_BN_CLICKED(IDC_TicksY, OnTicksY)
ON_BN_CLICKED(IDC_GridX, OnGridX)
ON_BN_CLICKED(IDC_GridY, OnGridY)
ON_BN_CLICKED(IDC_NoneX, OnNoneX)
ON_BN_CLICKED(IDC_NoneY, OnNoneY)
END_MESSAGE_MAP()
****
What are the control IDs of those IDC_ values? Could you have a conflict with some other
ID?
I've not seen behavior like this, so if you are getting WM_COMMAND messages, there's
something going on that is not evident from this code.
****
void CFitGridWindow::OnTicksX()
{
} <-breakpoint here catches the bogus messages
*****
If they are sent via SendMessage, your stack backtrace should reveal who sent them. Study
it.
joe
*****
etc
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm