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

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