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

  1. /*
  2.  *  SetROP2
  3.  *  setrop2.c
  4.  *
  5.  *  This program demonstrates the use of the function SetROP2.
  6.  *  It sets the current drawing mode of the display context. GDI uses the
  7.  *  drawing mode to combine pens and interior of filled objects with color
  8.  *  already on the display surface. The mode specifies how the color of 
  9.  *  the pen or interior and the color already on the display surface are
  10.  *  combined to yield a new color. In this program, a rectangle is drawn on 
  11.  *  the client area with different drawing mode. It will show how the pen
  12.  *  (which is used to draw the border) and the brush (which is used to fill
  13.  *  the rectangle) combine with the color already on the screen. 
  14.  *
  15.  */
  16.  
  17. #include "windows.h"
  18.  
  19. /* Procedure called when the application is loaded for the first time */
  20. BOOL WinInit( hInstance )
  21. HANDLE hInstance;
  22. {
  23.     WNDCLASS   wcClass;
  24.  
  25.     /* registering the parent window class */
  26.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  27.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  28.     wcClass.lpszMenuName   = (LPSTR)NULL;
  29.     wcClass.lpszClassName  = (LPSTR)"Setrop2";
  30.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( LTGRAY_BRUSH );
  31.     wcClass.hInstance      = hInstance;
  32.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  33.     wcClass.lpfnWndProc    = DefWindowProc;
  34.     wcClass.cbClsExtra     = 0;
  35.     wcClass.cbWndExtra     = 0;
  36.  
  37.     RegisterClass( (LPWNDCLASS)&wcClass );
  38.     return TRUE;        /* Initialization succeeded */
  39. }
  40.  
  41.  
  42. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  43. HANDLE hInstance, hPrevInstance;
  44. LPSTR lpszCmdLine;
  45. int cmdShow;
  46. {
  47.     HWND  hWnd;                 /* Handle to the parent window    */
  48.     HDC   hDC;                  /* Display context of client area */
  49.     MSG   msg;                  /* Window messages                */
  50.  
  51.     WinInit (hInstance);
  52.  
  53.     hWnd = CreateWindow((LPSTR)"Setrop2",
  54.                         (LPSTR)"Setting Drawing Mode",
  55.                         WS_OVERLAPPEDWINDOW,
  56.                         50,                /* x         */
  57.                         50,                /* y         */
  58.                         600,               /* width     */
  59.                         250,               /* height    */
  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.  
  66.     /* Make window visible according to the way the app is activated */
  67.     ShowWindow( hWnd, cmdShow );
  68.     UpdateWindow( hWnd );
  69.  
  70.     /* Get a DC before writing to the client area */
  71.     hDC = GetDC (hWnd);
  72.  
  73.     /* Using the default drawing mode of R2_COPYPEN from the display 
  74.      * context, where the pixel is the color of the pen and brush, 
  75.      * regardless of what is on the screen
  76.      */
  77.     Rectangle (hDC, 50, 50, 150, 100);
  78.     MessageBox (hWnd, (LPSTR)"The ROP2 is R2_COPYPEN", (LPSTR)"R2_COPYPEN", MB_OK);
  79.  
  80.     /* The pixel is always white with R2_WHITE */
  81.     SetROP2 (hDC, R2_WHITE);
  82.     Rectangle (hDC, 60, 60, 160, 110);
  83.     MessageBox (hWnd, (LPSTR)"The ROP2 is R2_WHITE", (LPSTR)"R2_WHITE", MB_OK);
  84.  
  85.     /* The pixel is a combination of colors in the pen/brush and display,
  86.      * but not in both witj R2_XORPEN
  87.      */    
  88.     SetROP2 (hDC, R2_XORPEN);
  89.     Rectangle (hDC, 70, 70, 170, 120);
  90.     MessageBox (hWnd, (LPSTR)"The ROP2 is R2_XORPEN", (LPSTR)"R2_XORPEN", MB_OK);
  91.  
  92.     /* The pixel is the inverse of the display color with R2_NOT */
  93.     SetROP2 (hDC, R2_NOT);
  94.     Rectangle (hDC, 80, 80, 180, 130);
  95.     MessageBox (hWnd, (LPSTR)"The ROP2 is R2_NOT", (LPSTR)"R2_NOT", MB_OK);
  96.  
  97.     /* return the display context when everything is done */
  98.     ReleaseDC (hWnd, hDC);
  99.     
  100.     /* Window message loop */
  101.     while (GetMessage ((LPMSG)&msg, NULL, 0, 0))
  102.       {
  103.          TranslateMessage ((LPMSG)&msg);
  104.          DispatchMessage  ((LPMSG)&msg);
  105.       }
  106.  
  107.     return (int)msg.wParam;
  108. }
  109.