home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / msj / msjv3_3 / gpicode / cachedps.c next >
Encoding:
C/C++ Source or Header  |  1989-03-02  |  4.4 KB  |  145 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.    CACHEDPS.C -- Demonstrates Cached Micro-PS
  15.   --------------------------------------------*/
  16.  
  17. #define INCL_GPI
  18.  
  19. #include <os2.h>
  20.  
  21. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  22.  
  23. main ()
  24.      {
  25.      static CHAR szClientClass [] = "CachedPS" ;
  26.      HAB    hab ;
  27.      HMQ    hmq ;
  28.      HWND   hwndFrame, hwndClient ;
  29.      QMSG   qmsg ;
  30.  
  31.      hab = WinInitialize (0) ;
  32.      hmq = WinCreateMsgQueue (hab, 0) ;
  33.  
  34.      WinRegisterClass (hab, szClientClass, ClientWndProc,
  35.                                            CS_SIZEREDRAW, 0) ;
  36.  
  37.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP,
  38.                     WS_VISIBLE | FS_SIZEBORDER | FS_TITLEBAR
  39.                                | FS_SYSMENU    | FS_MINMAX,
  40.                     szClientClass, "Cached Micro-PS",
  41.                     0L, NULL, 0, &hwndClient) ;
  42.  
  43.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  44.           WinDispatchMsg (hab, &qmsg) ;
  45.  
  46.      WinDestroyWindow (hwndFrame) ;
  47.      WinDestroyMsgQueue (hmq) ;
  48.      WinTerminate (hab) ;
  49.  
  50.      return 0 ;
  51.      }
  52.  
  53. MRESULT EXPENTRY ClientWndProc (hwnd, msg, mp1, mp2)
  54.      HWND          hwnd ;
  55.      USHORT        msg ;
  56.      MPARAM        mp1 ;
  57.      MPARAM        mp2 ;
  58.      {
  59.      static CHAR   szText []      = "Graphics Programming Interface" ;
  60.      static LONG   lTextLength    = sizeof szText - 1L ;
  61.      static LONG   alColorData [] = { CLR_BACKGROUND, RGB_WHITE,
  62.                                       CLR_NEUTRAL,    RGB_BLACK } ;
  63.      static POINTL ptlTextStart, aptlLineStart [4],
  64.                    aptlTextBox [TXTBOX_COUNT] ;
  65.      static SHORT  cxClient, cyClient ;
  66.      HPS           hps ;
  67.      POINTL        ptl ;
  68.      SHORT         sIndex ;
  69.  
  70.      switch (msg)
  71.           {
  72.           case WM_CREATE:
  73.                hps = WinGetPS (hwnd) ;
  74.  
  75.                GpiQueryTextBox (hps, lTextLength, szText,
  76.                                 TXTBOX_COUNT, aptlTextBox) ;
  77.  
  78.                WinReleasePS (hps) ;
  79.                break ;
  80.  
  81.           case WM_SIZE:
  82.                cxClient = LOUSHORT (mp2) ;
  83.                cyClient = HIUSHORT (mp2) ;
  84.  
  85.                ptlTextStart.x = (cxClient - 
  86.                                 aptlTextBox [TXTBOX_BOTTOMRIGHT].x -
  87.                                 aptlTextBox [TXTBOX_BOTTOMLEFT].x) / 2 ;
  88.  
  89.                ptlTextStart.y = (cyClient -
  90.                                 aptlTextBox [TXTBOX_TOPLEFT].y -
  91.                                 aptlTextBox [TXTBOX_BOTTOMLEFT].y) / 2 ;
  92.  
  93.                for (sIndex = 0 ; sIndex < 4 ; sIndex ++)
  94.                     {
  95.                     aptlLineStart [sIndex] = aptlTextBox [sIndex] ;
  96.                     aptlLineStart [sIndex].x += ptlTextStart.x ;
  97.                     aptlLineStart [sIndex].y += ptlTextStart.y ;
  98.                     }
  99.                break ;
  100.  
  101.           case WM_PAINT:
  102.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  103.  
  104.                GpiSavePS (hps) ;                         /* temp fix */
  105.                GpiResetPS (hps, GRES_ATTRS) ;            /* temp fix */
  106.                GpiCreateLogColorTable (hps, LCOL_RESET,
  107.                     LCOLF_INDRGB, 0L, 4L, alColorData) ; /* temp fix */
  108.  
  109.                GpiErase (hps) ;
  110.  
  111.                GpiSetColor (hps, CLR_RED) ;
  112.  
  113.                GpiCharStringAt (hps, &ptlTextStart,
  114.                                    lTextLength, szText) ;
  115.  
  116.                GpiSetLineType (hps, LINETYPE_DOT) ;
  117.  
  118.                GpiMove (hps, aptlLineStart + TXTBOX_BOTTOMLEFT) ;
  119.                ptl.x = 0 ;
  120.                ptl.y = 0 ;
  121.                GpiLine (hps, &ptl) ;
  122.  
  123.                GpiMove (hps, aptlLineStart + TXTBOX_BOTTOMRIGHT) ;
  124.                ptl.x = cxClient ;
  125.                GpiLine (hps, &ptl) ;
  126.  
  127.                GpiMove (hps, aptlLineStart + TXTBOX_TOPRIGHT) ;
  128.                ptl.y = cyClient ;
  129.                GpiLine (hps, &ptl) ;
  130.  
  131.                GpiMove (hps, aptlLineStart + TXTBOX_TOPLEFT) ;
  132.                ptl.x = 0 ;
  133.                GpiLine (hps, &ptl) ;
  134.  
  135.                GpiRestorePS (hps, -1L) ;    /* temp fix */
  136.  
  137.                WinEndPaint (hps) ;
  138.                break ;
  139.  
  140.           default:
  141.                return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  142.           }
  143.      return FALSE ;
  144.      }
  145.