Page 201 - DCAP408_WEB_PROGRAMMING
P. 201

Unit 12: Dialog Boxes (II)




          highlighted  in the  list box,  so just  press “Add  Variable”  and  type  in  the  variable  name  Notes
          m_bIsChecked and press “OK”.





             Notes  Class Wizard gave you a default variable type of boolean. To create a variable
             forIDC_EDITBOX, press “Add Variable” again and type the variable name m_strText.
             Class Wizard gave this variable a default class of CString.
          In our main application, we need to modify our menu and/or toolbar to add a command to
          activate  our dialog  box. Assuming we’ve added  a command to “Demo the Dialog” (again,
          another topic, another time), we’ll add a message handler (in Class Wizard) to handle the user
          command  to  display  the  dialog  box.  Assuming  the  message  handler  is  named
          “OnViewDemodialog”, we would edit the handler to look like this:
          void  CMainFrame::OnViewDemodialog()
          {
                 //  Let’s  set  a  CMainFrame  boolean  variable  to  use  for  our  UI  command
                 //  handling.
                 m_bDemoDlgActive  =  TRUE;


                 //  Here,  we  create  our  dialog  box  class  and  initialize  the
                 //  member  variables.
                 CString  strResult;
                 CDemoDialog  MyDialog;


                 MyDialog.m_strText  =  “Edit  Me!”;  //  fill  in  edit  box
                 MyDialog.m_bIsChecked  =  FALSE;  //  set  up  check  box


                 if  (  MyDialog.DoModal()  ==  IDOK  )  {
                         //  If  the  user  pressed  “OK”,  we’ll  stuff  the  results  onto  the
                         //  control  bar.
                         strResult.Format(“(Returned:  ‘%s’,’%s’)”,MyDialog.m_strText,
                                (MyDialog.m_bIsChecked  ?  “checked”  :  “unchecked”));
                 }  //  if
                 else  {
                         //  User  pressed  “Cancel”,  so  write  to  control  bar.
                         strResult  =  “(Canceled)”;
                 }  //  else


                 //  Update  status  bar
                 m_wndStatusBar.SetWindowText(strResult);  //  always  use  for  pane
          0...







                                           LOVELY PROFESSIONAL UNIVERSITY                                   195
   196   197   198   199   200   201   202   203   204   205   206