Page 40 - DCAP408_WEB_PROGRAMMING
P. 40

Windows Programming




                    Notes          3.3 Creating the Programs Window

                                   There are two chief things you must perform in order to generate even the simplest window:
                                   you must create the middle point of the program, and you must tell the operating system how
                                   to react when the user does what.
                                   Just like a C++ program always contains a main() function, a Win32 program requires a central
                                   function call WinMain. The syntax of that function is:
                                   INT  WINAPI  WinMain(HINSTANCE  hInstance,  HINSTANCE  hPrevInstance,
                                                      LPSTR lpCmdLine, int nCmdShow );
                                   Dissimilar to the C++ main() function, the arguments of the WinMain() function are not optional.
                                   Your program will require them to converse with the operating system.

                                   The first argument, hInstance, is a handle to the instance of the program you are writing.
                                   The second argument, hPrevInstance, is used if your program had any earlier instance. If not, this
                                   argument can be unnoticed, which will always be the case.

                                   The third argument, lpCmdLine, is a string that displays all items used on the command line to
                                   compile the application.
                                   The last argument, nCmdShow, handles how the window you are building will be displayed.

                                   An object that represents on your screen is known as a window. Since there can be different types
                                   of windows in your programs, your first accountability is to manage them, know where they
                                   are, what they are doing, why and when. The first control you must exercise on these dissimilar
                                   windows is to host them so that all windows of your program belong to an entity known as the
                                   main window. This main window is created by means of an object that can be called a class
                                   (strictly, a structure).
                                   The Win32 library offers two classes for generating the main window and you can use any one
                                   of them. They are WNDCLASS and WNDCLASSEX. The second adds only a slight trait to the
                                   first. Thus, we will mostly use the WNDCLASSEX structure.

                                   The WNDCLASS and the WNDCLASSEX classes are defined as below:
                                    typedef struct _WNDCLASS {               typedef struct _WNDCLASSEX {
                                       UINT       style;                         UINT       cbSize;
                                       WNDPROC    lpfnWndProc;                   UINT       style;
                                       int        cbClsExtra;                    WNDPROC    lpfnWndProc;
                                       int        cbWndExtra;                    int        cbClsExtra;
                                       HINSTANCE  hInstance;                     int        cbWndExtra;
                                       HICON      hIcon;                         HINSTANCE  hInstance;
                                       HCURSOR    hCursor;                       HICON      hIcon;
                                       HBRUSH     hbrBackground;                 HCURSOR    hCursor;
                                       LPCTSTR    lpszMenuName;                  HBRUSH     hbrBackground;
                                       LPCTSTR    lpszClassName;                 LPCTSTR    lpszMenuName;
                                   } WNDCLASS, *PW                               LPCTSTR    lpszClassName;
                                                                                 HICON      hIconSm;
                                                                             } WNDCLASSEX, *PWNDCLASSEX;

                                       !
                                     Caution  To create a window, you must “fill out” this class, which means you must supply
                                     a value for each of its members so the operating system would identify what your program
                                     is anticipated to do.




          34                                LOVELY PROFESSIONAL UNIVERSITY
   35   36   37   38   39   40   41   42   43   44   45