home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / clines.zip / LINESTL.CPP < prev    next >
C/C++ Source or Header  |  1994-10-04  |  3KB  |  112 lines

  1. /****************************************************************/
  2. /* LINESTL.CPP                                                  */
  3. /* Custom Line style demonstration code                         */
  4. /* By Nick Hodapp, 1994                                         */
  5. /*                                                              */
  6. /* For OS/2 Developer Magazine                                  */
  7. /*                                                              */
  8. /****************************************************************/
  9.  
  10. #define INCL_WIN
  11. #define INCL_GPI
  12.  
  13. #include <os2.h>
  14.  
  15. #include "linestl.h"
  16. #include "custstl.h"
  17.  
  18. MRESULT EXPENTRY ClientWndProc (HWND,ULONG,MPARAM,MPARAM);
  19.  
  20. HAB   hab;
  21. HWND  hWndFrame,
  22.       hWndClient;
  23. CHAR  szTitle[64];
  24.  
  25. int main()
  26. {
  27.     HMQ   hmq;
  28.     QMSG  qmsg;
  29.     ULONG flFrameFlags    = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER |
  30.                                 FCF_MINMAX   | FCF_SHELLPOSITION | FCF_TASKLIST;
  31.  
  32.     CHAR  szClientClass[] = "CLIENT";
  33.  
  34.     hab = WinInitialize (0);
  35.     hmq = WinCreateMsgQueue (hab, 0);
  36.  
  37.     WinRegisterClass (hab, szClientClass, (PFNWP)ClientWndProc, 0, 0);
  38.     WinLoadString (hab, 0, ID_APPNAME, sizeof(szTitle), szTitle);
  39.  
  40.     hWndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  41.         &flFrameFlags, szClientClass, szTitle, 0, 0, ID_APPNAME, &hWndClient);
  42.  
  43.     while (WinGetMsg (hab, &qmsg, 0, 0, 0))
  44.         WinDispatchMsg (hab, &qmsg);
  45.  
  46.     WinDestroyWindow (hWndFrame);
  47.     WinDestroyMsgQueue (hmq);
  48.     WinTerminate (hab);
  49.     return (0);
  50. }
  51.  
  52. MRESULT EXPENTRY ClientWndProc (HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  53. {
  54. ULONG    i;
  55. HPS     hps;
  56. POINTL  line[2];
  57. RECTL    rectl;
  58.  
  59. static LONG maxStyle;
  60.  
  61.     switch (msg)
  62.     {
  63.     case WM_CREATE:
  64.         for (i = STYLE_RES_START ; i <= STYLE_RES_END ; i++)
  65.             maxStyle = GpiLoadLineStyle(NULLHANDLE, i);
  66.  
  67.         break;
  68.  
  69.     case WM_PAINT:
  70.         hps = WinBeginPaint (hWnd,0,0);
  71.  
  72.  
  73.         WinQueryWindowRect(hWnd, &rectl);
  74.         WinFillRect(hps, &rectl, CLR_WHITE);
  75.  
  76.         line[0].x = 50;
  77.         line[0].y = 15;
  78.         line[1].x = rectl.xRight - rectl.xLeft - 50;
  79.         line[1].y = 15;
  80.  
  81.         for (i = 20 ; i <= maxStyle ; i++) {
  82.  
  83.             GpiSetLineType(hps, i);
  84.             GpiMove(hps, &line[0]);
  85.             GpiLine(hps, &line[1]);
  86.  
  87.             line[0].y += 20;
  88.             line[1].y += 20;
  89.         }
  90.  
  91.         WinEndPaint (hps);
  92.         break;
  93.  
  94.     case WM_SIZE:
  95.         WinInvalidateRect(hWnd, NULL, TRUE);
  96.         break;
  97.  
  98.     case WM_ERASEBACKGROUND:
  99.         return (MRESULT) TRUE;
  100.  
  101.     case WM_DESTROY:
  102.         for (i = 10 ; i <= maxStyle ; i++)
  103.             GpiFreeLineStyle(i);
  104.  
  105.         break;
  106.     }
  107.  
  108.     return WinDefWindowProc (hWnd,msg,mp1,mp2);
  109. }
  110.  
  111.  
  112.