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

  1. /*
  2.  *
  3.  *  Function (s) demonstrated in this program: FrameRgn
  4.  *  Compiler version: C 5.1
  5.  *
  6.  *  Description:
  7.  *     This program demonstrates the use of the function FrameRgn.
  8.  *     This function draws a border around the region specified by a
  9.  *     handle to a region, using the brush specified by a hanle to a
  10.  *     brush. The fourth parameter specifies the width of the border
  11.  *     on vertical brush strokes, and the fifth parameter specifies
  12.  *     the height on horizontal strokes.
  13.  *  
  14.  */
  15.  
  16. #include <windows.h>
  17.  
  18. long    FAR PASCAL WndProc (HANDLE, unsigned, WORD, LONG);
  19.  
  20. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  21. HANDLE    hInstance, hPrevInstance;
  22. LPSTR     lpszCmdLine;
  23. int       cmdShow;
  24.   {
  25.   HWND     hWnd;
  26.   WNDCLASS rClass;
  27.   MSG      msg;
  28.  
  29.   if (!hPrevInstance)
  30.     {
  31.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  32.     rClass.lpfnWndProc   = WndProc;
  33.     rClass.cbClsExtra    = 0;
  34.     rClass.cbWndExtra    = 0;
  35.     rClass.hInstance     = hInstance;
  36.     rClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  37.     rClass.hIcon         = LoadIcon (hInstance, IDI_APPLICATION);
  38.     rClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  39.     rClass.lpszMenuName  = NULL;
  40.     rClass.lpszClassName = "framergn";
  41.  
  42.     if (!RegisterClass (&rClass))
  43.       return FALSE;
  44.     }
  45.  
  46.   hWnd = CreateWindow ("framergn",            /* window class name       */
  47.                       "FrameRgn",                 /* window caption          */
  48.                       WS_OVERLAPPEDWINDOW,        /* window style            */
  49.                       CW_USEDEFAULT,              /* initial x position      */
  50.                       0,                          /* initial y position      */
  51.                       CW_USEDEFAULT,              /* initial x size          */
  52.                       0,                          /* initial y size          */
  53.                       NULL,                       /* parent window handle    */
  54.                       NULL,                       /* window menu handle      */
  55.                       hInstance,                  /* program instance handle */
  56.                       NULL);                      /* create parameters       */
  57.  
  58.   ShowWindow (hWnd, cmdShow);
  59.   UpdateWindow (hWnd);
  60.  
  61.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  62.     {
  63.     TranslateMessage ( (LPMSG) & msg);
  64.     DispatchMessage ( (LPMSG) & msg);
  65.     }
  66.   return (msg.wParam);
  67.   }
  68.  
  69. long    FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  70. HWND        hWnd;
  71. unsigned    message;
  72. WORD        wParam;
  73. LONG        lParam;
  74.   {
  75.   HDC    hDC;
  76.   HMENU  hMenu;
  77.   HRGN   hRgn;
  78.   HBRUSH hBrush;
  79.  
  80.   switch (message)
  81.     {
  82.     case WM_CREATE:
  83.       hMenu = CreateMenu ();
  84.       ChangeMenu (hMenu, NULL, (LPSTR)"Frame", 100, MF_APPEND);
  85.       SetMenu (hWnd, hMenu);
  86.       break;
  87.  
  88.     case WM_INITMENU:
  89.       InvalidateRect (hWnd, NULL, TRUE);
  90.       break;
  91.  
  92.     case WM_COMMAND:
  93.       if (wParam == 100)
  94.         {
  95.         hRgn = CreateRectRgn (1, 1, 200, 100);
  96.         hBrush = CreateSolidBrush ( (DWORD) 0x0000FF);
  97.         hDC = GetDC (hWnd);
  98.         FrameRgn (hDC, hRgn, hBrush, 10, 10);
  99.         DeleteObject (hRgn);
  100.         DeleteObject (hBrush);
  101.         ReleaseDC (hWnd, hDC);
  102.         }
  103.       break;
  104.  
  105.     case WM_DESTROY:
  106.       PostQuitMessage (0);
  107.       break;
  108.  
  109.     default:
  110.       return (DefWindowProc (hWnd, message, wParam, lParam));
  111.     }
  112.   return (0L);
  113.   }
  114.