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

  1. /*
  2.  *  Function Name:   Arc
  3.  *  SDK Version:         2.03
  4.  *  Runtime Version:     2.03
  5.  *  Microsoft C Version: 5.1
  6.  *
  7.  *  Description:
  8.  *   The program below will draw an arc.
  9.  */
  10.  
  11. #include "windows.h"
  12.  
  13. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  14.  
  15. /***********************************************************************/
  16.  
  17. void CALL_Arc (hWnd, hDC)
  18. HWND hWnd;
  19. HDC hDC;
  20.   {
  21.   BOOL      bDrawn;
  22.   int   xScreen, yScreen;
  23.  
  24.   xScreen = GetSystemMetrics (SM_CXSCREEN);
  25.   yScreen = GetSystemMetrics (SM_CYSCREEN);
  26.  
  27.   bDrawn = Arc (hDC, xScreen / 3, yScreen / 3, (2 * xScreen) / 3, (2 * yScreen) / 3,
  28.       (2 * xScreen) / 5, (2 * yScreen) / 5, xScreen / 2, yScreen / 2);  /* function demonstrated  */
  29.  
  30.   if (bDrawn != TRUE)
  31.     MessageBeep (MB_OK);  /*  Couldn't Draw the ARC, so BEEP!!!  */
  32.  
  33.   return;
  34.   }
  35.  
  36.  
  37. /**************************************************************************/
  38.  
  39. /* Procedure called when the application is loaded for the first time */
  40. BOOL WinInit (hInstance)
  41. HANDLE hInstance;
  42.   {
  43.   WNDCLASS   wcClass;
  44.  
  45.   wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  46.   wcClass.lpfnWndProc    = WndProc;
  47.   wcClass.cbClsExtra     = 0;
  48.   wcClass.cbWndExtra     = 0;
  49.   wcClass.hInstance      = hInstance;
  50.   wcClass.hIcon          = LoadIcon (hInstance, NULL);
  51.   wcClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  52.   wcClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  53.   wcClass.lpszMenuName   = (LPSTR)NULL;
  54.   wcClass.lpszClassName  = (LPSTR)"Arc";
  55.  
  56.   if (!RegisterClass ( (LPWNDCLASS) & wcClass))
  57.     return FALSE;
  58.  
  59.   return TRUE;
  60.   }
  61.  
  62.  
  63. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  64. HANDLE    hInstance, hPrevInstance;
  65. LPSTR     lpszCmdLine;
  66. int       cmdShow;
  67.   {
  68.   MSG   msg;
  69.   HWND  hWnd;
  70.  
  71.   if (!hPrevInstance)
  72.     if (!WinInit (hInstance))
  73.       return FALSE;
  74.  
  75.   hWnd = CreateWindow ( (LPSTR)"Arc", (LPSTR)"Arc ()",
  76.                       WS_OVERLAPPEDWINDOW,
  77.                       CW_USEDEFAULT, 0,
  78.                       CW_USEDEFAULT, 0,
  79.                       NULL, NULL, hInstance, NULL);
  80.  
  81.   ShowWindow (hWnd, cmdShow);
  82.   UpdateWindow (hWnd);
  83.  
  84.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  85.     {
  86.     TranslateMessage ( (LPMSG) & msg);
  87.     DispatchMessage ( (LPMSG) & msg);
  88.     }
  89.   return (int)msg.wParam;
  90.   }
  91.  
  92. /* Procedures which make up the window class. */
  93. long    FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  94. HWND hWnd;
  95. unsigned    message;
  96. WORD wParam;
  97. LONG lParam;
  98.   {
  99.   PAINTSTRUCT ps;
  100.  
  101.   switch (message)
  102.     {
  103.     case WM_PAINT:
  104.       BeginPaint (hWnd, (LPPAINTSTRUCT) & ps);
  105.       CALL_Arc (hWnd, ps.hdc);
  106.       ValidateRect (hWnd, (LPRECT) NULL);
  107.       EndPaint (hWnd, (LPPAINTSTRUCT) & ps);
  108.       break;
  109.  
  110.     case WM_DESTROY:
  111.       PostQuitMessage (0);
  112.       break;
  113.  
  114.     default:
  115.       return DefWindowProc (hWnd, message, wParam, lParam);
  116.       break;
  117.     }
  118.   return (0L);
  119.   }
  120.