Problem on dialog creation
-
Sorry but maybe I was not clear enough. I open this dialog window by clicking on a menu choice in my main window. When the dialog opens, OnInitDialog() completes then the handler of the radio-button, which is in the window just opened, is being called. I break in the handler and I move to the OnCommand function using the Context window of the debugger. Then I check the value of lParam and it changes everytime I close and reopen the dialog window using the menu choice of my main window. If what you say is true regarding lParam containing the handle of the control sending the message, then the value in lParam should always be the same because I am always using the menu choice to open the dialog window. Maybe I am missing something here! Thanks!
jpyp
The radio button is a child of the dialog, right? The handler you break in is a command message to the dialog, right? If yes to both, then every time you create this new dialog window, a new radio button is created. Its window handle (HWND) which is passed in the LParam of its command messages to its parent (the dialog) can (probably will) be different for every new instance of the dialog. You use the ID of the radio button to identify it in a WM_COMMAND message from the radio button, not its HWND. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
The radio button is a child of the dialog, right? The handler you break in is a command message to the dialog, right? If yes to both, then every time you create this new dialog window, a new radio button is created. Its window handle (HWND) which is passed in the LParam of its command messages to its parent (the dialog) can (probably will) be different for every new instance of the dialog. You use the ID of the radio button to identify it in a WM_COMMAND message from the radio button, not its HWND. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
Got you! Thanks for the explanation. Now considering my answer to DavidCrow, what do you think could cause this message to be generated? As I previously said, I am not sending this message anywhere in my code. The call stack proves it and looks like this: Message handler ... (a number of DLL and OS functions) OnCommand ... (a number of DLL and OS functions) Function where I call Create() to create the dialog (stopped at the Create() call). Thanks!
jpyp
-
Got you! Thanks for the explanation. Now considering my answer to DavidCrow, what do you think could cause this message to be generated? As I previously said, I am not sending this message anywhere in my code. The call stack proves it and looks like this: Message handler ... (a number of DLL and OS functions) OnCommand ... (a number of DLL and OS functions) Function where I call Create() to create the dialog (stopped at the Create() call). Thanks!
jpyp
WM_COMMAND messages which come from a control are notifications from the control to the parent. For a radio button, see Button Messages[^] The section "Notification Messages from Buttons" lists the BN_xxx notifications that a button sends to its parent in the form of a WM_COMMAND message. You should be able to match the high WORD of the WPARAM in the command message to one of those BN_xx codes. If not, maybe it's an undocumented message :) Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
DavidCrow wrote:
While your code may not be doing it directly, a BM_SETCHECK message is being sent to the control, thus the control's handler is doing what it should. If this is undesirable behavior, there's an easy solution.
By easy solution you mean removing the SetCheck(FALSE) call in OnInitDialog(), I tried that with no difference. Any other suggestions? Thanks!
jpyp
jpyp wrote:
By easy solution you mean removing the SetCheck(FALSE) call in OnInitDialog()...
No, I did not mean that at all. Try:
void CMyDialog::CMyDialog()
{
m_bInitializing = true;
}BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
...
m_bInitializing = false;
return TRUE;
}void CMyDialog::OnButtonChange()
{
if (! m_bInitializing)
{
// do whatever here
}
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
WM_COMMAND messages which come from a control are notifications from the control to the parent. For a radio button, see Button Messages[^] The section "Notification Messages from Buttons" lists the BN_xxx notifications that a button sends to its parent in the form of a WM_COMMAND message. You should be able to match the high WORD of the WPARAM in the command message to one of those BN_xx codes. If not, maybe it's an undocumented message :) Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
Thanks for your reply and info. As I stated in my original post, the high word of wParam is 0. I still can't figure out where this message is coming from. This is driving me crazy. If you can think of anything else, please let me know. If not thanks anyway for your help.
jpyp
-
jpyp wrote:
By easy solution you mean removing the SetCheck(FALSE) call in OnInitDialog()...
No, I did not mean that at all. Try:
void CMyDialog::CMyDialog()
{
m_bInitializing = true;
}BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
...
m_bInitializing = false;
return TRUE;
}void CMyDialog::OnButtonChange()
{
if (! m_bInitializing)
{
// do whatever here
}
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Thanks for your reply and info. As I stated in my original post, the high word of wParam is 0. I still can't figure out where this message is coming from. This is driving me crazy. If you can think of anything else, please let me know. If not thanks anyway for your help.
jpyp
jpyp wrote:
As I stated in my original post, the high word of wParam is 0
I never claimed I could read ;P That's a BN_CLICKED notification. It could be because the control received a WM_SETFOCUS message. I can't recall if a BN_CLICKED gets sent when you send a BM_SETCHECK - if you comment out that call, do you still get the notification? I'm not sure why you're worried about it. There's lots of messages that most of us don't handle or care about. It's much more of a problem when you expect a message and get none :) I thought I posted this link, but in case I didn't: Button Messages[^] This documents how messages are processed by and from a button control (this is documented for pretty much all Windows controls). Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Thanks for your reply. However this will not help as the handler is being called after OnInitDialog() completes so in OnButtonChange() m_bInitializing will always be FALSE. This is driving me crazy. This behavior does not happen with my other dialogs.
jpyp
jpyp wrote:
the handler is being called after OnInitDialog() completes
It almost sounds like
UpdateData()
is the culprit. What I don't understand, however, is why this is a problem. I've calledSetCheck()
withinOnInitDialog()
in several of my programs and it works fine. Can you explain a bit further what the actual problem is?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
jpyp wrote:
As I stated in my original post, the high word of wParam is 0
I never claimed I could read ;P That's a BN_CLICKED notification. It could be because the control received a WM_SETFOCUS message. I can't recall if a BN_CLICKED gets sent when you send a BM_SETCHECK - if you comment out that call, do you still get the notification? I'm not sure why you're worried about it. There's lots of messages that most of us don't handle or care about. It's much more of a problem when you expect a message and get none :) I thought I posted this link, but in case I didn't: Button Messages[^] This documents how messages are processed by and from a button control (this is documented for pretty much all Windows controls). Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
I do get the same problem if I comment out the SetCheck call. I'll investigate the WM_SETFOCUS idea. I don't that is it but you never know. The reason I worry so much about it is that I have other controls on this dialog that are supposed to be disabled when the dialog opens. When the user click on the button that I have problem with, these controls are then enabled. My problem is that when I receive this "irritating" message when the dialog opens, these controls get enabled when they should not be yet because the user has not click on it yet. Hope I'm making some sense. Thanks!
jpyp
-
jpyp wrote:
the handler is being called after OnInitDialog() completes
It almost sounds like
UpdateData()
is the culprit. What I don't understand, however, is why this is a problem. I've calledSetCheck()
withinOnInitDialog()
in several of my programs and it works fine. Can you explain a bit further what the actual problem is?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I do get the same problem if I comment out the SetCheck call. I'll investigate the WM_SETFOCUS idea. I don't that is it but you never know. The reason I worry so much about it is that I have other controls on this dialog that are supposed to be disabled when the dialog opens. When the user click on the button that I have problem with, these controls are then enabled. My problem is that when I receive this "irritating" message when the dialog opens, these controls get enabled when they should not be yet because the user has not click on it yet. Hope I'm making some sense. Thanks!
jpyp
jpyp wrote:
I'll investigate the WM_SETFOCUS idea. I don't that is it but you never know.
I just know what I read about how the default window proc for a button control handles the WM_SETFOCUS message: "Draws a focus rectangle on the button getting the focus. For radio buttons and automatic radio buttons, the parent window is sent a BN_CLICKED notification message." So, to back up, you are calling SetCheck(BST_UNCHECKED) for the radio button in question? Is this an automatic radio button? If so, maybe calling SetCheck(BST_CHECKED) on the radio button you DO want initially checked would be more appropriate. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
I do get the same problem if I comment out the SetCheck call. I'll investigate the WM_SETFOCUS idea. I don't that is it but you never know. The reason I worry so much about it is that I have other controls on this dialog that are supposed to be disabled when the dialog opens. When the user click on the button that I have problem with, these controls are then enabled. My problem is that when I receive this "irritating" message when the dialog opens, these controls get enabled when they should not be yet because the user has not click on it yet. Hope I'm making some sense. Thanks!
jpyp
jpyp wrote:
I have other controls on this dialog that are supposed to be disabled when the dialog opens.
Unless your resource(s) are frozen (that's a concept with my product), shouldn't you be disabling those at design time, and only enabling them when said button is clicked?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I do get the same problem if I comment out the SetCheck call. I'll investigate the WM_SETFOCUS idea. I don't that is it but you never know. The reason I worry so much about it is that I have other controls on this dialog that are supposed to be disabled when the dialog opens. When the user click on the button that I have problem with, these controls are then enabled. My problem is that when I receive this "irritating" message when the dialog opens, these controls get enabled when they should not be yet because the user has not click on it yet. Hope I'm making some sense. Thanks!
jpyp
I fixed it!!!!! But before I tell how I fixed it, let me answer your comments/questions. First I'll show how the dialog is designed: RadButCol1 RadButCol2 PushBut1 EditCol1_1 EditCol2_1 PushBut1 EditCol1_2 EditCol2_2 PushBut1 EditCol1_3 EditCol2_3 PushBut1 EditCol1_4 EditCol2_4 ... PushBut19 EditCol1_19 EditCol2_19 David: At design, I disable all buttons in column 1 and 2 and the two radio buttons are unchecked. So when I open the dialog both columns should be disabled. Then the user should clickone of the radio buttons to enable one set of edit controls. However when the dialog is open, the handler for RadButCol1 is being called automatically and therefore the edit controls of column one get enabled. Mark: Setting the first push-button as the default button did not help. Also I tried with calling SetFocus() in the OnInitDlg() on PushBut1 so that the RadButCol1 would not have the focus on startup, but that still did not work. Now the fix (and I still don't know why it worked!!!!): In my .rc file I moved the declarations of the two radio buttons down so that they are not first in the dialog definition. Being first seems to trigger a BN_CLICKED notification message for some reason. If you have any idea why, please let me know. I really appreciate your help and time on this issue. Thanks!
jpyp