home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / METATEST.ZIP / STAR5.C < prev    next >
Text File  |  1990-05-22  |  4KB  |  155 lines

  1. /*---------------------------------
  2.    STAR5.C -- Draws 5-Pointed Star
  3.  ----------------------------------*/
  4.  
  5. /*
  6. Modified to write a PM metafile which can be viewed by the PM Picture
  7. displayer within the utilities directory of the OS/2 1.2 Desktop.
  8. */
  9.  
  10.  
  11.  
  12. #define INCL_GPI
  13.  
  14. #include <os2.h>
  15.  
  16. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  17.  
  18. /* Added for metafile */
  19. DEVOPENSTRUC dop;
  20.  
  21. HDC            hdc;
  22. HDC            hdcMeta;
  23. HPS            hpsMeta;
  24. HMF            hmf;
  25. SIZEL            sizlPage;
  26. POINTL        ptl1, ptl2;
  27. /* End of metafile stuff */
  28.  
  29. int main (void)
  30.      {
  31.      static CHAR  szClientClass [] = "Star5" ;
  32.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  33.                                  FCF_SIZEBORDER    | FCF_MINMAX  |
  34.                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
  35.      HAB          hab ;
  36.      HMQ          hmq ;
  37.      HWND         hwndFrame, hwndClient ;
  38.      QMSG         qmsg ;
  39.  
  40.      hab = WinInitialize (0) ;
  41.  
  42.      hmq = WinCreateMsgQueue (hab, 0) ;
  43.  
  44.      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
  45.  
  46.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  47.                                      &flFrameFlags, szClientClass, NULL,
  48.                                      0L, NULL, 0, &hwndClient) ;
  49.  
  50. /* Added for metafile */
  51.     dop.pszLogAddress = NULL;    
  52.     dop.pszDriverName = "DISPLAY";    
  53.     dop.pdriv = NULL;    
  54.     dop.pszDataType = NULL;    
  55.  
  56.     hdcMeta = DevOpenDC(hab,
  57.                 OD_METAFILE,
  58.                 "*",
  59.                 4L,
  60.                 (PDEVOPENDATA) &dop,
  61.                 hdc);
  62.  
  63.     hpsMeta = GpiCreatePS(hab,
  64.                 hdcMeta,
  65.                 &sizlPage,
  66.                 PU_PELS | GPIA_ASSOC);
  67.  
  68. /* Draw box in metafile */
  69.  
  70.     GpiSetColor(hpsMeta, CLR_CYAN);
  71.     ptl1.x = 150;
  72.     ptl1.y = 200;
  73.     GpiMove(hpsMeta, &ptl1);
  74.     ptl2.x = 300;
  75.     ptl2.y = 275;
  76.     GpiBox(hpsMeta, DRO_FILL, &ptl2, 0L, 0L);
  77.  
  78.     GpiSetColor(hpsMeta, CLR_GREEN);
  79.     ptl1.x = 300;
  80.     ptl1.y = 200;
  81.     GpiMove(hpsMeta, &ptl1);
  82.     ptl2.x = 390;
  83.     ptl2.y = 275;
  84.     GpiBox(hpsMeta, DRO_FILL, &ptl2, 0L, 0L);
  85.  
  86.     GpiSetColor(hpsMeta, CLR_YELLOW);
  87.     ptl1.x = 390;
  88.     ptl1.y = 200;
  89.     GpiMove(hpsMeta, &ptl1);
  90.     ptl2.x = 530;
  91.     ptl2.y = 275;
  92.     GpiBox(hpsMeta, DRO_FILL, &ptl2, 0L, 0L);
  93.  
  94.     GpiSetColor(hpsMeta, CLR_PINK);
  95.     ptl1.x = 175;
  96.     ptl1.y = 230;
  97.     GpiMove(hpsMeta, &ptl1);
  98.     GpiCharString(hpsMeta, 41L,
  99.     "This is a sample Metafile created by Dan.");
  100.  
  101.     GpiAssociate(hpsMeta, NULL);
  102.     hmf = DevCloseDC(hdcMeta);
  103.  
  104.     /* Sabve metafile to disk */
  105.     GpiSaveMetaFile(hmf, "box.met");
  106.  
  107. /* End of metafile code */
  108.  
  109.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  110.           WinDispatchMsg (hab, &qmsg) ;
  111.  
  112.      WinDestroyWindow (hwndFrame) ;
  113.      WinDestroyMsgQueue (hmq) ;
  114.      WinTerminate (hab) ;
  115.      return 0 ;
  116.      }
  117.  
  118.  
  119.  
  120. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  121.      {
  122.      static POINTL aptlStar[5] = {-59,-81, 0,100, 59,-81, -95,31, 95,31 } ;
  123.      static SHORT  cxClient, cyClient ;
  124.      HPS           hps ;
  125.      POINTL        aptl[5] ;
  126.      SHORT         sIndex ;
  127.  
  128.      switch (msg)
  129.       {
  130.           case WM_SIZE:
  131.                cxClient = SHORT1FROMMP (mp2) ;
  132.                cyClient = SHORT2FROMMP (mp2) ;
  133.                return 0 ;
  134.  
  135.           case WM_PAINT:
  136.  
  137.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  138.                GpiErase (hps) ;
  139.  
  140.                for (sIndex = 0 ; sIndex < 5 ; sIndex++)
  141.                     {
  142.                     aptl[sIndex].x = cxClient / 2 + cxClient *
  143.                                                  aptlStar[sIndex].x / 200 ;
  144.                     aptl[sIndex].y = cyClient / 2 + cyClient *
  145.                                                  aptlStar[sIndex].y / 200 ;
  146.                     }
  147.                GpiMove (hps, aptl + 4) ;
  148.                GpiPolyLine (hps, 5L, aptl) ;
  149.  
  150.                WinEndPaint (hps) ;
  151.                return 0 ;
  152.           }
  153.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  154.      }
  155.