home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / graphics / polyline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.3 KB  |  154 lines

  1. /*
  2.  *  Polyline
  3.  *
  4.  *  This function demonstrates the use of the Polyline function.  It will
  5.  *  create a window, and procede to draw a small 3-D Box in the window.
  6.  *
  7.  */
  8.  
  9. #include <windows.h>
  10.  
  11. BOOL FAR PASCAL InitPolyline (HANDLE, HANDLE, int);
  12. long    FAR PASCAL PolylineWindowProc (HANDLE, unsigned, WORD, LONG);
  13.  
  14. int    PASCAL WinMain  (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  15.  
  16. HANDLE hInstance, hPrevInstance;
  17. LPSTR  lpszCmdLine;
  18. int    cmdShow;
  19. {
  20.   MSG  msg;
  21.  
  22.   InitPolyline (hInstance, hPrevInstance, cmdShow);
  23.  
  24.   while (GetMessage((LPMSG) & msg, NULL, 0, 0))
  25.   {
  26.     TranslateMessage((LPMSG) & msg);
  27.     DispatchMessage((LPMSG) & msg);
  28.   }
  29.  
  30.   exit(msg.wParam);
  31. }
  32.  
  33.  
  34. BOOL FAR PASCAL InitPolyline (hInstance, hPrevInstance, cmdShow)
  35.  
  36. HANDLE hInstance;
  37. HANDLE hPrevInstance;
  38. int    cmdShow;
  39.  
  40. {
  41.   WNDCLASS  wcPolylineClass;
  42.   HWND hWnd;
  43.  
  44.   wcPolylineClass.lpszClassName = (LPSTR) "Polyline";
  45.   wcPolylineClass.hInstance     = hInstance;
  46.   wcPolylineClass.lpfnWndProc   = PolylineWindowProc;
  47.   wcPolylineClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  48.   wcPolylineClass.hIcon         = NULL;
  49.   wcPolylineClass.lpszMenuName  = (LPSTR) NULL;
  50.   wcPolylineClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  51.   wcPolylineClass.style         = CS_HREDRAW | CS_VREDRAW;
  52.   wcPolylineClass.cbClsExtra    = 0;
  53.   wcPolylineClass.cbWndExtra    = 0;
  54.  
  55.   RegisterClass ((LPWNDCLASS) & wcPolylineClass);
  56.  
  57.   hWnd = CreateWindow((LPSTR) "Polyline", (LPSTR) "Polyline",
  58.       WS_OVERLAPPEDWINDOW, 
  59.       CW_USEDEFAULT,  0,
  60.       CW_USEDEFAULT,  0,
  61.       NULL,  NULL,  hInstance, NULL);
  62.  
  63.   ShowWindow (hWnd, cmdShow);
  64.   UpdateWindow (hWnd);
  65.  
  66.   return TRUE;
  67. }
  68.  
  69.  
  70. long    FAR PASCAL PolylineWindowProc (hWnd, message, wParam, lParam)
  71.  
  72. HWND     hWnd;
  73. unsigned    message;
  74. WORD     wParam;
  75. LONG     lParam;
  76. {
  77.   switch (message)
  78.   {
  79.   case WM_PAINT:
  80.     PaintPolylineWindow (hWnd);
  81.     break;
  82.  
  83.   case WM_DESTROY:
  84.     PostQuitMessage(0);
  85.     break;
  86.  
  87.   default:
  88.     return(DefWindowProc(hWnd, message, wParam, lParam));
  89.     break;
  90.   }
  91.   return(0L);
  92. }
  93.  
  94.  
  95. PaintPolylineWindow (hWnd)
  96.  
  97. HWND hWnd;
  98. {
  99.   PAINTSTRUCT ps;
  100.   HDC  hDC;
  101.   POINT       lpSide1[4];
  102.   POINT       lpSide2[4];
  103.   POINT       lpSide3[4];
  104.   POINT       lpSide4[4];
  105.  
  106.   BeginPaint (hWnd, (LPPAINTSTRUCT) & ps);
  107.   hDC = ps.hdc;
  108.  
  109.   lpSide1[0].x = 140;  /*  The values of the box  */
  110.   lpSide1[0].y = 130;
  111.   lpSide1[1].x = 100;
  112.   lpSide1[1].y = 100;
  113.   lpSide1[2].x = 170;
  114.   lpSide1[2].y = 100;
  115.   lpSide1[3].x = 200;
  116.   lpSide1[3].y = 130;
  117.   lpSide2[0].x = 100;
  118.   lpSide2[0].y = 100;
  119.   lpSide2[1].x = 100;
  120.   lpSide2[1].y = 170;
  121.   lpSide2[2].x = 170;
  122.   lpSide2[2].y = 170;
  123.   lpSide2[3].x = 170;
  124.   lpSide2[3].y = 100;
  125.   lpSide3[0].x = 100;
  126.   lpSide3[0].y = 170;
  127.   lpSide3[1].x = 140;
  128.   lpSide3[1].y = 200;
  129.   lpSide3[2].x = 200;
  130.   lpSide3[2].y = 200;
  131.   lpSide3[3].x = 170;
  132.   lpSide3[3].y = 170;
  133.   lpSide4[0].x = 140;
  134.   lpSide4[0].y = 200;
  135.   lpSide4[1].x = 140;
  136.   lpSide4[1].y = 130;
  137.   lpSide4[2].x = 200;
  138.   lpSide4[2].y = 130;
  139.   lpSide4[3].x = 200;
  140.   lpSide4[3].y = 200;
  141.  
  142.   Polyline(hDC, lpSide1, 4);  /*  Draw the sides of the box  */
  143.   Polyline(hDC, lpSide2, 4);
  144.   Polyline(hDC, lpSide3, 4);
  145.   Polyline(hDC, lpSide4, 4);
  146.  
  147.   ValidateRect (hWnd, (LPRECT) NULL);
  148.   EndPaint (hWnd, (LPPAINTSTRUCT) & ps);
  149.  
  150.   return TRUE;
  151. }
  152.  
  153.  
  154.