Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Simple question about radio buttons

Simple question about radio buttons

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
19 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jay Hova

    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

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #10

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

    J 1 Reply Last reply
    0
    • D David Crow

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

      J Offline
      J Offline
      Jay Hova
      wrote on last edited by
      #11

      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

      D 1 Reply Last reply
      0
      • J Jay Hova

        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

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #12

        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?

        J 1 Reply Last reply
        0
        • D David Crow

          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?

          J Offline
          J Offline
          Jay Hova
          wrote on last edited by
          #13

          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.

          D 1 Reply Last reply
          0
          • J Jay Hova

            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.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #14

            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 in DoDataExchange() 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 to DoModal() in there. Correct?

            J 1 Reply Last reply
            0
            • D David Crow

              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 in DoDataExchange() 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 to DoModal() in there. Correct?

              J Offline
              J Offline
              Jay Hova
              wrote on last edited by
              #15

              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

              D 1 Reply Last reply
              0
              • J Jay Hova

                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

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #16

                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); }

                J 1 Reply Last reply
                0
                • D David Crow

                  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); }

                  J Offline
                  J Offline
                  Jay Hova
                  wrote on last edited by
                  #17

                  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.

                  D 1 Reply Last reply
                  0
                  • J Jay Hova

                    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.

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #18

                    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?

                    J 1 Reply Last reply
                    0
                    • D David Crow

                      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?

                      J Offline
                      J Offline
                      Jay Hova
                      wrote on last edited by
                      #19

                      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!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups