home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12716.ZIP / BASE.C < prev    next >
C/C++ Source or Header  |  1990-09-27  |  6KB  |  143 lines

  1. /**************************************************************************\
  2.  *                                                                        *
  3.  * Base.c                                                                 *
  4.  *                                                                        *
  5.  * This application does the following:                                   *
  6.  *                                                                        *   
  7.  *   Creates a "kid" frame inside the parent frame, and draws a bitmap    *
  8.  *   in the client area of both parent and "kid".                         *
  9.  *                                                                        *
  10.  *   It serves to demonstrates that by taking care of the WM_PAINT        *
  11.  *   message in both the client areas of "kid" and parent, the clients    *
  12.  *   will be redrawn correctly when repainting is required.               *
  13.  *                                                                        *
  14.  *                                                                        *
  15.  * Author: Petrus Wong                                                    *
  16.  *                                                                        *
  17.  * History: created 8-20-90                                               *
  18.  *                                                                        *
  19.  **************************************************************************/
  20. #define INCL_WIN
  21. #include <os2.h>
  22. #include "base.h"
  23.  
  24. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  25. MRESULT EXPENTRY ChildWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  26.  
  27. int main (void)
  28.      {
  29.      static CHAR  szClientClass [] = "Base" ;
  30.      static CHAR  szChildClass [] = "Kid" ;
  31.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  32.                                  FCF_SIZEBORDER    | FCF_MINMAX  |
  33.                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
  34.      HAB          hab ;
  35.      HMQ          hmq ;
  36.      HWND         hwndFrame, hwndClient, hwndChildFrame, hwndChildClient ;
  37.      QMSG         qmsg ;
  38.  
  39.      hab = WinInitialize (0) ;
  40.      hmq = WinCreateMsgQueue (hab, 0) ;
  41.  
  42.      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
  43.      WinRegisterClass (hab, szChildClass, ChildWndProc, CS_SIZEREDRAW, 0) ;
  44.  
  45.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  46.                                      &flFrameFlags, szClientClass, NULL,
  47.                                      0L, NULL, 0, &hwndClient) ;
  48.      flFrameFlags &= ~FCF_SHELLPOSITION ;
  49.      hwndChildFrame = WinCreateStdWindow (hwndClient, 0L,
  50.                                      &flFrameFlags, szChildClass, "Kid",
  51.                                      0L, NULL, 0, &hwndChildClient) ;
  52.      WinSetWindowPos(hwndChildFrame, HWND_TOP, 0, 0, 300, 200,
  53.                      SWP_SHOW | SWP_SIZE | SWP_MOVE );
  54.  
  55.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  56.           WinDispatchMsg (hab, &qmsg) ;
  57.  
  58.      WinDestroyWindow (hwndFrame) ;
  59.      WinDestroyMsgQueue (hmq) ;
  60.      WinTerminate (hab) ;
  61.      return 0 ;
  62.      }
  63.  
  64. MRESULT EXPENTRY ChildWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  65.      {
  66.      static SHORT cxClient, cyClient ;
  67.      HBITMAP      hbm ;
  68.      HPS          hps ;
  69.      POINTL       ptl ;
  70.  
  71.      switch (msg)
  72.           {
  73.           case WM_SIZE:
  74.                cxClient = SHORT1FROMMP (mp2) ;
  75.                cyClient = SHORT2FROMMP (mp2) ;
  76.                return 0 ;
  77.  
  78.           case WM_PAINT:
  79.  
  80.                /* By taking care of the drawing in here, the bitmap or 
  81.                   the client will be redrawn when it receives this 
  82.                   message.  */
  83.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  84.                GpiErase (hps) ;
  85.  
  86.                hbm = GpiLoadBitmap (hps, NULL, IDB_HELLO,
  87.                                     (LONG) cxClient, (LONG) cyClient) ;
  88.                if (hbm)
  89.                     {
  90.                     ptl.x = 0 ;
  91.                     ptl.y = 0 ;
  92.  
  93.                     WinDrawBitmap (hps, hbm, NULL, &ptl,
  94.                                    CLR_NEUTRAL, CLR_BACKGROUND, DBM_NORMAL) ;
  95.  
  96.                     GpiDeleteBitmap (hbm) ;               
  97.                     }
  98.                WinEndPaint (hps) ;
  99.                return 0 ;
  100.           }
  101.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  102.      }
  103.  
  104. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  105.      {
  106.      static SHORT cxClient, cyClient ;
  107.      HBITMAP      hbm ;
  108.      HPS          hps ;
  109.      POINTL       ptl ;
  110.  
  111.      switch (msg)
  112.           {
  113.           case WM_SIZE:
  114.                cxClient = SHORT1FROMMP (mp2) ;
  115.                cyClient = SHORT2FROMMP (mp2) ;
  116.                return 0 ;
  117.  
  118.           case WM_PAINT:
  119.  
  120.                /* By taking care of the drawing in here, the bitmap or 
  121.                   the client will be redrawn when it receives this 
  122.                   message.    */
  123.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  124.                GpiErase (hps) ;
  125.  
  126.                hbm = GpiLoadBitmap (hps, NULL, IDB_HELLO,
  127.                                     (LONG) cxClient, (LONG) cyClient) ;
  128.                if (hbm)
  129.                     {
  130.                     ptl.x = 0 ;
  131.                     ptl.y = 0 ;
  132.  
  133.                     WinDrawBitmap (hps, hbm, NULL, &ptl,
  134.                                    CLR_NEUTRAL, CLR_BACKGROUND, DBM_NORMAL) ;
  135.  
  136.                     GpiDeleteBitmap (hbm) ;               
  137.                     }
  138.                WinEndPaint (hps) ;
  139.                return 0 ;
  140.           }
  141.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  142.      }
  143.