home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / BOXES1.ZIP / BOXES1.C < prev    next >
C/C++ Source or Header  |  1988-11-27  |  4KB  |  104 lines

  1. /*----------------------------------------------------------------------
  2.    BOXES1.C -- OS/2 PM program that draws nested boxes in client window
  3.                (c) 1988, Ziff Communications Company
  4.                PC Magazine * Charles Petzold, 4/88 and 11/88
  5.   ----------------------------------------------------------------------*/
  6.  
  7. #define INCL_WIN
  8. #include <os2.h>
  9.  
  10. #define NUMBOXES  50     /* number of boxes to draw    */
  11. #define INCREMENT 20     /* rotate each 1/20th of side */
  12.  
  13. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  14.  
  15. int main (void)
  16.      {
  17.      static CHAR  szClientClass [] = "Boxes1" ;
  18.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  19.                                  FCF_SIZEBORDER    | FCF_MINMAX  |
  20.                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
  21.      HAB          hab ;
  22.      HMQ          hmq ;
  23.      HWND         hwndFrame, hwndClient ;
  24.      QMSG         qmsg ;
  25.  
  26.      hab = WinInitialize (0) ;
  27.      hmq = WinCreateMsgQueue (hab, 0) ;
  28.  
  29.      WinRegisterClass (
  30.                     hab,                /* Anchor block handle             */
  31.                     szClientClass,      /* Name of class being registered  */
  32.                     ClientWndProc,      /* Window procedure for class      */
  33.                     CS_SIZEREDRAW,      /* Class style                     */
  34.                     0) ;                /* Extra bytes to reserve          */
  35.  
  36.      hwndFrame = WinCreateStdWindow (
  37.                     HWND_DESKTOP,       /* Parent window handle            */
  38.                     WS_VISIBLE,         /* Style of frame window           */
  39.                     &flFrameFlags,      /* Frame creation flags            */
  40.                     szClientClass,      /* Client window class name        */
  41.                     NULL,               /* Title bar text                  */
  42.                     0L,                 /* Style of client window          */
  43.                     NULL,               /* Module handle for resources     */
  44.                     0,                  /* ID of resources                 */
  45.                     &hwndClient) ;      /* Pointer to client window handle */
  46.  
  47.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  48.           WinDispatchMsg (hab, &qmsg) ;
  49.  
  50.      WinDestroyWindow (hwndFrame) ;
  51.      WinDestroyMsgQueue (hmq) ;
  52.      WinTerminate (hab) ;
  53.      return 0 ;
  54.      }
  55.  
  56. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  57.      {
  58.      static SHORT xClient, yClient ;
  59.      HPS          hps;
  60.      POINTL       aptl[5] ;
  61.      SHORT        sRep, sSide ;
  62.  
  63.      switch (msg)
  64.           {
  65.           case WM_SIZE:
  66.                xClient = SHORT1FROMMP (mp2) ;
  67.                yClient = SHORT2FROMMP (mp2) ;
  68.                return 0 ;
  69.  
  70.           case WM_ERASEBACKGROUND:
  71.                return TRUE ;
  72.  
  73.           case WM_PAINT:
  74.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  75.  
  76.                aptl[0].x = aptl[1].x = 0 ;
  77.                aptl[2].x = aptl[3].x = xClient - 1 ;
  78.                aptl[0].y = aptl[3].y = 0 ;
  79.                aptl[1].y = aptl[2].y = yClient - 1 ;
  80.  
  81.                for (sRep = 0 ; sRep < NUMBOXES ; sRep ++)
  82.                     {
  83.                     aptl[4] = aptl[0] ;
  84.  
  85.                     GpiMove (hps, aptl) ;
  86.                     GpiPolyLine (hps, 4L, aptl + 1) ;
  87.  
  88.                     for (sSide = 0 ; sSide < 4 ; sSide++)
  89.                          {
  90.                          aptl[sSide].x = ((INCREMENT - 1) * aptl[sSide].x +
  91.                                              aptl[sSide + 1].x +
  92.                                                   INCREMENT / 2) / INCREMENT ;
  93.  
  94.                          aptl[sSide].y = ((INCREMENT - 1) * aptl[sSide].y +
  95.                                              aptl[sSide + 1].y +
  96.                                                   INCREMENT / 2) / INCREMENT ;
  97.                          }
  98.                     }
  99.                WinEndPaint (hps) ;
  100.                return 0 ;
  101.           }
  102.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  103.      }
  104.