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. Check buttons

Check buttons

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 6 Posters 0 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.
  • P Offline
    P Offline
    ppathan
    wrote on last edited by
    #1

    Is it possible to set a few check buttons to be defaultly true so that when a user opens an applcation those buttons are by default true?? if it is how can we do that??

    M I B 3 Replies Last reply
    0
    • P ppathan

      Is it possible to set a few check buttons to be defaultly true so that when a user opens an applcation those buttons are by default true?? if it is how can we do that??

      M Offline
      M Offline
      melwyn
      wrote on last edited by
      #2

      Try calling CButton::SetCheck() in OnInitDialog() of your dialog class.

      1 Reply Last reply
      0
      • P ppathan

        Is it possible to set a few check buttons to be defaultly true so that when a user opens an applcation those buttons are by default true?? if it is how can we do that??

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        There is no window style to set to get your checkboxes set initially. e.g. No BS_CHECKEDALREADY. But its not hard to do this for yourself. If you use classwizard / DDX_Check, just make sure your m_bAlreadySet = TRUE in your dialog constructor. Or check the box manually in your OnInitDialog routine. The possibilities may not be endless, but they are pretty large. Iain

        P 1 Reply Last reply
        0
        • I Iain Clarke Warrior Programmer

          There is no window style to set to get your checkboxes set initially. e.g. No BS_CHECKEDALREADY. But its not hard to do this for yourself. If you use classwizard / DDX_Check, just make sure your m_bAlreadySet = TRUE in your dialog constructor. Or check the box manually in your OnInitDialog routine. The possibilities may not be endless, but they are pretty large. Iain

          P Offline
          P Offline
          ppathan
          wrote on last edited by
          #4

          can u please give me exact code if I use class wizard /DDX_check? I tried to declare a variable called m_Alreadyset to my check button of type BOOL and set it to true in OninitDialog, but it didn't work.

          G D I 3 Replies Last reply
          0
          • P ppathan

            can u please give me exact code if I use class wizard /DDX_check? I tried to declare a variable called m_Alreadyset to my check button of type BOOL and set it to true in OninitDialog, but it didn't work.

            G Offline
            G Offline
            G Steudtel
            wrote on last edited by
            #5

            Hi, Setting the BOOL variable to TRUE will work only before! a call to DoDataEcxhange. So you must set your variable to TRUE before the line CDialog::OnInitialUpdate(); or call UpdateData(false); at the end of your OnInitialUpdate-Routine. You may also consider doing the assignment in your dialog's constructor. Regards G. Steudtel

            1 Reply Last reply
            0
            • P ppathan

              can u please give me exact code if I use class wizard /DDX_check? I tried to declare a variable called m_Alreadyset to my check button of type BOOL and set it to true in OninitDialog, but it didn't work.

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

              You'll need a member variable mapped to each of the checkboxes. Then in OnInitDialog(), simply call the SetCheck() method of each member variable.

              m_checkbox1.SetCheck(BST_CHECKED);
              m_checkbox2.SetCheck(BST_UNCHECKED);
              m_checkbox3.SetCheck(BST_CHECKED);
              ...

              1 Reply Last reply
              0
              • P ppathan

                Is it possible to set a few check buttons to be defaultly true so that when a user opens an applcation those buttons are by default true?? if it is how can we do that??

                B Offline
                B Offline
                Ben805
                wrote on last edited by
                #7

                Make sure the member variable for the checkbox is a control variable, not value...then you can use SetCheck()

                1 Reply Last reply
                0
                • P ppathan

                  can u please give me exact code if I use class wizard /DDX_check? I tried to declare a variable called m_Alreadyset to my check button of type BOOL and set it to true in OninitDialog, but it didn't work.

                  I Offline
                  I Offline
                  Iain Clarke Warrior Programmer
                  wrote on last edited by
                  #8

                  Some possibilities have already been given to you. If you use classwizard, you can assign a member variable of type BOOL to a check box. Doing this will fill in all the right code for you. As I remember (I don't touch CW with a barge pole) you can even assign an initial value of 1 (TRUE) to it. If not, all you have to do is find the line in the constructor which initialises the check variable and change it to say = 1; or = TRUE; depending on taste. If you want to do it the hard way, then the following code will help. Is assume you have a check box of value IDC_CHECK1, and you are making a dialog class called CMyDlg. In the header:

                  class CMyDlg : public CDialog
                  {
                  public:
                  CMyDlg (....);
                  ....
                  BOOL m_bCheckValue;
                  ....

                  protected:
                  void DoDataExchange (CDataExchange *pDX);
                  BOOL OnInitDialog ();
                  ....
                  };

                  In the implementation file (eg. mydlg.cpp)

                  CMyDlg (...) : CDialog (....)
                  {
                  ....
                  m_bCheckValue = TRUE;
                  ....
                  }

                  BOOL CMyDlg::OnInitDialog ()
                  {
                  ....
                  BOOL bReturn = CDialog::OnInitDialog ();
                  ....
                  return bReturn;
                  }

                  void CMyDlg::DoDataExchange (CDataExchange *pDX)
                  {
                  CDialog::DoDataExchange (pDX); // Nothing actually happens here, but its good practice.
                  ....
                  DDX_Check (pDX, IDC_CHECK1, m_bCheckValue);
                  ....
                  }

                  I put in the OnInitDialog just to remind you you need to call the base member to ensure DoDataExchange gets called. By putting the DDX_Check in, rather than just checking the box in OnInitDialog, we make sure that the value is retrieved when you press OK, so you can find out whether the user cleared the check box or not. Iain.

                  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