Page 59 - DCAP408_WEB_PROGRAMMING
P. 59

Unit 4: Windows Controls




          The Cancel caption is functional on a button whose parent (the dialog box) would ask a question  Notes
          or  request a follow-up action from the user. A Cancel button  is also simple to  make by just
          adding a button to a dialog box and choosing IDCANCEL as its identifier in the ID combo box.
          Setting a button’s identifier to IDCANCEL also permits the user to press Esc to dismiss  the
          dialog box.
          The  scenarios illustrated for the OK and  the Cancel buttons are made probable  only if the
          compiler is able to make sure or validate the changes completed on a dialog box. To make this
          validation probable, in your class, you must overload the CWnd::DoDataExchange() member
          function. Its syntax is:

          virtual  void  DoDataExchange(CDataExchange*  pDX);
          This member function is utilized internally by the application (the framework) to discover if
          data on a dialog box has been changed as the object was displayed. This member function does
          two things: It makes sure the exchange of data among controls and it authenticates the values of
          those controls. In realism, it does not intrinsically perform data validation, meaning it would
          not permit or disallow value on a control. Rather, the compiler uses it to generate a table of the
          controls on the dialog box, their variables and values, permitting other controls to refer to it for
          data exchange and validation. If you want to discover the data a user would have typed or
          chosen in a control, you would have to write the essential code.

          4.5.5 Processing


          Button Control Messages

          The most usual action users carry out on a button is to click it. When a user does this, the button
          sends a  BN_CLICKED message. In some but rare situations,  you may  also ask  the user to
          double-click a button. In general, you will take care of most message handling when the user
          clicks a button. There are other messages that you can  manage through a button.
          To close a dialog box, you can utilize the Win32 API’s PostQuitMessage() function. Its syntax is:
          VOID  PostQuitMessage(int  nExitCode);
          This function takes one argument, which is an integer. The argument could be set to approximately
          any integer value even though it should be WM_QUIT.

                 Example: Here is an example:

          void  CDialog5Dlg::OnBtnClose()
          {
                  //  TODO:  Add  your  control  notification  handler  code  here
                  PostQuitMessage(125);
          }
          Even though the MFC library offers enough messages related with the various controls, in some
          situation you will need use a message that is not necessarily connected with the control. In such
          a case, you can call the CWnd::SendMessage() member function. Its syntax is:
          LRESULT SendMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0);

          The first argument of this member function can be a Win32 message or constant.







                                           LOVELY PROFESSIONAL UNIVERSITY                                   53
   54   55   56   57   58   59   60   61   62   63   64