Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- FiveWin 1.9.2 - January 97 - <b>windows api messages structure</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 Windows API messages structure
 --------------------------------------------------------------------------------

  If you review the examples provided in the Petzold book, you will realize
  all Windows applications have the same structure:

               * Creating the application main window
               * Start running the main get-message loop
               * Taking decisions based on received messages

  Almost all that we see in a Windows environment is a window. The PushButtons,
  the Scrollbars, the CheckBoxes, the Dialogs, etc... are all windows.

  Windows sends messages to all windows informing them about what is
  happening and about what every window has to do. That is why Windows
  API requires the programmer to provide a window procedure for every
  window which will be called by Windows in order to give us the messages.

  In all Windows applications there must be a typical defined window
  function:

   long WINAPI WndProc( HWND hWnd, WORD wMessage, WORD wParam, LONG lParam )

  That is the function Windows API uses to sends messages to our defined
  window. Let's review those parameters:

     * hWnd       The Window API handle of our window. Windows
                  identifies every window using a 'handle': a numeric
                  value Windows API internally generates. This value
                  must NOT be manipulated, it is a 'read-only' value.

     * wMessage   A numeric value that identifies any of the
                  Windows API different messages. All these different
                  messages values are provided in a header file
                  provided by Microsoft called Windows.h. FiveWin has
                  its own WinApi.ch which includes the most used messages
                  identifiers values. If you need to know about them,
                  please review Windows.h supplied by Microsoft or
                  Borland or any other Windows tools manufacturer.

     * wParam     A numeric value, a 'WORD' is a number of two
                  bytes so it is in the range 0-216  which is used
                  to provide the window function with some parameter
                  value. This parameter may be many different things
                  according to the sent message.

     * lParam     A numeric value, a 'LONG' is a number of four
                  bytes so it is in the range 0-232  which is used
                  to provide the window function with some extra parameter
                  value. This parameter may be many different things
                  according to the sent message.

  The window function typically performs a C switch statement, a Clipper
  DO CASE... ENDCASE statement  and performs different actions according
  to the message received and its parameters, provided by Windows API.

  In all Petzold examples we will find C code like this:

                  switch( wMsg )
                  {
                     case WM_PAINT:
                          ...
                          return 0;

                     case WM_COMMAND:
                          ...
                          return ...;

                     ...

                     default:
                          return DefWindowProc( hWnd, wMsg, wParam, lParam );
                  }

  Windows provides a mechanism for processing unattended messages, that
  is default behaviors to be performed in case we don't care about
  all sent messages. That is why all window functions have a default call
  at the bottom of them to the Windows API function DefWindowProc( ... )
  Default window procedure provided by Windows API.

  Our window tells Windows API what to do according to the different values
  the window function returns. Typically there are these possibilities:

        * return 0           Means we have performed an action
                             and we don't want Windows to do anything.

        * return non-zero    In some cases Windows API requires some
                             values.

        * If we want         We call DefWindowProc( ... ) and returns
          standard behavior  its value to Windows API.

  This process is the main conversation system between Windows API and
  our defined windows. In this process we have to connect to the Clipper
  Object Oriented kernel in order to convert it into an Object Oriented
  process.


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson