home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP04 / ENDJOIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  3.8 KB  |  119 lines

  1. /*----------------------------------------
  2.    ENDJOIN.C -- Ends and Joins Demo
  3.                 (c) Charles Petzold, 1996
  4.   ----------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  11.                     PSTR szCmdLine, int iCmdShow)
  12.      {
  13.      static char szAppName[] = "EndJoin" ;
  14.      HWND        hwnd ;
  15.      MSG         msg ;
  16.      WNDCLASSEX  wndclass ;
  17.  
  18.      wndclass.cbSize        = sizeof (WNDCLASSEX) ;
  19.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  20.      wndclass.lpfnWndProc   = WndProc ;
  21.      wndclass.cbClsExtra    = 0 ;
  22.      wndclass.cbWndExtra    = 0 ;
  23.      wndclass.hInstance     = hInstance ;
  24.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  25.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  26.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  27.      wndclass.lpszMenuName  = NULL ;
  28.      wndclass.lpszClassName = szAppName ;
  29.      wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
  30.  
  31.      RegisterClassEx (&wndclass) ;
  32.  
  33.      hwnd = CreateWindow (szAppName, "Ends and Joins Demo",
  34.                           WS_OVERLAPPEDWINDOW,
  35.                           CW_USEDEFAULT, CW_USEDEFAULT,
  36.                           CW_USEDEFAULT, CW_USEDEFAULT,
  37.                           NULL, NULL, hInstance, NULL) ;
  38.  
  39.      ShowWindow (hwnd, iCmdShow) ;
  40.      UpdateWindow (hwnd) ;
  41.  
  42.      while (GetMessage (&msg, NULL, 0, 0))
  43.           {
  44.           TranslateMessage (&msg) ;
  45.           DispatchMessage (&msg) ;
  46.           }
  47.      return msg.wParam ;
  48.      }
  49.  
  50. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  51.      {
  52.      static int  iEnd  [] = { PS_ENDCAP_ROUND, PS_ENDCAP_SQUARE,
  53.                               PS_ENDCAP_FLAT } ;
  54.      static int  iJoin [] = { PS_JOIN_ROUND,   PS_JOIN_BEVEL,
  55.                               PS_JOIN_MITER } ;
  56.      static int  cxClient, cyClient ;
  57.      HDC         hdc ;
  58.      int         i ;
  59.      LOGBRUSH    lb ;
  60.      PAINTSTRUCT ps ;
  61.  
  62.      switch (iMsg)
  63.           {
  64.           case WM_SIZE:
  65.                cxClient = LOWORD (lParam) ;
  66.                cyClient = HIWORD (lParam) ;
  67.                return 0 ;
  68.  
  69.           case WM_PAINT:
  70.            hdc = BeginPaint (hwnd, &ps) ;
  71.  
  72.                SetMapMode (hdc, MM_ANISOTROPIC) ;
  73.                SetWindowExtEx (hdc, 100, 100, NULL) ;
  74.                SetViewportExtEx (hdc, cxClient, cyClient, NULL) ;
  75.  
  76.                lb.lbStyle = BS_SOLID ;
  77.                lb.lbColor = RGB (128, 128, 128) ;
  78.                lb.lbHatch = 0 ;
  79.  
  80.  
  81.                for (i = 0 ; i < 3 ; i++)
  82.                     {
  83.                     SelectObject (hdc,
  84.                          ExtCreatePen (PS_SOLID | PS_GEOMETRIC |
  85.                                        iEnd [i] | iJoin [i], 10,
  86.                                        &lb, 0, NULL)) ;
  87.  
  88.                     BeginPath (hdc) ;
  89.  
  90.                     MoveToEx (hdc, 10 + 30 * i, 25, NULL) ;
  91.                     LineTo   (hdc, 20 + 30 * i, 75) ;
  92.                     LineTo   (hdc, 30 + 30 * i, 25) ;
  93.  
  94.  
  95.                     EndPath (hdc) ;
  96.  
  97.                     StrokePath (hdc) ;
  98.  
  99.                     DeleteObject (
  100.                          SelectObject (hdc,
  101.                               GetStockObject (BLACK_PEN))) ;
  102.  
  103.                     MoveToEx (hdc, 10 + 30 * i, 25, NULL) ;
  104.                     LineTo   (hdc, 20 + 30 * i, 75) ;
  105.                     LineTo   (hdc, 30 + 30 * i, 25) ;
  106.                     }
  107.  
  108.  
  109.            EndPaint (hwnd, &ps) ;
  110.                return 0 ;
  111.  
  112.           case WM_DESTROY:
  113.                PostQuitMessage (0) ;
  114.                return 0 ;
  115.           }
  116.  
  117.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  118.      }
  119.