Click to See Complete Forum and Search --> : Urgent! I need help for using checkbox in the dialog.


yang
April 26th, 1999, 01:21 PM
In my dialog, there are one edit box (for input file) and two checkboxes, called "Top" and "Bottom". After the user browses the file from the directory, they have to click on one of checkboxes, in order to explain what kind of file they get, if it is "Top" file or "Bottom" file. If they click on the "Top" checkbox, there are program that go through the file and do something, or if they click on the "Bottom" checkbox, there are the same program that go through the file ans do something else. What I want to know is how to make the program to response those check boxes. So far, I already created those checkboxes, and made variable fuctions for them.
void CDesignDlg::OnTop()
{

}

void CDesignDlg::OnBottom()
{

}

I want to know what kind of code I shall put in those functions, in order to make them work.

Please help me out. Thank you very much.

Harvey Hawes
April 26th, 1999, 01:48 PM
Hi,

I'm not sure I fully understand the question. Let me see if I can paraphrase what you said:

You have a dialog box in which the user selects a file (and puts the file name in an edit box). The user then has two options on how to process that file. One method is called "Top" and the other is "Bottom".

Assuming that what I said is correct, and that you want to do the file processing when the user Hits OK on the dlg this is what I'd do:

1) Use Radio buttons instead of Check buttons if the options are mutually exclusive (i.e. the user can only choose "Top" or "Bottom, not both, or neither).

2) Be sure to set the first radio button's group option (so that the button act as a mutually exclusive pair)

3) Using class Wizard, bind an integer to the first radio button in the group (if you've done step 2 then only the first radio button ID will be available).

4) Let MFC do the work of handling the user clicks on the radio buttons (you don't have to handle the click... see DDX and DDV in the MFC help)

5) This is how I would call the dlg

// in some function that calls the dlg

CMyDlg dlg;

// init dlg vars
dlg.m_nRadioButtonInt = 0; // set the first one as selected (In this case "Top" is 0, "Bottom" is 1)

if(dlg.DoModal() == IDOK) // i.e. if the user did everything in the dlg and hit ok
{
// get the processing mode
if(dlg.m_nRadioButtonInt == 0) // top mode
DoTopProcessing(dlg.m_szFileName); // pass the file name to a function that does "Top" processing
else
DoBottomProcessing(dlg.m_szFileName); // "Bottom" processing
}


You can use Check boxes if you want, but again, for something this simple use DDX (again see the MFC help on this). You'll find that all of the work is done for you.

HTH,



Harvey Hawes

Software Engineer
BioScience Analysis Software Ltd.

Masters Candidate
Cardiovascular/Respiratory Sciences
Faculty of Medicine
University of Calgary
Calgary, Alberta, Canada