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

  1. /*
  2.  *  Pie
  3.  *
  4.  *  This function demonstrates the use of the Pie function.  It will create
  5.  *  a window, and procede to draw a pie inside of that window
  6.  *
  7.  */
  8.  
  9. #include <windows.h>
  10.  
  11. BOOL FAR PASCAL InitPie (HANDLE, HANDLE, int);
  12. long    FAR PASCAL PieWindowProc (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.   InitPie (hInstance, hPrevInstance, cmdShow);
  22.  
  23.   while (GetMessage((LPMSG) & msg, NULL, 0, 0))
  24.   {
  25.     TranslateMessage((LPMSG) & msg);
  26.     DispatchMessage((LPMSG) & msg);
  27.   }
  28.  
  29.   exit(msg.wParam);
  30. }
  31.  
  32.  
  33. BOOL FAR PASCAL InitPie (hInstance, hPrevInstance, cmdShow)
  34.  
  35. HANDLE hInstance;
  36. HANDLE hPrevInstance;
  37. int    cmdShow;
  38.  
  39. {
  40.   WNDCLASS  wcPieClass;
  41.   HWND hWnd;
  42.  
  43.   wcPieClass.lpszClassName = (LPSTR) "Pie";
  44.   wcPieClass.hInstance    = hInstance;
  45.   wcPieClass.lpfnWndProc   = PieWindowProc;
  46.   wcPieClass.hCursor    = LoadCursor (NULL, IDC_ARROW);
  47.   wcPieClass.hIcon    = NULL;
  48.   wcPieClass.lpszMenuName  = (LPSTR) NULL;
  49.   wcPieClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  50.   wcPieClass.style    = CS_HREDRAW | CS_VREDRAW;
  51.   wcPieClass.cbClsExtra    = 0;
  52.   wcPieClass.cbWndExtra    = 0;
  53.  
  54.   RegisterClass ((LPWNDCLASS) & wcPieClass);
  55.  
  56.   hWnd = CreateWindow((LPSTR) "Pie", (LPSTR) "Pie", 
  57.       WS_OVERLAPPEDWINDOW, 
  58.       CW_USEDEFAULT,  0,
  59.       CW_USEDEFAULT,  0,
  60.       NULL,  NULL,  hInstance, NULL);
  61.  
  62.   ShowWindow (hWnd, cmdShow);
  63.   UpdateWindow (hWnd);
  64.  
  65.   return TRUE;
  66. }
  67.  
  68.  
  69. long    FAR PASCAL PieWindowProc (hWnd, message, wParam, lParam)
  70.  
  71. HWND     hWnd;
  72. unsigned    message;
  73. WORD     wParam;
  74. LONG     lParam;
  75. {
  76.   switch (message)
  77.   {
  78.   case WM_PAINT:
  79.     PaintPieWindow (hWnd);
  80.     break;
  81.  
  82.   case WM_DESTROY:
  83.     PostQuitMessage(0);
  84.     break;
  85.  
  86.   default:
  87.     return(DefWindowProc(hWnd, message, wParam, lParam));
  88.     break;
  89.   }
  90.   return(0L);
  91. }
  92.  
  93.  
  94. PaintPieWindow (hWnd)
  95.  
  96. HWND hWnd;
  97. {
  98.   PAINTSTRUCT ps;
  99.   HDC  hDC;
  100.  
  101.   BeginPaint (hWnd, (LPPAINTSTRUCT) & ps);
  102.   hDC = ps.hdc;
  103.  
  104.   Pie (hDC, 100, 100, 300, 300, 300, 200, 200, 100);
  105. /*  Draw the Pie
  106.   *  Upper Left of box holding pie slice  = 100, 100
  107.   *  Lower Right of box holding pie slice = 300, 300
  108.   *  Start the arc at 300, 300
  109.   *  End the arc at 200, 100
  110.   *  The arc will be drawn in a counter clockwise direction
  111.   */
  112.  
  113.   ValidateRect (hWnd, (LPRECT) NULL);
  114.   EndPaint (hWnd, (LPPAINTSTRUCT) & ps);
  115.  
  116.   return TRUE;
  117. }
  118.  
  119.  
  120.