home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / msj / msjv3_3 / gpicode / microps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-02  |  4.6 KB  |  156 lines

  1. /*
  2. Microsoft Systems Journal
  3. Volume 3; Issue 3; May, 1988
  4.  
  5.     pp. 9-18
  6.  
  7. Author(s): Charles Petzold
  8. Title:     The Graphics Programming Interface: A Guide to OS/2 
  9.            Presentation Spaces
  10.  
  11. */
  12.  
  13. /*------------------------------------
  14.    MICROPS.C -- Demonstrates Micro-PS
  15.   ------------------------------------*/
  16.  
  17. #define INCL_WIN
  18. #define INCL_GPI
  19.  
  20. #include <os2.h>
  21.  
  22. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  23.  
  24. HAB  hab ;
  25.  
  26. main ()
  27.      {
  28.      static CHAR szClientClass [] = "MicroPS" ;
  29.      HMQ    hmq ;
  30.      HWND   hwndFrame, hwndClient ;
  31.      QMSG   qmsg ;
  32.  
  33.      hab = WinInitialize (0) ;
  34.      hmq = WinCreateMsgQueue (hab, 0) ;
  35.  
  36.      WinRegisterClass (hab, szClientClass, ClientWndProc,
  37.                                            CS_SIZEREDRAW, 0) ;
  38.  
  39.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP,
  40.                     WS_VISIBLE | FS_SIZEBORDER | FS_TITLEBAR
  41.                                | FS_SYSMENU    | FS_MINMAX,
  42.                     szClientClass, "Micro-PS",
  43.                     0L, NULL, 0, &hwndClient) ;
  44.  
  45.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  46.           WinDispatchMsg (hab, &qmsg) ;
  47.  
  48.      WinDestroyWindow (hwndFrame) ;
  49.      WinDestroyMsgQueue (hmq) ;
  50.      WinTerminate (hab) ;
  51.  
  52.      return 0 ;
  53.      }
  54.  
  55. MRESULT EXPENTRY ClientWndProc (hwnd, msg, mp1, mp2)
  56.      HWND          hwnd ;
  57.      USHORT        msg ;
  58.      MPARAM        mp1 ;
  59.      MPARAM        mp2 ;
  60.      {
  61.      static CHAR   szText []      = "Graphics Programming Interface" ;
  62.      static HPS    hps ;
  63.      static LONG   lTextLength    = sizeof szText - 1L ;
  64.      static LONG   alColorData [] = { CLR_BACKGROUND, RGB_WHITE,
  65.                                       CLR_NEUTRAL,    RGB_BLACK } ;
  66.      static POINTL ptlTextStart, aptlLineStart [4],
  67.                    aptlTextBox [TXTBOX_COUNT] ;
  68.      static SHORT  cxClient, cyClient ;
  69.      HDC           hdc ;
  70.      POINTL        ptl ;
  71.      SHORT         sIndex ;
  72.      SIZEL         sizl ;
  73.  
  74.      switch (msg)
  75.           {
  76.           case WM_CREATE:
  77.                hdc = WinOpenWindowDC (hwnd) ;
  78.  
  79.                sizl.cx = 0 ;
  80.                sizl.cy = 0 ;
  81.  
  82.                hps = GpiCreatePS (hab, hdc, &sizl, PU_PELS |
  83.                                    GPIF_DEFAULT | GPIT_MICRO |
  84.                                    GPIM_NORMAL  | GPIA_ASSOC) ;
  85.  
  86.                GpiCreateLogColorTable (hps, LCOL_RESET,
  87.                     LCOLF_INDRGB, 0L, 4L, alColorData) ; /* temp fix */
  88.  
  89.                GpiQueryTextBox (hps, lTextLength, szText,
  90.                                 TXTBOX_COUNT, aptlTextBox) ;
  91.  
  92.                GpiSetColor (hps, CLR_RED) ;
  93.                GpiSetLineType (hps, LINETYPE_DOT) ;
  94.                break ;
  95.  
  96.           case WM_SIZE:
  97.                cxClient = LOUSHORT (mp2) ;
  98.                cyClient = HIUSHORT (mp2) ;
  99.  
  100.                ptlTextStart.x = (cxClient - 
  101.                                 aptlTextBox [TXTBOX_BOTTOMRIGHT].x -
  102.                                 aptlTextBox [TXTBOX_BOTTOMLEFT].x) / 2 ;
  103.  
  104.                ptlTextStart.y = (cyClient -
  105.                                 aptlTextBox [TXTBOX_TOPLEFT].y -
  106.                                 aptlTextBox [TXTBOX_BOTTOMLEFT].y) / 2 ;
  107.  
  108.                for (sIndex = 0 ; sIndex < 4 ; sIndex ++)
  109.                     {
  110.                     aptlLineStart [sIndex] = aptlTextBox [sIndex] ;
  111.                     aptlLineStart [sIndex].x += ptlTextStart.x ;
  112.                     aptlLineStart [sIndex].y += ptlTextStart.y ;
  113.                     }
  114.  
  115.                break ;
  116.  
  117.           case WM_PAINT:
  118.                /* BeginPaint (hwnd, hps, NULL) ; */
  119.  
  120.                GpiErase (hps) ;
  121.  
  122.                GpiCharStringAt (hps, &ptlTextStart,
  123.                                    lTextLength, szText) ;
  124.  
  125.                GpiMove (hps, aptlLineStart + TXTBOX_BOTTOMLEFT) ;
  126.                ptl.x = 0 ;
  127.                ptl.y = 0 ;
  128.                GpiLine (hps, &ptl) ;
  129.  
  130.                GpiMove (hps, aptlLineStart + TXTBOX_BOTTOMRIGHT) ;
  131.                ptl.x = cxClient ;
  132.                GpiLine (hps, &ptl) ;
  133.  
  134.                GpiMove (hps, aptlLineStart + TXTBOX_TOPRIGHT) ;
  135.                ptl.y = cyClient ;
  136.                GpiLine (hps, &ptl) ;
  137.  
  138.                GpiMove (hps, aptlLineStart + TXTBOX_TOPLEFT) ;
  139.                ptl.x = 0 ;
  140.                GpiLine (hps, &ptl) ;
  141.  
  142.                /* EndPaint (hps) ; */
  143.  
  144.                WinValidateRect (hwnd, NULL, FALSE) ;    /* temp fix */
  145.                break ;
  146.  
  147.           case WM_DESTROY:
  148.                GpiDestroyPS (hps) ;
  149.                break ;
  150.  
  151.           default:
  152.                return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  153.           }
  154.      return FALSE ;
  155.      }
  156.