Page 42 - DCAP408_WEB_PROGRAMMING
P. 42

Windows Programming




                    Notes                 while  (GetMessage(&msg,  NULL,  0,  0)  >  0)
                                          {
                                   Functions are requisite to send the message onto the WndProc function.
                                   First we make use of the TranslateMessage function. The translate message function translates
                                   virtual-key  messages  into  character messages  which  is  required. This  function takes one
                                   parameter, being the MSG variable containing the message obtained.
                                                 TranslateMessage(&msg);
                                   The next function we are required to use is the DispatchMessage function. This sends the message
                                   via the window procedure (WndProc). It also takes one MSGparameter.

                                                 DispatchMessage(&msg);
                                          }
                                   Thus we used the PostQuitMessage function and passed the value of 0. This could have been a
                                   dissimilar value we had passed so we cannot just return 0 as normal. We return the msg.wParam
                                   value which is the return code passed onto the PostQuitMessage function.
                                          return  (int)msg.wParam;
                                   You should now be able to develop simple windows messages. If you execute the program, you
                                   will observe that the  window will stay on the screen  until you close the window. This  will
                                   demolish the window and shut the program competently.





                                      Task  Make distinction between LPMSG lpMsg  and HWND hwnd.

                                   Self Assessment

                                   Fill in the blanks:
                                   7.  Message loop is utilized to catch messages and pass them onto our ......................... function.

                                   8.  ......................... is used to state what window the message must be recovered for.
                                   9.  When the ......................... function is called, the function halts until a message is obtained.

                                   3.5 Creating a New Window Class

                                   The WNDLCLASS and the  WNDCLASSEX  classes are  utilized to initialize the application
                                   window class. To exhibit a window, that is, to provide the user an object to work with, you must
                                   generate a window object. This window is the object the user utilizes to interrelate with the
                                   computer.
                                   To create a window, you can call either the CreateWindow() or the CreateWindowEx()function.
                                   You can just call this function and state its arguments after you have registered the window class.


                                          Example: Here is an example:
                                   INT  WINAPI  WinMain(HINSTANCE  hInstance,  HINSTANCE  hPrevInstance,
                                                       LPSTR  lpCmdLine,  int  nCmdShow)
                                   {




          36                                LOVELY PROFESSIONAL UNIVERSITY
   37   38   39   40   41   42   43   44   45   46   47