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

  1. /*
  2.  
  3. Windows Version 2.03 function demonstration application
  4.  
  5. Function(s) demonstrated in this program: GetROP2
  6.  
  7. Compiler version: 5.01
  8.  
  9.  
  10. Description:
  11.  
  12. The GetROP2 function returns the current drawing mode.  The drawing mode
  13. specifies how the pen or interior color and the color already on the
  14. display surface are combined to yield a new color.  This program
  15. simply calls GetROP2 and displays the current drawing mode based on
  16. the function return value.
  17.  
  18.  
  19. Additional Comments:
  20.  
  21. Note that the drawing modes define how GDI combines source and destination
  22. colors when drawing with the current pen.
  23.  
  24. ****************************************************************************/
  25.  
  26. #include <windows.h>
  27.  
  28. long FAR PASCAL WndProc (HWND, unsigned, WORD, LONG) ;
  29.  
  30. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  31.      HANDLE      hInstance, hPrevInstance ;
  32.      LPSTR       lpszCmdLine ;
  33.      int         nCmdShow ;
  34.      {
  35.      static char szAppName [] = "GetROP2" ;
  36.      HWND        hWnd ;
  37.      WNDCLASS    wndclass ;
  38.      MSG msg;
  39.      HDC             hDC;                 /* For the GetROP2 demonstration */
  40.      short           iROP2;               /* For the GetROP2 demonstration */
  41.  
  42.      if (!hPrevInstance) 
  43.           {
  44.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  45.           wndclass.lpfnWndProc   = WndProc ;
  46.           wndclass.cbClsExtra    = 0 ;
  47.           wndclass.cbWndExtra    = 0 ;
  48.           wndclass.hInstance     = hInstance ;
  49.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  50.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  51.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  52.           wndclass.lpszMenuName  = NULL ;
  53.           wndclass.lpszClassName = szAppName ;
  54.  
  55.           if (!RegisterClass (&wndclass))
  56.                return FALSE ;
  57.           }
  58.  
  59.      hWnd = CreateWindow (szAppName,            /* window class name       */
  60.                     "GetROP2",                  /* window caption          */
  61.                     WS_OVERLAPPEDWINDOW,        /* window style            */
  62.                     CW_USEDEFAULT,              /* initial x position      */
  63.                     0,                          /* initial y position      */
  64.                     CW_USEDEFAULT,              /* initial x size          */
  65.                     0,                          /* initial y size          */
  66.                     NULL,                       /* parent window handle    */
  67.                     NULL,                       /* window menu handle      */
  68.                     hInstance,                  /* program instance handle */
  69.                     NULL) ;                     /* create parameters       */
  70.  
  71.      ShowWindow (hWnd, nCmdShow) ;
  72.  
  73.      UpdateWindow (hWnd) ;
  74.  
  75. /***************************************************************************/
  76. /* Begin the GetROP2 demonstration */
  77.  
  78.      hDC = GetDC (hWnd);
  79.      iROP2 = GetROP2 (hDC);                /* Get the current drawing mode */
  80.  
  81.      switch (iROP2)
  82.         {
  83.         case R2_BLACK:
  84.            {
  85.            MessageBox (hWnd,
  86.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  87. is R2_BLACK.",
  88.                        (LPSTR)"GetROP2",
  89.                        MB_OK
  90.                       );
  91.            break;
  92.            }
  93.         case R2_NOTMERGEPEN:
  94.            {
  95.            MessageBox (hWnd,
  96.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  97. is R2_NOTMERGEPEN.",  
  98.                        (LPSTR)"GetROP2",
  99.                        MB_OK
  100.                       );
  101.            break;
  102.            }
  103.         case R2_MASKNOTPEN:
  104.            {
  105.            MessageBox (hWnd,
  106.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  107. is R2_MASKNOTPEN.", 
  108.                        (LPSTR)"GetROP2",
  109.                        MB_OK
  110.                       );
  111.            break;
  112.            }
  113.         case R2_NOTCOPYPEN:
  114.            {
  115.            MessageBox (hWnd,
  116.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  117. is R2_NOTCOPYPEN.", 
  118.                        (LPSTR)"GetROP2",
  119.                        MB_OK
  120.                       );
  121.            break;
  122.            }
  123.         case R2_MASKPENNOT:
  124.            {
  125.            MessageBox (hWnd,
  126.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  127. is R2_MASKPENNOT.",   
  128.                        (LPSTR)"GetROP2",
  129.                        MB_OK
  130.                       );
  131.            break;
  132.            }
  133.         case R2_NOT:
  134.            {
  135.            MessageBox (hWnd,
  136.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  137. is R2_NOT .",   
  138.                        (LPSTR)"GetROP2",
  139.                        MB_OK
  140.                       );
  141.            break;
  142.            }
  143.         case R2_XORPEN:
  144.            {
  145.            MessageBox (hWnd,
  146.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  147. is R2_XORPEN.",    
  148.                        (LPSTR)"GetROP2",
  149.                        MB_OK
  150.                       );
  151.            break;
  152.            }
  153.         case R2_NOTMASKPEN:
  154.            {
  155.            MessageBox (hWnd,
  156.                        (LPSTR)" The current drawing mode returned by GetROP2 \
  157. is R2_NOTMASKPEN.",    
  158.                        (LPSTR)"GetROP2",
  159.                        MB_OK
  160.                       );
  161.            break;
  162.            }
  163.         case R2_MASKPEN:
  164.            {
  165.            MessageBox (hWnd,
  166.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  167. is R2_MASKPEN.",      
  168.                        (LPSTR)"GetROP2",
  169.                        MB_OK
  170.                       );
  171.            break;
  172.            }
  173.         case R2_NOTXORPEN:
  174.            {
  175.            MessageBox (hWnd,
  176.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  177. is R2_NOTXORPEN.",        
  178.                        (LPSTR)"GetROP2",
  179.                        MB_OK
  180.                       );
  181.            break;
  182.            }
  183.         case R2_NOP:
  184.            {
  185.            MessageBox (hWnd,
  186.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  187. is R2_NOP.",          
  188.                        (LPSTR)"GetROP2",
  189.                        MB_OK
  190.                       );
  191.            break;
  192.            }
  193.         case R2_MERGENOTPEN:
  194.            {
  195.            MessageBox (hWnd,
  196.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  197. is R2_MERGENOTPEN.",          
  198.                        (LPSTR)"GetROP2",
  199.                        MB_OK
  200.                       );
  201.            break;
  202.            }
  203.         case R2_COPYPEN:
  204.            {
  205.            MessageBox (hWnd,
  206.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  207. is R2_COPYPEN.",           
  208.                        (LPSTR)"GetROP2",
  209.                        MB_OK
  210.                       );
  211.            break;
  212.            }
  213.         case R2_MERGEPENNOT:
  214.            {
  215.            MessageBox (hWnd,
  216.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  217. is R2_MERGEPENNOT.",
  218.                        (LPSTR)"GetROP2",
  219.                        MB_OK
  220.                       );
  221.            break;
  222.            }
  223.         case R2_MERGEPEN:
  224.            {
  225.            MessageBox (hWnd,
  226.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  227. is R2_MERGEPEN.",  
  228.                        (LPSTR)"GetROP2",
  229.                        MB_OK
  230.                       );
  231.            break;
  232.            }
  233.         case R2_WHITE:
  234.            {
  235.            MessageBox (hWnd,
  236.                        (LPSTR)"The current drawing mode returned by GetROP2 \
  237. is R2_WHITE.",
  238.                        (LPSTR)"GetROP2",
  239.                        MB_OK
  240.                       );
  241.            break;
  242.            }
  243.         default:
  244.            MessageBox (hWnd,
  245.                        (LPSTR)"Something is wrong.  GetROP2 is supposed to \
  246. return the current drawing mode but instead returns an unknown value.",
  247.                        (LPSTR)"GetROP2",
  248.                        NULL
  249.                       );
  250.            break;
  251.         } /* end switch */
  252.  
  253.      ReleaseDC (hWnd, hDC);
  254.  
  255. /* End the GetROP2 demonstration */
  256. /***************************************************************************/
  257.  
  258.      while (GetMessage(&msg, NULL, 0, 0))
  259.      {
  260.       TranslateMessage(&msg);
  261.       DispatchMessage(&msg);
  262.      } 
  263.      return (msg.wParam) ;     
  264.      }
  265.  
  266. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  267. HWND     hWnd ;
  268. unsigned iMessage ;
  269. WORD     wParam ;
  270. LONG     lParam ;
  271. {
  272.  
  273.  switch(iMessage)
  274.  {
  275.   case WM_DESTROY:
  276.   {
  277.    PostQuitMessage(0);
  278.    break;
  279.   }
  280.   default:
  281.   {
  282.    return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  283.   }
  284.  }
  285.  
  286.  return (0L); 
  287. }
  288.