home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / msj / msjv3_3 / gpicode / normalps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-02  |  5.1 KB  |  166 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.    NORMALPS.C -- Demonstrates Normal-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 [] = "NormalPS" ;
  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, "Normal-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   lSegmentName   = 1 ;
  64.      static LONG   lTextLength    = sizeof szText - 1L ;
  65.      static LONG   alColorData [] = { CLR_BACKGROUND, RGB_WHITE,
  66.                                       CLR_NEUTRAL,    RGB_BLACK } ;
  67.      static POINTL aptlTextBox [TXTBOX_COUNT] ;
  68.      HDC           hdc ;
  69.      POINTL        ptl, ptlTextStart, aptlLineStart [4] ;
  70.      SHORT         cxClient, cyClient, sIndex ;
  71.      SIZEL         sizl ;
  72.  
  73.      switch (msg)
  74.           {
  75.           case WM_CREATE:
  76.                hdc = WinOpenWindowDC (hwnd) ;
  77.  
  78.                sizl.cx = 0 ;
  79.                sizl.cy = 0 ;
  80.  
  81.                hps = GpiCreatePS (hab, hdc, &sizl, PU_PELS    |
  82.                                    GPIF_DEFAULT | GPIT_NORMAL |
  83.                                    GPIM_NORMAL  | GPIA_ASSOC) ;
  84.  
  85.                GpiCreateLogColorTable (hps, LCOL_RESET,
  86.                     LCOLF_INDRGB, 0L, 4L, alColorData) ; /* temp fix */
  87.  
  88.                GpiQueryTextBox (hps, lTextLength, szText,
  89.                                 TXTBOX_COUNT, aptlTextBox) ;
  90.  
  91.                GpiSetDrawControl (hps, DCTL_ERASE, DCTL_ON) ;
  92.                GpiSetDrawingMode (hps, DM_RETAIN) ;
  93.                break ;
  94.  
  95.           case WM_SIZE:
  96.                cxClient = LOUSHORT (mp2) ;
  97.                cyClient = HIUSHORT (mp2) ;
  98.  
  99.                ptlTextStart.x = (cxClient - 
  100.                                 aptlTextBox [TXTBOX_BOTTOMRIGHT].x -
  101.                                 aptlTextBox [TXTBOX_BOTTOMLEFT].x) / 2 ;
  102.  
  103.                ptlTextStart.y = (cyClient -
  104.                                 aptlTextBox [TXTBOX_TOPLEFT].y -
  105.                                 aptlTextBox [TXTBOX_BOTTOMLEFT].y) / 2 ;
  106.  
  107.                for (sIndex = 0 ; sIndex < 4 ; sIndex ++)
  108.                     {
  109.                     aptlLineStart [sIndex] = aptlTextBox [sIndex] ;
  110.                     aptlLineStart [sIndex].x += ptlTextStart.x ;
  111.                     aptlLineStart [sIndex].y += ptlTextStart.y ;
  112.                     }
  113.  
  114.                GpiDeleteSegment (hps, lSegmentName) ;
  115.  
  116.                GpiOpenSegment (hps, lSegmentName) ;
  117.                     {
  118.                     GpiSetColor (hps, CLR_RED) ;
  119.  
  120.                     GpiCharStringAt (hps, &ptlTextStart,
  121.                                      lTextLength, szText) ;
  122.  
  123.                     GpiSetLineType (hps, LINETYPE_DOT) ;
  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.                GpiCloseSegment (hps) ;
  143.                break ;
  144.  
  145.           case WM_PAINT:
  146.                /* WinBeginPaint (hwnd, hps, NULL) ; */
  147.  
  148.                GpiDrawChain (hps) ;
  149.  
  150.                /* WinEndPaint (hps) ; */
  151.  
  152.                WinValidateRect (hwnd, NULL, FALSE) ;   /* temp fix */
  153.                break ;
  154.  
  155.           case WM_DESTROY:
  156.                GpiDeleteSegment (hps, lSegmentName) ;
  157.                GpiAssociate (hps, NULL) ;
  158.                GpiDestroyPS (hps) ;
  159.                break ;
  160.  
  161.           default:
  162.                return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  163.           }
  164.      return FALSE ;
  165.      }
  166.