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

  1. /*
  2.  *  Function Name:   CreateSolidBrush
  3.  *
  4.  *  Description:
  5.  *   This function creates a logical brush that can replace the current brush
  6.  *   for the device.  The program below draws a rectangle and fills it in
  7.  *   with a red brush that was selected.
  8.  */
  9.  
  10. #include "windows.h"
  11.  
  12. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  13.  
  14. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  15. HANDLE    hInstance, hPrevInstance;
  16. LPSTR     lpszCmdLine;
  17. int       cmdShow;
  18.   {
  19.   MSG     msg;
  20.   HWND    hWnd;
  21.   HBRUSH  hBrush;
  22.  
  23.   hBrush = CreateSolidBrush (RGB (255, 0, 0));   /* hBrush created (red). */
  24.  
  25.   if (hBrush == NULL)                /* checks for successful brush creation */
  26.     {
  27.     MessageBox (hWnd, (LPSTR)"CreateSolidBrush failed", (LPSTR)"ERROR", MB_ICONHAND);
  28.     return (0L);
  29.     }
  30.  
  31.   if (!hPrevInstance)
  32.     {
  33.     WNDCLASS   wcClass;
  34.  
  35.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  36.     wcClass.lpfnWndProc    = WndProc;
  37.     wcClass.cbClsExtra     = 0;
  38.     wcClass.cbWndExtra     = 0;
  39.     wcClass.hInstance      = hInstance;
  40.     wcClass.hIcon          = LoadIcon (hInstance, NULL);
  41.     wcClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  42.     wcClass.hbrBackground  = hBrush;
  43.     wcClass.lpszMenuName   = (LPSTR)NULL;
  44.     wcClass.lpszClassName  = (LPSTR)"CreateSolidBrush";
  45.  
  46.     if (!RegisterClass ( (LPWNDCLASS) & wcClass))
  47.       return FALSE;
  48.     }
  49.  
  50.   hWnd = CreateWindow ( (LPSTR)"CreateSolidBrush",
  51.                       (LPSTR)"CreateSolidBrush ()",
  52.                       WS_OVERLAPPEDWINDOW,
  53.                       CW_USEDEFAULT,
  54.                       CW_USEDEFAULT,
  55.                       CW_USEDEFAULT,
  56.                       CW_USEDEFAULT,
  57.                       (HWND)NULL,        /* no parent */
  58.                       (HMENU)NULL,       /* use class menu */
  59.                       (HANDLE)hInstance, /* handle to window instance */
  60.                       (LPSTR)NULL);      /* no params to pass on */
  61.  
  62.   ShowWindow (hWnd, cmdShow);
  63.   UpdateWindow (hWnd);
  64.  
  65.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  66.     {
  67.     TranslateMessage ( (LPMSG) & msg);
  68.     DispatchMessage ( (LPMSG) & msg);
  69.     }
  70.   DeleteObject (hBrush);
  71.   return (int)msg.wParam;
  72.   }
  73.  
  74.  
  75. /* Procedures which make up the window class. */
  76. long    FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  77. HWND     hWnd;
  78. unsigned message;
  79. WORD     wParam;
  80. LONG     lParam;
  81.   {
  82.   switch (message)
  83.     {
  84.     case WM_DESTROY:
  85.       PostQuitMessage (0);
  86.       break;
  87.  
  88.     default:
  89.       return DefWindowProc (hWnd, message, wParam, lParam);
  90.       break;
  91.     }
  92.   return (0L);
  93.   }
  94.