home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / cenvew / gdi.cmm < prev    next >
Encoding:
Text File  |  1993-11-11  |  2.0 KB  |  69 lines

  1. // GDI.cmm - Demonstrate GDI.lib
  2. //
  3. // Contributed in its initial form to the CEnvi library by Jari Karjala.
  4. // Thank you Jari.
  5.  
  6. #include "WinUtil.lib"
  7. #include "Window.lib"
  8. #include "gdi.lib"
  9.  
  10. // Create the graphics window and let it run
  11.    if ( MakeWindow(NULL,NULL,"GDIWindowFunction",
  12.                    "Demonstrate CEnvi's GDI.LIB",
  13.                    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  14.                    CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
  15.                    NULL) ) {
  16.  
  17.       while ( DoWindows() )
  18.          ;
  19.    }
  20.  
  21. GDIWindowFunction(hwnd,msg,wparm,lparm)
  22. {
  23.    // This is the Cmm routine called for all windows messages.  Here we're only
  24.    // interested in the PAINT message.  Everything else is handled by the
  25.    // default windows functions.
  26.    #define WM_PAINT 0x0F
  27.    if ( WM_PAINT == msg ) {
  28.       DrawStuff(hwnd);
  29.       return 0;
  30.    }
  31. }
  32.  
  33.  
  34. DrawStuff(hwnd)
  35. {
  36.    // Get size and DC handle
  37.    winbox = GetClientRect(hwnd)
  38.    hdc = BeginPaint(hwnd,PaintStruct);
  39.  
  40.    // Draw some lines
  41.    for (i = 0; i<winbox.bottom; i += 20) {
  42.        MoveTo(hdc, winbox.left, 0);
  43.        LineTo(hdc, winbox.right, i);
  44.        LineTo(hdc, 0, i);
  45.        LineTo(hdc, winbox.right, 0);
  46.    }
  47.  
  48.    // Draw some light gray rectangles
  49.    SelectObject(hdc, GetStockObject(LTGRAY_BRUSH));
  50.    for (i = winbox.bottom/2; i>0; i -= 20)
  51.        Rectangle(hdc, 0, 0, i, i);
  52.  
  53.    // Draw some gray rounded rectangles    
  54.    SelectObject(hdc, GetStockObject(WHITE_PEN));
  55.    SelectObject(hdc, GetStockObject(GRAY_BRUSH));
  56.    for (i = 0; i < winbox.bottom/2; i += 20)
  57.        RoundRect(hdc, (winbox.right-winbox.left)/2, winbox.top+i,
  58.                  winbox.right, winbox.bottom-i, 100, 100);
  59.  
  60.    // Draw some transparent ellipses
  61.    SelectObject(hdc, GetStockObject(BLACK_PEN));
  62.    SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
  63.    for (i = winbox.bottom/2; i>0; i -= 20)
  64.        Ellipse(hdc, 0, winbox.bottom-i, i, winbox.bottom);
  65.  
  66.    EndPaint(hwnd,PaintStruct);
  67. }
  68.  
  69.