Page 69 - DCAP408_WEB_PROGRAMMING
P. 69

Unit 4: Windows Controls




          4.7.2 Characteristics of a Combo Box                                                  Notes


          Windows Styles of a Combo Box
          Similar to all the other windows, to generate a combo box programmatically, you can call the
          CreateWindow() or the CreateWindowEx() function. The syntax used is:


           HWND CreateWindow( "COMBOBOX",       HWND CreateWindowEx( Extended Style,
                             "Default String",                       "COMBOBOX",
                             style,                                 "Default String",
                             x,                                     style,
                             y,                                     x,
                             width,                                 y,
                             height,                                width,
                             parent,                                height,
                             menu,                                  parent,
                             instance,                              menu,
                             Optional arameter );                      instance,
                                                                    Optional Parameter );

          The first argument of the CreateWindow() or the second argument of the CreateWindowEx()
          functions must be COMBOBOX passed as a string.

          The second argument of the CreateWindow() or the third argument of the CreateWindowEx()
          functions states a string that would display in the edit part of the combo box when the control
          occurs. If the control is generated with certain styles we will review here, this string would not
          come out even if you state it. You can also omit it and pass the argument as NULL or “” since
          there are other ways you can set the default string.
          Similar to every other Windows control, a combo box appearance and behavior are managed by
          a set of properties called styles.




             Did u know?   The main  properties of  a combo box are  those handled  by the  operating
             system and shared by all controls.
          You can utilize them to set the visibility, availability, and parenthood, etc., of the combo box. If
          you create a combo box by means of a resource script, since you would contain it in a DIALOG
          section of the script, the dialog box is automatically made its parent. Or else, to specify that the
          combo box is hosted by another control, get the handle of the host and pass it as the parent
          parameter. You must also set or add the WS_CHILD bit value to the style parameter. If you want
          the combo box to occur when its parent comes up, add the WS_VISIBLE style using the bitwise
          | operator.
          If you want the combo box to obtain focus as a result of the user pressing the Tab key, add the
          WS_TABSTOP style.
          The location of a combo box is stated by the x and y parameters whose values are d on the origin,
          located in the top-left corner or the dialog box or the window that is hosting the combo box.
          Programmatically Creating a Combo Box


          1.   To programmatically create a combo box, alter the Exercise.cpp file as follows:
               #include <windows.h>




                                           LOVELY PROFESSIONAL UNIVERSITY                                   63
   64   65   66   67   68   69   70   71   72   73   74