Page 41 - DCAP408_WEB_PROGRAMMING
P. 41

Unit 3: Windows Programming




          The first thing you must do so as to create an application is to state a variable of either WNDCLASS  Notes
          or WNDCLASSEX type.


                 Example: Here is an example of a WNDCLASSEX variable:
          INT  WINAPI  WinMain(HINSTANCE  hInstance,  HINSTANCE  hPrevInstance,
                         LPSTR lpCmdLine, int nCmdShow)
          {
                  WNDCLASSEX  WndClsEx;


              return 0;
          }

          Self Assessment

          Fill in the blanks:
          5.   The argument, ......................... , is used if your program had any earlier instance.
          6.   The argument, ......................... , handles how the window you are building will be displayed.

          3.4 Messages and Adding a Message Loop


          Message loop is utilized to catch messages and pass them onto our WndProc function.
          First we are required to state a MSG variable. This is used to hold the message that has been
          caught by the window.

          MSG msg;
          To discover out what the last message obtained was, we can use the GetMessage function. The
          parameters for the function are specified below.

          LPMSG lpMsg - After the function call, the parameter passed onto here will enclose the message
          that was obtained.
          HWND hwnd - This is used to state what window the message must be recovered for. If a NULL
          is passed, a message for any window will be retrieved.
          UINT wMsgFilterMin & UINT wMsgFilterMax - This declares the range of messages to obtain.
          Each message has an integer value so you can identify exactly  what messages you want  to
          receive. If you pass 0 for both parameters, all messages are obtained.





             Notes  The return value is 0 if a WM_QUIT message has been obtained. If the return value
             is less than 0, some error has appeared. We only want to carry on if there was no error and
             if there is no quit message. Keep in mind that we caused a quit message to be sent if the
             window was closed.

          When the GetMessage function is called, the function halts until a message is obtained. If you do
          not want this, you can make use of the PeekMessage function which doesn’t stop, even if there
          was no message. This is typically used if you are busy computing something else. If you go in
          the course of the OpenGL or DirectX , you will use this.



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