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

  1. /*
  2.  *  Function Name:   Ellipse
  3.  *  Program Name:    ellipse.c
  4.  *  Special Notes:
  5.  *
  6.  *  SDK Version:         2.03
  7.  *  Runtime Version:     2.03
  8.  *  Microsoft C Version: 5.0
  9.  *
  10.  *  Description:
  11.  *   The program below will draw an ellipse on the display.
  12.  *
  13.  */
  14.  
  15. #include "windows.h"
  16.  
  17. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  18.  
  19. /***********************************************************************/
  20.  
  21. void CALL_Ellipse(hWnd, hDC)
  22. HWND hWnd;
  23. HDC hDC;
  24. {
  25.   BOOL      bDrawn;
  26.  
  27.   bDrawn = Ellipse (hDC, 10, 10, 300, 150);
  28.  
  29.   if (bDrawn == FALSE)
  30.     MessageBox(hWnd,(LPSTR)"Ellipse failed",(LPSTR)"ERROR",MB_ICONHAND);
  31.  
  32.   return;
  33. }
  34.  
  35. /**************************************************************************/
  36.  
  37. /* Procedure called when the application is loaded for the first time */
  38. BOOL WinInit( hInstance )
  39. HANDLE hInstance;
  40. {
  41.     WNDCLASS   wcClass;
  42.  
  43.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  44.     wcClass.lpfnWndProc    = WndProc;
  45.     wcClass.cbClsExtra     =0;
  46.     wcClass.cbWndExtra     =0;
  47.     wcClass.hInstance      = hInstance;
  48.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  49.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  50.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  51.     wcClass.lpszMenuName   = (LPSTR)NULL;
  52.     wcClass.lpszClassName  = (LPSTR)"Ellipse";
  53.  
  54.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  55.         /* Initialization failed.
  56.          * Windows will automatically deallocate all allocated memory.
  57.          */
  58.         return FALSE;
  59.  
  60.     return TRUE;        /* Initialization succeeded */
  61. }
  62.  
  63.  
  64. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  65. HANDLE hInstance, hPrevInstance;
  66. LPSTR lpszCmdLine;
  67. int cmdShow;
  68. {
  69.     MSG   msg;
  70.     HWND  hWnd;
  71.  
  72.     if (!hPrevInstance)
  73.         {
  74.         /* Call initialization procedure if this is the first instance */
  75.         if (!WinInit( hInstance ))
  76.             return FALSE;
  77.         }
  78.  
  79.     hWnd = CreateWindow((LPSTR)"Ellipse",
  80.                         (LPSTR)"Ellipse()",
  81.                         WS_OVERLAPPEDWINDOW,
  82.                         CW_USEDEFAULT,
  83.                         CW_USEDEFAULT,
  84.                         CW_USEDEFAULT,
  85.                         CW_USEDEFAULT,
  86.                         (HWND)NULL,        /* no parent */
  87.                         (HMENU)NULL,       /* use class menu */
  88.                         (HANDLE)hInstance, /* handle to window instance */
  89.                         (LPSTR)NULL        /* no params to pass on */
  90.                         );
  91.  
  92.     /* Make window visible according to the way the app is activated */
  93.     ShowWindow( hWnd, cmdShow );
  94.     UpdateWindow( hWnd );
  95.  
  96.     /* Polling messages from event queue */
  97.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  98.         {
  99.         TranslateMessage((LPMSG)&msg);
  100.         DispatchMessage((LPMSG)&msg);
  101.         }
  102.  
  103.     return (int)msg.wParam;
  104. }
  105.  
  106. /* Procedures which make up the window class. */
  107. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  108. HWND hWnd;
  109. unsigned message;
  110. WORD wParam;
  111. LONG lParam;
  112. {
  113.     PAINTSTRUCT ps;
  114.  
  115.     switch (message)
  116.     {
  117.  
  118.     case WM_PAINT:
  119.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  120.         CALL_Ellipse(hWnd, ps.hdc);
  121.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  122.         break;
  123.  
  124.     case WM_DESTROY:
  125.         PostQuitMessage( 0 );
  126.         break;
  127.  
  128.     default:
  129.         return DefWindowProc( hWnd, message, wParam, lParam );
  130.         break;
  131.     }
  132.     return(0L);
  133. }
  134. 
  135.