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

  1. /*
  2.  *  Function Name:   CreatePen
  3.  *
  4.  *  Description:
  5.  *   It creates a logical pen that can replace the current pen for the device.
  6.  *   The module below draws an arc.
  7.  *   CreatePen selects the style (0=solid), a width of 20, and the color
  8.  *   red. A width of 0 is one pixel width on raster devices.  The mode used
  9.  *   is MM_TEXT (default).
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  15.  
  16. /***********************************************************************/
  17. void CALL_CreatePen (hWnd, hDC)
  18. HWND hWnd;
  19. HDC hDC;
  20.   {
  21.   HPEN hPen, hOldPen;
  22.  
  23.   hPen = CreatePen (0, 20, RGB (255, 0, 0));   /* hPen created.   */
  24.  
  25.   if (hPen == NULL)                /* checks for successful pen creation */
  26.     {
  27.     MessageBeep(0);
  28.     return;
  29.     }
  30.  
  31.   hOldPen = (HPEN) SelectObject (hDC, (HANDLE) hPen);
  32.   Arc (hDC, 0, 0, 300, 200, 200, 180, 100, 30);
  33.   DeleteObject (hPen);
  34.  
  35.   return;
  36.   }
  37.  
  38. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  39. HANDLE hInstance, hPrevInstance;
  40. LPSTR lpszCmdLine;
  41. int    cmdShow;
  42.   {
  43.   MSG   msg;
  44.   HWND  hWnd;
  45.  
  46.   if (!hPrevInstance)
  47.     {
  48.     WNDCLASS   wcClass;
  49.  
  50.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  51.     wcClass.lpfnWndProc    = WndProc;
  52.     wcClass.cbClsExtra     = 0;
  53.     wcClass.cbWndExtra     = 0;
  54.     wcClass.hInstance      = hInstance;
  55.     wcClass.hIcon          = LoadIcon (hInstance, NULL);
  56.     wcClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  57.     wcClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  58.     wcClass.lpszMenuName   = (LPSTR)NULL;
  59.     wcClass.lpszClassName  = (LPSTR)"CreatePen";
  60.  
  61.     if (!RegisterClass ( (LPWNDCLASS) & wcClass))
  62.       return FALSE;
  63.     }
  64.  
  65.   hWnd = CreateWindow ( (LPSTR)"CreatePen",
  66.                       (LPSTR)"CreatePen ()",
  67.                       WS_OVERLAPPEDWINDOW,
  68.                       CW_USEDEFAULT,
  69.                       CW_USEDEFAULT,
  70.                       CW_USEDEFAULT,
  71.                       CW_USEDEFAULT,
  72.                       (HWND)NULL,        /* no parent */
  73.                       (HMENU)NULL,       /* use class menu */
  74.                       (HANDLE)hInstance, /* handle to window instance */
  75.                       (LPSTR)NULL);      /* no params to pass on */
  76.  
  77.   ShowWindow (hWnd, cmdShow);
  78.   UpdateWindow (hWnd);
  79.  
  80.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  81.     {
  82.     TranslateMessage ( (LPMSG) & msg);
  83.     DispatchMessage ( (LPMSG) & msg);
  84.     }
  85.   return (int)msg.wParam;
  86.   }
  87.  
  88. /* Procedures which make up the window class. */
  89. long    FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  90. HWND hWnd;
  91. unsigned    message;
  92. WORD wParam;
  93. LONG lParam;
  94.   {
  95.   PAINTSTRUCT ps;
  96.  
  97.   switch (message)
  98.     {
  99.  
  100.   case WM_PAINT:
  101.     BeginPaint (hWnd, (LPPAINTSTRUCT) & ps);
  102.     CALL_CreatePen (hWnd, ps.hdc);
  103.     ValidateRect (hWnd, (LPRECT) NULL);
  104.     EndPaint (hWnd, (LPPAINTSTRUCT) & ps);
  105.     break;
  106.  
  107.   case WM_DESTROY:
  108.     PostQuitMessage (0);
  109.     break;
  110.  
  111.   default:
  112.     return DefWindowProc (hWnd, message, wParam, lParam);
  113.     break;
  114.     }
  115.   return (0L);
  116.   }
  117.