Check buttons
-
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??
-
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??
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
-
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
-
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.
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
-
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.
You'll need a member variable mapped to each of the checkboxes. Then in
OnInitDialog()
, simply call theSetCheck()
method of each member variable.m_checkbox1.SetCheck(BST_CHECKED);
m_checkbox2.SetCheck(BST_UNCHECKED);
m_checkbox3.SetCheck(BST_CHECKED);
... -
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??
-
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.
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.