Simple question about radio buttons
-
David, That is exactly as i was doing it in the OnInitDialog.... Perhaps I am doing something incorrect in the OnOk. How would i get the which one is selected by the user? thanks again for all your help and patience with a mechanical engineer with no wit to program. ;P
Jay Hova wrote: Perhaps I am doing something incorrect in the OnOk. How would i get the which one is selected by the user?
if (xxx.GetCheck() == BST_CHECKED)
... -
Jay Hova wrote: Perhaps I am doing something incorrect in the OnOk. How would i get the which one is selected by the user?
if (xxx.GetCheck() == BST_CHECKED)
... -
This is what i have in OnOk():
if(m_Screen_Radio.GetCheck() == BST_CHECKED) m_SendTo = 0; else m_SendTo = 1;
where m_SendTo is a member variable of type int and m_Screen_Radio is CButton
What you've shown should work. Does it? Now in the code that instantiates the dialog object, you'll need something like:
CMyDialog dlg;
dlg.m_SendTo = m_SendTo;
if (dlg.DoModal() == IDOK)
m_SendTo = dlg.m_SendTo;Make sense?
-
What you've shown should work. Does it? Now in the code that instantiates the dialog object, you'll need something like:
CMyDialog dlg;
dlg.m_SendTo = m_SendTo;
if (dlg.DoModal() == IDOK)
m_SendTo = dlg.m_SendTo;Make sense?
-
I get an assertion failure with that code that I had.... You lost me however with what you wrote. I don't understand it. Where should I put that code? Please clarify if you can. Many many thanks.
Jay Hova wrote: I get an assertion failure with that code that I had.... See my previous comment about
DoDataExchange()
. Even though you have a CButton control variable, there must be an entry inDoDataExchange()
for it. To verify, note the file/line of the fired assertion. If you then look at that code, it will most likely look something like:ASSERT(::IsWindow(m_hWnd));
which means there is no window associated with the variable. Jay Hova wrote: You lost me however with what you wrote. I don't understand it. Where should I put that code? Please clarify if you can. You previously mentioned that the dialog was being displayed as the result of a menu selection. I assume you already have a call toDoModal()
in there. Correct? -
Jay Hova wrote: I get an assertion failure with that code that I had.... See my previous comment about
DoDataExchange()
. Even though you have a CButton control variable, there must be an entry inDoDataExchange()
for it. To verify, note the file/line of the fired assertion. If you then look at that code, it will most likely look something like:ASSERT(::IsWindow(m_hWnd));
which means there is no window associated with the variable. Jay Hova wrote: You lost me however with what you wrote. I don't understand it. Where should I put that code? Please clarify if you can. You previously mentioned that the dialog was being displayed as the result of a menu selection. I assume you already have a call toDoModal()
in there. Correct? -
I tried to implement the code you wrote, but i get an error saying that m_SendTo is an undeclared identifier. The assertion failure is in afxwin2.inl on line 588.... Thanks again for your help. Your patience is amazing! :-O
Jay Hova wrote: I tried to implement the code you wrote, but i get an error saying that m_SendTo is an undeclared identifier. Right. You'll need to add this member variable to the appropriate class. Jay Hova wrote: The assertion failure is in afxwin2.inl on line 588.... As I predicted:
_AFXWIN_INLINE int CButton::GetCheck() const
{ ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0); } -
Jay Hova wrote: I tried to implement the code you wrote, but i get an error saying that m_SendTo is an undeclared identifier. Right. You'll need to add this member variable to the appropriate class. Jay Hova wrote: The assertion failure is in afxwin2.inl on line 588.... As I predicted:
_AFXWIN_INLINE int CButton::GetCheck() const
{ ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0); }David, Sorry that you have to spoon feed me through this. I feel like such a moron because I can not grasp this concept. I really appreciate your help. What do i have to put in DoDataExchange? Also by adding the member variable to the other cpp file, won't it over write the existing data in m_SendTo? Thanks.
-
David, Sorry that you have to spoon feed me through this. I feel like such a moron because I can not grasp this concept. I really appreciate your help. What do i have to put in DoDataExchange? Also by adding the member variable to the other cpp file, won't it over write the existing data in m_SendTo? Thanks.
Jay Hova wrote: Sorry that you have to spoon feed me through this. I feel like such a moron because I can not grasp this concept. I really appreciate your help. Not a problem. The first few applications are always the hardest. Jay Hova wrote: What do i have to put in DoDataExchange? Also by adding the member variable to the other cpp file, won't it over write the existing data in m_SendTo? I've never had to manaully add anything to
DoDataExchange()
. ClassWizard does it all for me (hint: use CW to create the member and control variables). By looking at that function, however, you can get a feel for what MFC might be doing. Jay Hova wrote: Also by adding the member variable to the other cpp file, won't it over write the existing data in m_SendTo? I'm not quite sure I understand what you are asking here. Care to elaborate? -
Jay Hova wrote: Sorry that you have to spoon feed me through this. I feel like such a moron because I can not grasp this concept. I really appreciate your help. Not a problem. The first few applications are always the hardest. Jay Hova wrote: What do i have to put in DoDataExchange? Also by adding the member variable to the other cpp file, won't it over write the existing data in m_SendTo? I've never had to manaully add anything to
DoDataExchange()
. ClassWizard does it all for me (hint: use CW to create the member and control variables). By looking at that function, however, you can get a feel for what MFC might be doing. Jay Hova wrote: Also by adding the member variable to the other cpp file, won't it over write the existing data in m_SendTo? I'm not quite sure I understand what you are asking here. Care to elaborate?David, Thank you for your help. I had to manually insert the control in DoDataExchange because after reading the article you linked me to earlier today, i ungrouped the second radio. It doesn't make sense to me, but it seems to be working right now. Now to the next part of this app.... Many many thanks for your help, patience, and understanding. You are really a class act guy!