home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_17 / PrinterDevice / DCAttr.cpp next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  7.1 KB  |  252 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : dcattr.cpp                                                             //
  10. //  Description: KDCAttributes class                                                 //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define NOCRYPT
  16. #define _WIN32_WINNT 0x0500
  17. #define WINVER       0x0500
  18.  
  19. #include <windows.h>
  20. #include <tchar.h>
  21. #include <stdio.h>
  22.  
  23. #include "resource.h"
  24.  
  25. #include "..\\..\\include\\property.h"
  26. #include "..\\..\\include\\listview.h"
  27.  
  28. #include "DCAttr.h"
  29.  
  30.  
  31. BOOL KDCAttributes::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  32. {
  33.     switch ( uMsg )
  34.     {
  35.         case WM_INITDIALOG:
  36.             m_hWnd = hWnd;
  37.  
  38.             { 
  39.                 HWND hOK = GetDlgItem(hWnd, IDOK);
  40.  
  41.                 RECT rect;
  42.  
  43.                 GetWindowRect(hOK, & rect);
  44.  
  45.                 HRGN hRgn = CreateEllipticRgn(0, 0, (rect.right - rect.left), (rect.bottom - rect.top));
  46.  
  47.                 SetWindowRgn(hOK, hRgn, TRUE);
  48.             }
  49.  
  50.             m_List.FromDlgItem(hWnd, IDC_DCATTRIBUTES);
  51.  
  52.             return OnInitDialog();
  53.  
  54.         case WM_COMMAND:
  55.             switch ( wParam )
  56.             {
  57.                 case IDOK:
  58.                     EndDialog(hWnd, TRUE);
  59.                     break;
  60.  
  61.                 default:
  62.                     return FALSE;
  63.             }
  64.             return TRUE;
  65.     }
  66.         
  67.     return FALSE;
  68. }
  69.  
  70.  
  71. void KDCAttributes::Add(LPCTSTR pszAttribute, LPCTSTR pszFormat, ...)
  72. {
  73.     va_list ap;
  74.     TCHAR temp[MAX_PATH];
  75.  
  76.     va_start(ap, pszFormat);
  77.     
  78.     vsprintf(temp, pszFormat, ap);
  79.     
  80.     va_end(ap);
  81.  
  82.     m_List.AddItem(0, pszAttribute);
  83.     m_List.AddItem(1, temp);
  84. }
  85.  
  86.  
  87. BOOL KDCAttributes::OnInitDialog(void)
  88. {
  89.     m_List.AddColumn(0, 160, _T("Attribute"));
  90.     m_List.AddColumn(1, 400, _T("Value"));
  91.  
  92. //    SendDlgItemMessage(m_hWnd, IDC_CREATEDC, BM_SETCHECK, BST_CHECKED, 0);
  93.     
  94.     DumpDC(m_hDC);
  95.  
  96.     return TRUE;
  97. }
  98.  
  99.  
  100. void KDCAttributes::DumpDC(HDC hDC)
  101. {
  102.     POINT pnt;
  103.     SIZE  size;
  104.  
  105.     m_List.DeleteAll();
  106.  
  107.     Add(_T("Technology"),  _T("%d"), GetDeviceCaps(hDC, TECHNOLOGY));
  108.     Add(_T("width"),       _T("%d"), GetDeviceCaps(hDC, HORZRES));
  109.     Add(_T("height"),       _T("%d"), GetDeviceCaps(hDC, VERTRES));
  110.  
  111.     GetDCOrgEx(hDC, & pnt); 
  112.     Add(_T("DC Origin"), _T("{ %d, %d }"), pnt.x, pnt.y);
  113.  
  114.     TCHAR szTitle[MAX_PATH];
  115.  
  116.     szTitle[0] = 0;
  117.  
  118.     GetWindowText(WindowFromDC(hDC), szTitle, MAX_PATH);
  119.     Add(_T("Window"),    _T("0x%X \"%s\""), WindowFromDC(hDC), szTitle);
  120.  
  121.     Add(_T("Bitmap"),        _T("0x%X"), GetCurrentObject(hDC, OBJ_BITMAP));
  122.  
  123.     Add(_T("Graphics Mode"), _T("%d"), GetGraphicsMode(hDC));
  124.     Add(_T("Mapping Mode"),  _T("%d"), GetMapMode(hDC));
  125.  
  126.     GetViewportExtEx(hDC, & size);
  127.     Add(_T("Viewport Extent"), _T("{ %d, %d }"), size.cx, size.cy);
  128.     
  129.     GetViewportOrgEx(hDC, & pnt);
  130.     Add(_T("Viewport Origin"), _T("{ %d, %d }"), pnt.x, pnt.y);
  131.  
  132.     GetWindowExtEx(hDC, & size);
  133.     Add(_T("Window Extent"), _T("{ %d, %d }"), size.cx, size.cy);
  134.     
  135.     GetWindowOrgEx(hDC, & pnt);
  136.     Add(_T("Window Origin"), _T("{ %d, %d }"), pnt.x, pnt.y);
  137.  
  138.     XFORM xform;
  139.     GetWorldTransform(hDC, & xform);
  140.  
  141.     Add(_T("World transformation"), _T("{ %f, %f, %f, %f, %f, %f }"),
  142.         xform.eM11, xform.eM12, xform.eM21, xform.eM22, xform.eDx, xform.eDy);
  143.  
  144.     // transformation
  145.  
  146.     Add(_T("Background Color"), _T("0x%X"), GetBkColor(hDC));
  147.     Add(_T("Text Color"),       _T("0x%X"), GetTextColor(hDC));
  148.     Add(_T("Palette"),          _T("0x%X"), GetCurrentObject(hDC, OBJ_PAL));
  149.  
  150.     {
  151.         COLORADJUSTMENT ca;
  152.         GetColorAdjustment(hDC, & ca);
  153.     
  154.         Add(_T("Color Adjustment"), _T("{ %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d }"), 
  155.             ca.caSize, ca.caFlags, ca.caIlluminantIndex,
  156.             ca.caRedGamma, ca.caGreenGamma, ca.caBlueGamma, 
  157.             ca.caReferenceBlack, ca.caReferenceWhite,
  158.             ca.caContrast, ca.caBrightness, ca.caColorfulness, ca.caRedGreenTint);
  159.     }
  160.  
  161.     Add(_T("Color Space"), _T("0x%X"), GetColorSpace(hDC));
  162.     Add(_T("ICM Mode"),    _T("%d"),   SetICMMode(hDC, ICM_QUERY));
  163.  
  164.     {
  165.         TCHAR szProfile[MAX_PATH];
  166.         DWORD dwSize = MAX_PATH;
  167.  
  168.         szProfile[0] = 0;
  169.         GetICMProfile(hDC, & dwSize, szProfile);
  170.  
  171.         Add(_T("ICM Profile"), _T("%s"), szProfile);
  172.     }
  173.  
  174.     GetCurrentPositionEx(hDC, & pnt);
  175.     Add(_T("Current Position"), _T("{ %d, %d }"), pnt.x, pnt.y);
  176.  
  177.     Add(_T("ROP2"),                _T("%d"),    GetROP2(hDC));
  178.     Add(_T("Background Mode"),    _T("%d"),    GetBkMode(hDC));
  179.     Add(_T("Logical Pen"),        _T("0x%X"), GetCurrentObject(hDC, OBJ_PEN));
  180.     Add(_T("DC Pen Color"),     _T("0x%X"), GetDCPenColor(hDC));
  181.     Add(_T("Arc Direction"),    _T("%d"),    GetArcDirection(hDC));
  182.  
  183.     FLOAT miter;
  184.     GetMiterLimit(hDC, & miter);
  185.  
  186.     Add(_T("Miter Limit"),        _T("%f"),    miter);
  187.     
  188.     Add(_T("Logical Brush"),    _T("0x%X"), GetCurrentObject(hDC, OBJ_BRUSH));
  189.     Add(_T("DC Brush Color"),   _T("0x%X"), GetDCBrushColor(hDC));
  190.  
  191.     GetBrushOrgEx(hDC, & pnt);
  192.     Add(_T("Brush Origin"),     _T("{ %d, %d }"), pnt.x, pnt.y);
  193.  
  194.     Add(_T("Polygon Filling Mode"),   _T("%d"), GetPolyFillMode(hDC));
  195.     Add(_T("Bitmap Stretching Mode"), _T("%d"), GetStretchBltMode(hDC));
  196.     Add(_T("Logical Font"),              _T("0x%X"), GetCurrentObject(hDC, OBJ_FONT));
  197.     Add(_T("Inter-character spacing"), _T("%d"), GetTextCharacterExtra(hDC));
  198.  
  199.     DWORD flag = SetMapperFlags(hDC, 0);
  200.     SetMapperFlags(hDC, flag);
  201.  
  202.     Add(_T("Font Mapper Flags"),       _T("0x%X"), flag);
  203.  
  204.     Add(_T("Text Alignment"),           _T("0x%X"), GetTextAlign(hDC));
  205.  
  206.     Add(_T("Text Justification"),      _T("write only"), 0);
  207.  
  208.     Add(_T("Layout"),                  _T("%d"), GetLayout(hDC));
  209.  
  210.     Add(_T("Path"),                       _T("%d bytes"), GetPath(hDC, NULL, NULL, 0));
  211.  
  212.     RECT rect;
  213.  
  214.     int typ = GetClipBox(hDC, & rect);
  215.  
  216.     HRGN hRgn = CreateRectRgn(0, 0, 1, 1);
  217.     
  218.     GetClipRgn(hDC, hRgn);
  219.  
  220.     Add(_T("Clipping"),                   _T("type %d clip box { %d, %d, %d, %d } size %d bytes"), 
  221.         typ, rect.left, rect.top, rect.right, rect.bottom,
  222.         GetRegionData(hRgn, 0, NULL)
  223.         );
  224.     
  225.     GetMetaRgn(hDC, hRgn);
  226.  
  227.     GetRgnBox(hRgn, & rect);
  228.     Add(_T("Meta Region"), _T("size %d bytes, rgn box { %d, %d, %d, %d }"), 
  229.         GetRegionData(hRgn, 0, NULL), rect.left, rect.top, rect.right, rect.bottom);
  230.  
  231.     for (int i=1; i<=5; i++)
  232.     {
  233.         int rslt = GetRandomRgn(hDC, hRgn, i);
  234.  
  235.         if ( rslt==1 )
  236.         {
  237.             GetRgnBox(hRgn, & rect);
  238.             Add(_T("Random Region"), _T("size %d bytes, rgn box { %d, %d, %d, %d }"), 
  239.             GetRegionData(hRgn, 0, NULL), rect.left, rect.top, rect.right, rect.bottom);
  240.         }
  241.         else if ( rslt==0 )
  242.             Add(_T("Random Region"), _T("NULL"), 0);
  243.         else
  244.             Add(_T("Random Region"), _T("FAIL"), 0);
  245.     }
  246.     DeleteObject(hRgn);
  247.  
  248.     GetBoundsRect(hDC, & rect, 0);
  249.  
  250.     Add(_T("Bounds Rectangle"),        _T("{ %d, %d, %d, %d }"), 
  251.         rect.left, rect.top, rect.right, rect.bottom);
  252. }