1 // Windows Template Library - WTL version 8.0
2 // Copyright (C) Microsoft Corporation. All rights reserved.
4 // This file is a part of the Windows Template Library.
5 // The use and distribution terms for this software are covered by the
6 // Microsoft Permissive License (Ms-PL) which can be found in the file
7 // Ms-PL.txt at the root of this distribution.
15 #error ATL requires C++ compilation (use a .cpp suffix)
19 #error atlgdi.h requires atlapp.h to be included first
23 // protect template members from windowsx.h macros
32 #endif // _INC_WINDOWSX
35 #if !defined(_ATL_NO_MSIMG) && !defined(_WIN32_WCE)
36 #pragma comment(lib, "msimg32.lib")
37 #endif // !defined(_ATL_NO_MSIMG) && !defined(_WIN32_WCE)
38 #if !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
39 #pragma comment(lib, "opengl32.lib")
40 #endif // !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
43 ///////////////////////////////////////////////////////////////////////////////
44 // Classes in this file:
47 // CBrushT<t_bManaged>
50 // CBitmapT<t_bManaged>
51 // CPaletteT<t_bManaged>
59 // CEnhMetaFileT<t_bManaged>
63 // AtlGetBitmapResourceInfo()
64 // AtlGetBitmapResourceBitsPerPixel()
65 // AtlIsAlphaBitmapResource()
67 // AtlGetDibColorTableSize()
68 // AtlGetDibNumColors(),
71 // AtlCreatePackedDib16()
72 // AtlSetClipboardDib16()
73 // AtlGetClipboardDib()
79 ///////////////////////////////////////////////////////////////////////////////
80 // Bitmap resource helpers to extract bitmap information for a bitmap resource
82 inline LPBITMAPINFOHEADER
AtlGetBitmapResourceInfo(HMODULE hModule
, ATL::_U_STRINGorID image
)
84 HRSRC hResource
= ::FindResource(hModule
, image
.m_lpstr
, RT_BITMAP
);
85 ATLASSERT(hResource
!= NULL
);
86 HGLOBAL hGlobal
= ::LoadResource(hModule
, hResource
);
87 ATLASSERT(hGlobal
!= NULL
);
88 LPBITMAPINFOHEADER pBitmapInfoHeader
= (LPBITMAPINFOHEADER
)::LockResource(hGlobal
);
89 ATLASSERT(pBitmapInfoHeader
!= NULL
);
90 return pBitmapInfoHeader
;
93 inline WORD
AtlGetBitmapResourceBitsPerPixel(HMODULE hModule
, ATL::_U_STRINGorID image
)
95 LPBITMAPINFOHEADER pBitmapInfoHeader
= AtlGetBitmapResourceInfo(hModule
, image
);
96 ATLASSERT(pBitmapInfoHeader
!= NULL
);
97 return pBitmapInfoHeader
->biBitCount
;
100 inline WORD
AtlGetBitmapResourceBitsPerPixel(ATL::_U_STRINGorID image
)
102 return AtlGetBitmapResourceBitsPerPixel(ModuleHelper::GetResourceInstance(), image
);
105 ///////////////////////////////////////////////////////////////////////////////
106 // 32-bit (alpha channel) bitmap resource helper
108 // Note: 32-bit (alpha channel) images work only on Windows XP with Common Controls version 6.
109 // If you want your app to work on older version of Windows, load non-alpha images if Common
110 // Controls version is less than 6.
112 inline bool AtlIsAlphaBitmapResource(ATL::_U_STRINGorID image
)
114 return (AtlGetBitmapResourceBitsPerPixel(image
) == 32);
118 ///////////////////////////////////////////////////////////////////////////////
121 template <bool t_bManaged
>
128 // Constructor/destructor/operators
129 CPenT(HPEN hPen
= NULL
) : m_hPen(hPen
)
134 if(t_bManaged
&& m_hPen
!= NULL
)
138 CPenT
<t_bManaged
>& operator =(HPEN hPen
)
144 void Attach(HPEN hPen
)
146 if(t_bManaged
&& m_hPen
!= NULL
&& m_hPen
!= hPen
)
147 ::DeleteObject(m_hPen
);
158 operator HPEN() const { return m_hPen
; }
160 bool IsNull() const { return (m_hPen
== NULL
); }
163 HPEN
CreatePen(int nPenStyle
, int nWidth
, COLORREF crColor
)
165 ATLASSERT(m_hPen
== NULL
);
166 m_hPen
= ::CreatePen(nPenStyle
, nWidth
, crColor
);
171 HPEN
CreatePen(int nPenStyle
, int nWidth
, const LOGBRUSH
* pLogBrush
, int nStyleCount
= 0, const DWORD
* lpStyle
= NULL
)
173 ATLASSERT(m_hPen
== NULL
);
174 m_hPen
= ::ExtCreatePen(nPenStyle
, nWidth
, pLogBrush
, nStyleCount
, lpStyle
);
177 #endif // !_WIN32_WCE
179 HPEN
CreatePenIndirect(LPLOGPEN lpLogPen
)
181 ATLASSERT(m_hPen
== NULL
);
182 m_hPen
= ::CreatePenIndirect(lpLogPen
);
188 ATLASSERT(m_hPen
!= NULL
);
189 BOOL bRet
= ::DeleteObject(m_hPen
);
196 int GetLogPen(LOGPEN
* pLogPen
) const
198 ATLASSERT(m_hPen
!= NULL
);
199 return ::GetObject(m_hPen
, sizeof(LOGPEN
), pLogPen
);
202 bool GetLogPen(LOGPEN
& LogPen
) const
204 ATLASSERT(m_hPen
!= NULL
);
205 return (::GetObject(m_hPen
, sizeof(LOGPEN
), &LogPen
) == sizeof(LOGPEN
));
209 int GetExtLogPen(EXTLOGPEN
* pLogPen
) const
211 ATLASSERT(m_hPen
!= NULL
);
212 return ::GetObject(m_hPen
, sizeof(EXTLOGPEN
), pLogPen
);
215 bool GetExtLogPen(EXTLOGPEN
& ExtLogPen
) const
217 ATLASSERT(m_hPen
!= NULL
);
218 return (::GetObject(m_hPen
, sizeof(EXTLOGPEN
), &ExtLogPen
) == sizeof(EXTLOGPEN
));
220 #endif // !_WIN32_WCE
223 typedef CPenT
<false> CPenHandle
;
224 typedef CPenT
<true> CPen
;
227 ///////////////////////////////////////////////////////////////////////////////
230 template <bool t_bManaged
>
237 // Constructor/destructor/operators
238 CBrushT(HBRUSH hBrush
= NULL
) : m_hBrush(hBrush
)
243 if(t_bManaged
&& m_hBrush
!= NULL
)
247 CBrushT
<t_bManaged
>& operator =(HBRUSH hBrush
)
253 void Attach(HBRUSH hBrush
)
255 if(t_bManaged
&& m_hBrush
!= NULL
&& m_hBrush
!= hBrush
)
256 ::DeleteObject(m_hBrush
);
262 HBRUSH hBrush
= m_hBrush
;
267 operator HBRUSH() const { return m_hBrush
; }
269 bool IsNull() const { return (m_hBrush
== NULL
); }
272 HBRUSH
CreateSolidBrush(COLORREF crColor
)
274 ATLASSERT(m_hBrush
== NULL
);
275 m_hBrush
= ::CreateSolidBrush(crColor
);
280 HBRUSH
CreateHatchBrush(int nIndex
, COLORREF crColor
)
282 ATLASSERT(m_hBrush
== NULL
);
283 m_hBrush
= ::CreateHatchBrush(nIndex
, crColor
);
286 #endif // !_WIN32_WCE
288 #if !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
289 HBRUSH
CreateBrushIndirect(const LOGBRUSH
* lpLogBrush
)
291 ATLASSERT(m_hBrush
== NULL
);
293 m_hBrush
= ::CreateBrushIndirect(lpLogBrush
);
295 m_hBrush
= ATL::CreateBrushIndirect(lpLogBrush
);
299 #endif // !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
301 HBRUSH
CreatePatternBrush(HBITMAP hBitmap
)
303 ATLASSERT(m_hBrush
== NULL
);
304 m_hBrush
= ::CreatePatternBrush(hBitmap
);
308 HBRUSH
CreateDIBPatternBrush(HGLOBAL hPackedDIB
, UINT nUsage
)
310 ATLASSERT(hPackedDIB
!= NULL
);
311 const void* lpPackedDIB
= GlobalLock(hPackedDIB
);
312 ATLASSERT(lpPackedDIB
!= NULL
);
313 m_hBrush
= ::CreateDIBPatternBrushPt(lpPackedDIB
, nUsage
);
314 GlobalUnlock(hPackedDIB
);
318 HBRUSH
CreateDIBPatternBrush(const void* lpPackedDIB
, UINT nUsage
)
320 ATLASSERT(m_hBrush
== NULL
);
321 m_hBrush
= ::CreateDIBPatternBrushPt(lpPackedDIB
, nUsage
);
325 HBRUSH
CreateSysColorBrush(int nIndex
)
327 ATLASSERT(m_hBrush
== NULL
);
328 m_hBrush
= ::GetSysColorBrush(nIndex
);
334 ATLASSERT(m_hBrush
!= NULL
);
335 BOOL bRet
= ::DeleteObject(m_hBrush
);
342 int GetLogBrush(LOGBRUSH
* pLogBrush
) const
344 ATLASSERT(m_hBrush
!= NULL
);
345 return ::GetObject(m_hBrush
, sizeof(LOGBRUSH
), pLogBrush
);
348 bool GetLogBrush(LOGBRUSH
& LogBrush
) const
350 ATLASSERT(m_hBrush
!= NULL
);
351 return (::GetObject(m_hBrush
, sizeof(LOGBRUSH
), &LogBrush
) == sizeof(LOGBRUSH
));
355 typedef CBrushT
<false> CBrushHandle
;
356 typedef CBrushT
<true> CBrush
;
359 ///////////////////////////////////////////////////////////////////////////////
362 class CLogFont
: public LOGFONT
367 memset(this, 0, sizeof(LOGFONT
));
370 CLogFont(const LOGFONT
& lf
)
375 CLogFont(HFONT hFont
)
377 ATLASSERT(::GetObjectType(hFont
) == OBJ_FONT
);
378 ::GetObject(hFont
, sizeof(LOGFONT
), (LOGFONT
*)this);
381 HFONT
CreateFontIndirect()
383 return ::CreateFontIndirect(this);
393 return (lfWeight
>= FW_BOLD
);
396 void MakeBolder(int iScale
= 1)
398 lfWeight
+= FW_BOLD
* iScale
;
401 void MakeLarger(int iScale
)
409 void SetHeight(LONG nPointSize
, HDC hDC
= NULL
)
411 // For MM_TEXT mapping mode
412 lfHeight
= -::MulDiv(nPointSize
, ::GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
415 LONG
GetHeight(HDC hDC
= NULL
) const
417 // For MM_TEXT mapping mode
418 return ::MulDiv(-lfHeight
, 72, ::GetDeviceCaps(hDC
, LOGPIXELSY
));
421 LONG
GetDeciPointHeight(HDC hDC
= NULL
) const
424 POINT ptOrg
= { 0, 0 };
425 ::DPtoLP(hDC
, &ptOrg
, 1);
427 pt
.y
= abs(lfHeight
) + ptOrg
.y
;
429 return ::MulDiv(pt
.y
, 720, ::GetDeviceCaps(hDC
, LOGPIXELSY
)); // 72 points/inch, 10 decipoints/point
431 // DP and LP are always the same on CE
432 return ::MulDiv(abs(lfHeight
), 720, ::GetDeviceCaps(hDC
, LOGPIXELSY
)); // 72 points/inch, 10 decipoints/point
436 void SetHeightFromDeciPoint(LONG nDeciPtHeight
, HDC hDC
= NULL
)
440 pt
.y
= ::MulDiv(::GetDeviceCaps(hDC
, LOGPIXELSY
), nDeciPtHeight
, 720); // 72 points/inch, 10 decipoints/point
441 ::DPtoLP(hDC
, &pt
, 1);
442 POINT ptOrg
= { 0, 0 };
443 ::DPtoLP(hDC
, &ptOrg
, 1);
444 lfHeight
= -abs(pt
.y
- ptOrg
.y
);
446 // DP and LP are always the same on CE
447 lfHeight
= -abs(::MulDiv(::GetDeviceCaps(hDC
, LOGPIXELSY
), nDeciPtHeight
, 720)); // 72 points/inch, 10 decipoints/point
452 void SetCaptionFont()
454 NONCLIENTMETRICS ncm
= { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
455 ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0));
456 Copy(&ncm
.lfCaptionFont
);
461 NONCLIENTMETRICS ncm
= { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
462 ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0));
463 Copy(&ncm
.lfMenuFont
);
468 NONCLIENTMETRICS ncm
= { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
469 ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0));
470 Copy(&ncm
.lfStatusFont
);
473 void SetMessageBoxFont()
475 NONCLIENTMETRICS ncm
= { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
476 ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0));
477 Copy(&ncm
.lfMessageFont
);
479 #endif // !_WIN32_WCE
481 void Copy(const LOGFONT
* pLogFont
)
483 ATLASSERT(pLogFont
!= NULL
);
484 *(LOGFONT
*)this = *pLogFont
;
487 CLogFont
& operator =(const CLogFont
& src
)
493 CLogFont
& operator =(const LOGFONT
& src
)
499 CLogFont
& operator =(HFONT hFont
)
501 ATLASSERT(::GetObjectType(hFont
) == OBJ_FONT
);
502 ::GetObject(hFont
, sizeof(LOGFONT
), (LOGFONT
*)this);
506 bool operator ==(const LOGFONT
& logfont
) const
508 return(logfont
.lfHeight
== lfHeight
&&
509 logfont
.lfWidth
== lfWidth
&&
510 logfont
.lfEscapement
== lfEscapement
&&
511 logfont
.lfOrientation
== lfOrientation
&&
512 logfont
.lfWeight
== lfWeight
&&
513 logfont
.lfItalic
== lfItalic
&&
514 logfont
.lfUnderline
== lfUnderline
&&
515 logfont
.lfStrikeOut
== lfStrikeOut
&&
516 logfont
.lfCharSet
== lfCharSet
&&
517 logfont
.lfOutPrecision
== lfOutPrecision
&&
518 logfont
.lfClipPrecision
== lfClipPrecision
&&
519 logfont
.lfQuality
== lfQuality
&&
520 logfont
.lfPitchAndFamily
== lfPitchAndFamily
&&
521 lstrcmp(logfont
.lfFaceName
, lfFaceName
) == 0);
526 template <bool t_bManaged
>
533 // Constructor/destructor/operators
534 CFontT(HFONT hFont
= NULL
) : m_hFont(hFont
)
539 if(t_bManaged
&& m_hFont
!= NULL
)
543 CFontT
<t_bManaged
>& operator =(HFONT hFont
)
549 void Attach(HFONT hFont
)
551 if(t_bManaged
&& m_hFont
!= NULL
&& m_hFont
!= hFont
)
552 ::DeleteObject(m_hFont
);
558 HFONT hFont
= m_hFont
;
563 operator HFONT() const { return m_hFont
; }
565 bool IsNull() const { return (m_hFont
== NULL
); }
568 HFONT
CreateFontIndirect(const LOGFONT
* lpLogFont
)
570 ATLASSERT(m_hFont
== NULL
);
571 m_hFont
= ::CreateFontIndirect(lpLogFont
);
575 #if !defined(_WIN32_WCE) && (_WIN32_WINNT >= 0x0500)
576 HFONT
CreateFontIndirectEx(CONST ENUMLOGFONTEXDV
* penumlfex
)
578 ATLASSERT(m_hFont
== NULL
);
579 m_hFont
= ::CreateFontIndirectEx(penumlfex
);
582 #endif // !defined(_WIN32_WCE) && (_WIN32_WINNT >= 0x0500)
584 #if !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
585 HFONT
CreateFont(int nHeight
, int nWidth
, int nEscapement
,
586 int nOrientation
, int nWeight
, BYTE bItalic
, BYTE bUnderline
,
587 BYTE cStrikeOut
, BYTE nCharSet
, BYTE nOutPrecision
,
588 BYTE nClipPrecision
, BYTE nQuality
, BYTE nPitchAndFamily
,
589 LPCTSTR lpszFacename
)
591 ATLASSERT(m_hFont
== NULL
);
593 m_hFont
= ::CreateFont(nHeight
, nWidth
, nEscapement
,
594 nOrientation
, nWeight
, bItalic
, bUnderline
, cStrikeOut
,
595 nCharSet
, nOutPrecision
, nClipPrecision
, nQuality
,
596 nPitchAndFamily
, lpszFacename
);
598 m_hFont
= ATL::CreateFont(nHeight
, nWidth
, nEscapement
,
599 nOrientation
, nWeight
, bItalic
, bUnderline
, cStrikeOut
,
600 nCharSet
, nOutPrecision
, nClipPrecision
, nQuality
,
601 nPitchAndFamily
, lpszFacename
);
605 #endif // !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
607 HFONT
CreatePointFont(int nPointSize
, LPCTSTR lpszFaceName
, HDC hDC
= NULL
, bool bBold
= false, bool bItalic
= false)
609 LOGFONT logFont
= { 0 };
610 logFont
.lfCharSet
= DEFAULT_CHARSET
;
611 logFont
.lfHeight
= nPointSize
;
612 SecureHelper::strncpy_x(logFont
.lfFaceName
, _countof(logFont
.lfFaceName
), lpszFaceName
, _TRUNCATE
);
615 logFont
.lfWeight
= FW_BOLD
;
617 logFont
.lfItalic
= (BYTE
)TRUE
;
619 return CreatePointFontIndirect(&logFont
, hDC
);
622 HFONT
CreatePointFontIndirect(const LOGFONT
* lpLogFont
, HDC hDC
= NULL
)
624 HDC hDC1
= (hDC
!= NULL
) ? hDC
: ::GetDC(NULL
);
626 // convert nPointSize to logical units based on hDC
627 LOGFONT logFont
= *lpLogFont
;
630 pt
.y
= ::MulDiv(::GetDeviceCaps(hDC1
, LOGPIXELSY
), logFont
.lfHeight
, 720); // 72 points/inch, 10 decipoints/point
631 ::DPtoLP(hDC1
, &pt
, 1);
632 POINT ptOrg
= { 0, 0 };
633 ::DPtoLP(hDC1
, &ptOrg
, 1);
634 logFont
.lfHeight
= -abs(pt
.y
- ptOrg
.y
);
636 // DP and LP are always the same on CE
637 logFont
.lfHeight
= -abs(::MulDiv(::GetDeviceCaps(hDC1
, LOGPIXELSY
), logFont
.lfHeight
, 720)); // 72 points/inch, 10 decipoints/point
641 ::ReleaseDC(NULL
, hDC1
);
643 return CreateFontIndirect(&logFont
);
648 ATLASSERT(m_hFont
!= NULL
);
649 BOOL bRet
= ::DeleteObject(m_hFont
);
656 int GetLogFont(LOGFONT
* pLogFont
) const
658 ATLASSERT(m_hFont
!= NULL
);
659 return ::GetObject(m_hFont
, sizeof(LOGFONT
), pLogFont
);
662 bool GetLogFont(LOGFONT
& LogFont
) const
664 ATLASSERT(m_hFont
!= NULL
);
665 return (::GetObject(m_hFont
, sizeof(LOGFONT
), &LogFont
) == sizeof(LOGFONT
));
669 typedef CFontT
<false> CFontHandle
;
670 typedef CFontT
<true> CFont
;
673 ///////////////////////////////////////////////////////////////////////////////
676 template <bool t_bManaged
>
683 // Constructor/destructor/operators
684 CBitmapT(HBITMAP hBitmap
= NULL
) : m_hBitmap(hBitmap
)
689 if(t_bManaged
&& m_hBitmap
!= NULL
)
693 CBitmapT
<t_bManaged
>& operator =(HBITMAP hBitmap
)
699 void Attach(HBITMAP hBitmap
)
701 if(t_bManaged
&& m_hBitmap
!= NULL
&& m_hBitmap
!= hBitmap
)
702 ::DeleteObject(m_hBitmap
);
708 HBITMAP hBitmap
= m_hBitmap
;
713 operator HBITMAP() const { return m_hBitmap
; }
715 bool IsNull() const { return (m_hBitmap
== NULL
); }
717 // Create and load methods
718 HBITMAP
LoadBitmap(ATL::_U_STRINGorID bitmap
)
720 ATLASSERT(m_hBitmap
== NULL
);
721 m_hBitmap
= ::LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap
.m_lpstr
);
725 HBITMAP
LoadOEMBitmap(UINT nIDBitmap
) // for OBM_/OCR_/OIC_
727 ATLASSERT(m_hBitmap
== NULL
);
728 m_hBitmap
= ::LoadBitmap(NULL
, MAKEINTRESOURCE(nIDBitmap
));
733 HBITMAP
LoadMappedBitmap(UINT nIDBitmap
, UINT nFlags
= 0, LPCOLORMAP lpColorMap
= NULL
, int nMapSize
= 0)
735 ATLASSERT(m_hBitmap
== NULL
);
736 m_hBitmap
= ::CreateMappedBitmap(ModuleHelper::GetResourceInstance(), nIDBitmap
, (WORD
)nFlags
, lpColorMap
, nMapSize
);
739 #endif // !_WIN32_WCE
741 HBITMAP
CreateBitmap(int nWidth
, int nHeight
, UINT nPlanes
, UINT nBitsPerPixel
, const void* lpBits
)
743 ATLASSERT(m_hBitmap
== NULL
);
744 m_hBitmap
= ::CreateBitmap(nWidth
, nHeight
, nPlanes
, nBitsPerPixel
, lpBits
);
749 HBITMAP
CreateBitmapIndirect(LPBITMAP lpBitmap
)
751 ATLASSERT(m_hBitmap
== NULL
);
752 m_hBitmap
= ::CreateBitmapIndirect(lpBitmap
);
755 #endif // !_WIN32_WCE
757 HBITMAP
CreateCompatibleBitmap(HDC hDC
, int nWidth
, int nHeight
)
759 ATLASSERT(m_hBitmap
== NULL
);
760 m_hBitmap
= ::CreateCompatibleBitmap(hDC
, nWidth
, nHeight
);
765 HBITMAP
CreateDiscardableBitmap(HDC hDC
, int nWidth
, int nHeight
)
767 ATLASSERT(m_hBitmap
== NULL
);
768 m_hBitmap
= ::CreateDiscardableBitmap(hDC
, nWidth
, nHeight
);
771 #endif // !_WIN32_WCE
775 ATLASSERT(m_hBitmap
!= NULL
);
776 BOOL bRet
= ::DeleteObject(m_hBitmap
);
783 int GetBitmap(BITMAP
* pBitMap
) const
785 ATLASSERT(m_hBitmap
!= NULL
);
786 return ::GetObject(m_hBitmap
, sizeof(BITMAP
), pBitMap
);
789 bool GetBitmap(BITMAP
& bm
) const
791 ATLASSERT(m_hBitmap
!= NULL
);
792 return (::GetObject(m_hBitmap
, sizeof(BITMAP
), &bm
) == sizeof(BITMAP
));
795 bool GetSize(SIZE
& size
) const
797 ATLASSERT(m_hBitmap
!= NULL
);
801 size
.cx
= bm
.bmWidth
;
802 size
.cy
= bm
.bmHeight
;
807 DWORD
GetBitmapBits(DWORD dwCount
, LPVOID lpBits
) const
809 ATLASSERT(m_hBitmap
!= NULL
);
810 return ::GetBitmapBits(m_hBitmap
, dwCount
, lpBits
);
812 #endif // !_WIN32_WCE
814 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
815 DWORD
SetBitmapBits(DWORD dwCount
, const void* lpBits
)
817 ATLASSERT(m_hBitmap
!= NULL
);
818 return ::SetBitmapBits(m_hBitmap
, dwCount
, lpBits
);
820 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
823 BOOL
GetBitmapDimension(LPSIZE lpSize
) const
825 ATLASSERT(m_hBitmap
!= NULL
);
826 return ::GetBitmapDimensionEx(m_hBitmap
, lpSize
);
829 BOOL
SetBitmapDimension(int nWidth
, int nHeight
, LPSIZE lpSize
= NULL
)
831 ATLASSERT(m_hBitmap
!= NULL
);
832 return ::SetBitmapDimensionEx(m_hBitmap
, nWidth
, nHeight
, lpSize
);
836 HBITMAP
CreateDIBitmap(HDC hDC
, CONST BITMAPINFOHEADER
* lpbmih
, DWORD dwInit
, CONST VOID
* lpbInit
, CONST BITMAPINFO
* lpbmi
, UINT uColorUse
)
838 ATLASSERT(m_hBitmap
== NULL
);
839 m_hBitmap
= ::CreateDIBitmap(hDC
, lpbmih
, dwInit
, lpbInit
, lpbmi
, uColorUse
);
842 #endif // !_WIN32_WCE
844 HBITMAP
CreateDIBSection(HDC hDC
, CONST BITMAPINFO
* lpbmi
, UINT uColorUse
, VOID
** ppvBits
, HANDLE hSection
, DWORD dwOffset
)
846 ATLASSERT(m_hBitmap
== NULL
);
847 m_hBitmap
= ::CreateDIBSection(hDC
, lpbmi
, uColorUse
, ppvBits
, hSection
, dwOffset
);
852 int GetDIBits(HDC hDC
, UINT uStartScan
, UINT cScanLines
, LPVOID lpvBits
, LPBITMAPINFO lpbmi
, UINT uColorUse
) const
854 ATLASSERT(m_hBitmap
!= NULL
);
855 return ::GetDIBits(hDC
, m_hBitmap
, uStartScan
, cScanLines
, lpvBits
, lpbmi
, uColorUse
);
858 int SetDIBits(HDC hDC
, UINT uStartScan
, UINT cScanLines
, CONST VOID
* lpvBits
, CONST BITMAPINFO
* lpbmi
, UINT uColorUse
)
860 ATLASSERT(m_hBitmap
!= NULL
);
861 return ::SetDIBits(hDC
, m_hBitmap
, uStartScan
, cScanLines
, lpvBits
, lpbmi
, uColorUse
);
863 #endif // !_WIN32_WCE
866 typedef CBitmapT
<false> CBitmapHandle
;
867 typedef CBitmapT
<true> CBitmap
;
870 ///////////////////////////////////////////////////////////////////////////////
873 template <bool t_bManaged
>
880 // Constructor/destructor/operators
881 CPaletteT(HPALETTE hPalette
= NULL
) : m_hPalette(hPalette
)
886 if(t_bManaged
&& m_hPalette
!= NULL
)
890 CPaletteT
<t_bManaged
>& operator =(HPALETTE hPalette
)
896 void Attach(HPALETTE hPalette
)
898 if(t_bManaged
&& m_hPalette
!= NULL
&& m_hPalette
!= hPalette
)
899 ::DeleteObject(m_hPalette
);
900 m_hPalette
= hPalette
;
905 HPALETTE hPalette
= m_hPalette
;
910 operator HPALETTE() const { return m_hPalette
; }
912 bool IsNull() const { return (m_hPalette
== NULL
); }
915 HPALETTE
CreatePalette(LPLOGPALETTE lpLogPalette
)
917 ATLASSERT(m_hPalette
== NULL
);
918 m_hPalette
= ::CreatePalette(lpLogPalette
);
923 HPALETTE
CreateHalftonePalette(HDC hDC
)
925 ATLASSERT(m_hPalette
== NULL
);
926 ATLASSERT(hDC
!= NULL
);
927 m_hPalette
= ::CreateHalftonePalette(hDC
);
930 #endif // !_WIN32_WCE
934 ATLASSERT(m_hPalette
!= NULL
);
935 BOOL bRet
= ::DeleteObject(m_hPalette
);
942 int GetEntryCount() const
944 ATLASSERT(m_hPalette
!= NULL
);
946 ::GetObject(m_hPalette
, sizeof(WORD
), &nEntries
);
947 return (int)nEntries
;
950 UINT
GetPaletteEntries(UINT nStartIndex
, UINT nNumEntries
, LPPALETTEENTRY lpPaletteColors
) const
952 ATLASSERT(m_hPalette
!= NULL
);
953 return ::GetPaletteEntries(m_hPalette
, nStartIndex
, nNumEntries
, lpPaletteColors
);
956 UINT
SetPaletteEntries(UINT nStartIndex
, UINT nNumEntries
, LPPALETTEENTRY lpPaletteColors
)
958 ATLASSERT(m_hPalette
!= NULL
);
959 return ::SetPaletteEntries(m_hPalette
, nStartIndex
, nNumEntries
, lpPaletteColors
);
964 void AnimatePalette(UINT nStartIndex
, UINT nNumEntries
, LPPALETTEENTRY lpPaletteColors
)
966 ATLASSERT(m_hPalette
!= NULL
);
967 ::AnimatePalette(m_hPalette
, nStartIndex
, nNumEntries
, lpPaletteColors
);
970 BOOL
ResizePalette(UINT nNumEntries
)
972 ATLASSERT(m_hPalette
!= NULL
);
973 return ::ResizePalette(m_hPalette
, nNumEntries
);
975 #endif // !_WIN32_WCE
977 UINT
GetNearestPaletteIndex(COLORREF crColor
) const
979 ATLASSERT(m_hPalette
!= NULL
);
980 return ::GetNearestPaletteIndex(m_hPalette
, crColor
);
984 typedef CPaletteT
<false> CPaletteHandle
;
985 typedef CPaletteT
<true> CPalette
;
988 ///////////////////////////////////////////////////////////////////////////////
991 template <bool t_bManaged
>
998 // Constructor/destructor/operators
999 CRgnT(HRGN hRgn
= NULL
) : m_hRgn(hRgn
)
1004 if(t_bManaged
&& m_hRgn
!= NULL
)
1008 CRgnT
<t_bManaged
>& operator =(HRGN hRgn
)
1014 void Attach(HRGN hRgn
)
1016 if(t_bManaged
&& m_hRgn
!= NULL
&& m_hRgn
!= hRgn
)
1017 ::DeleteObject(m_hRgn
);
1028 operator HRGN() const { return m_hRgn
; }
1030 bool IsNull() const { return (m_hRgn
== NULL
); }
1033 HRGN
CreateRectRgn(int x1
, int y1
, int x2
, int y2
)
1035 ATLASSERT(m_hRgn
== NULL
);
1036 m_hRgn
= ::CreateRectRgn(x1
, y1
, x2
, y2
);
1040 HRGN
CreateRectRgnIndirect(LPCRECT lpRect
)
1042 ATLASSERT(m_hRgn
== NULL
);
1043 m_hRgn
= ::CreateRectRgnIndirect(lpRect
);
1048 HRGN
CreateEllipticRgn(int x1
, int y1
, int x2
, int y2
)
1050 ATLASSERT(m_hRgn
== NULL
);
1051 m_hRgn
= ::CreateEllipticRgn(x1
, y1
, x2
, y2
);
1055 HRGN
CreateEllipticRgnIndirect(LPCRECT lpRect
)
1057 ATLASSERT(m_hRgn
== NULL
);
1058 m_hRgn
= ::CreateEllipticRgnIndirect(lpRect
);
1062 HRGN
CreatePolygonRgn(LPPOINT lpPoints
, int nCount
, int nMode
)
1064 ATLASSERT(m_hRgn
== NULL
);
1065 m_hRgn
= ::CreatePolygonRgn(lpPoints
, nCount
, nMode
);
1069 HRGN
CreatePolyPolygonRgn(LPPOINT lpPoints
, LPINT lpPolyCounts
, int nCount
, int nPolyFillMode
)
1071 ATLASSERT(m_hRgn
== NULL
);
1072 m_hRgn
= ::CreatePolyPolygonRgn(lpPoints
, lpPolyCounts
, nCount
, nPolyFillMode
);
1076 HRGN
CreateRoundRectRgn(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
)
1078 ATLASSERT(m_hRgn
== NULL
);
1079 m_hRgn
= ::CreateRoundRectRgn(x1
, y1
, x2
, y2
, x3
, y3
);
1083 HRGN
CreateFromPath(HDC hDC
)
1085 ATLASSERT(m_hRgn
== NULL
);
1086 ATLASSERT(hDC
!= NULL
);
1087 m_hRgn
= ::PathToRegion(hDC
);
1091 HRGN
CreateFromData(const XFORM
* lpXForm
, int nCount
, const RGNDATA
* pRgnData
)
1093 ATLASSERT(m_hRgn
== NULL
);
1094 m_hRgn
= ::ExtCreateRegion(lpXForm
, nCount
, pRgnData
);
1097 #endif // !_WIN32_WCE
1101 ATLASSERT(m_hRgn
!= NULL
);
1102 BOOL bRet
= ::DeleteObject(m_hRgn
);
1109 void SetRectRgn(int x1
, int y1
, int x2
, int y2
)
1111 ATLASSERT(m_hRgn
!= NULL
);
1112 ::SetRectRgn(m_hRgn
, x1
, y1
, x2
, y2
);
1115 void SetRectRgn(LPCRECT lpRect
)
1117 ATLASSERT(m_hRgn
!= NULL
);
1118 ::SetRectRgn(m_hRgn
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
1121 int CombineRgn(HRGN hRgnSrc1
, HRGN hRgnSrc2
, int nCombineMode
)
1123 ATLASSERT(m_hRgn
!= NULL
);
1124 return ::CombineRgn(m_hRgn
, hRgnSrc1
, hRgnSrc2
, nCombineMode
);
1127 int CombineRgn(HRGN hRgnSrc
, int nCombineMode
)
1129 ATLASSERT(m_hRgn
!= NULL
);
1130 return ::CombineRgn(m_hRgn
, m_hRgn
, hRgnSrc
, nCombineMode
);
1133 int CopyRgn(HRGN hRgnSrc
)
1135 ATLASSERT(m_hRgn
!= NULL
);
1136 return ::CombineRgn(m_hRgn
, hRgnSrc
, NULL
, RGN_COPY
);
1139 BOOL
EqualRgn(HRGN hRgn
) const
1141 ATLASSERT(m_hRgn
!= NULL
);
1142 return ::EqualRgn(m_hRgn
, hRgn
);
1145 int OffsetRgn(int x
, int y
)
1147 ATLASSERT(m_hRgn
!= NULL
);
1148 return ::OffsetRgn(m_hRgn
, x
, y
);
1151 int OffsetRgn(POINT point
)
1153 ATLASSERT(m_hRgn
!= NULL
);
1154 return ::OffsetRgn(m_hRgn
, point
.x
, point
.y
);
1157 int GetRgnBox(LPRECT lpRect
) const
1159 ATLASSERT(m_hRgn
!= NULL
);
1160 return ::GetRgnBox(m_hRgn
, lpRect
);
1163 BOOL
PtInRegion(int x
, int y
) const
1165 ATLASSERT(m_hRgn
!= NULL
);
1166 return ::PtInRegion(m_hRgn
, x
, y
);
1169 BOOL
PtInRegion(POINT point
) const
1171 ATLASSERT(m_hRgn
!= NULL
);
1172 return ::PtInRegion(m_hRgn
, point
.x
, point
.y
);
1175 BOOL
RectInRegion(LPCRECT lpRect
) const
1177 ATLASSERT(m_hRgn
!= NULL
);
1178 return ::RectInRegion(m_hRgn
, lpRect
);
1181 int GetRegionData(LPRGNDATA lpRgnData
, int nDataSize
) const
1183 ATLASSERT(m_hRgn
!= NULL
);
1184 return (int)::GetRegionData(m_hRgn
, nDataSize
, lpRgnData
);
1188 typedef CRgnT
<false> CRgnHandle
;
1189 typedef CRgnT
<true> CRgn
;
1192 ///////////////////////////////////////////////////////////////////////////////
1193 // CDC - The device context class
1195 template <bool t_bManaged
>
1202 // Constructor/destructor/operators
1203 CDCT(HDC hDC
= NULL
) : m_hDC(hDC
)
1209 if(t_bManaged
&& m_hDC
!= NULL
)
1210 ::DeleteDC(Detach());
1213 CDCT
<t_bManaged
>& operator =(HDC hDC
)
1219 void Attach(HDC hDC
)
1221 if(t_bManaged
&& m_hDC
!= NULL
&& m_hDC
!= hDC
)
1233 operator HDC() const { return m_hDC
; }
1235 bool IsNull() const { return (m_hDC
== NULL
); }
1239 HWND
WindowFromDC() const
1241 ATLASSERT(m_hDC
!= NULL
);
1242 return ::WindowFromDC(m_hDC
);
1244 #endif // !_WIN32_WCE
1246 CPenHandle
GetCurrentPen() const
1248 ATLASSERT(m_hDC
!= NULL
);
1249 return CPenHandle((HPEN
)::GetCurrentObject(m_hDC
, OBJ_PEN
));
1252 CBrushHandle
GetCurrentBrush() const
1254 ATLASSERT(m_hDC
!= NULL
);
1255 return CBrushHandle((HBRUSH
)::GetCurrentObject(m_hDC
, OBJ_BRUSH
));
1258 CPaletteHandle
GetCurrentPalette() const
1260 ATLASSERT(m_hDC
!= NULL
);
1261 return CPaletteHandle((HPALETTE
)::GetCurrentObject(m_hDC
, OBJ_PAL
));
1264 CFontHandle
GetCurrentFont() const
1266 ATLASSERT(m_hDC
!= NULL
);
1267 return CFontHandle((HFONT
)::GetCurrentObject(m_hDC
, OBJ_FONT
));
1270 CBitmapHandle
GetCurrentBitmap() const
1272 ATLASSERT(m_hDC
!= NULL
);
1273 return CBitmapHandle((HBITMAP
)::GetCurrentObject(m_hDC
, OBJ_BITMAP
));
1276 HDC
CreateDC(LPCTSTR lpszDriverName
, LPCTSTR lpszDeviceName
, LPCTSTR lpszOutput
, const DEVMODE
* lpInitData
)
1278 ATLASSERT(m_hDC
== NULL
);
1279 m_hDC
= ::CreateDC(lpszDriverName
, lpszDeviceName
, lpszOutput
, lpInitData
);
1283 HDC
CreateCompatibleDC(HDC hDC
= NULL
)
1285 ATLASSERT(m_hDC
== NULL
);
1286 m_hDC
= ::CreateCompatibleDC(hDC
);
1294 BOOL bRet
= ::DeleteDC(m_hDC
);
1300 // Device-Context Functions
1303 ATLASSERT(m_hDC
!= NULL
);
1304 return ::SaveDC(m_hDC
);
1307 BOOL
RestoreDC(int nSavedDC
)
1309 ATLASSERT(m_hDC
!= NULL
);
1310 return ::RestoreDC(m_hDC
, nSavedDC
);
1313 int GetDeviceCaps(int nIndex
) const
1315 ATLASSERT(m_hDC
!= NULL
);
1316 return ::GetDeviceCaps(m_hDC
, nIndex
);
1320 UINT
SetBoundsRect(LPCRECT lpRectBounds
, UINT flags
)
1322 ATLASSERT(m_hDC
!= NULL
);
1323 return ::SetBoundsRect(m_hDC
, lpRectBounds
, flags
);
1326 UINT
GetBoundsRect(LPRECT lpRectBounds
, UINT flags
) const
1328 ATLASSERT(m_hDC
!= NULL
);
1329 return ::GetBoundsRect(m_hDC
, lpRectBounds
, flags
);
1332 BOOL
ResetDC(const DEVMODE
* lpDevMode
)
1334 ATLASSERT(m_hDC
!= NULL
);
1335 return ::ResetDC(m_hDC
, lpDevMode
) != NULL
;
1338 // Drawing-Tool Functions
1339 BOOL
GetBrushOrg(LPPOINT lpPoint
) const
1341 ATLASSERT(m_hDC
!= NULL
);
1342 return ::GetBrushOrgEx(m_hDC
, lpPoint
);
1344 #endif // !_WIN32_WCE
1346 BOOL
SetBrushOrg(int x
, int y
, LPPOINT lpPoint
= NULL
)
1348 ATLASSERT(m_hDC
!= NULL
);
1349 return ::SetBrushOrgEx(m_hDC
, x
, y
, lpPoint
);
1352 BOOL
SetBrushOrg(POINT point
, LPPOINT lpPointRet
= NULL
)
1354 ATLASSERT(m_hDC
!= NULL
);
1355 return ::SetBrushOrgEx(m_hDC
, point
.x
, point
.y
, lpPointRet
);
1359 int EnumObjects(int nObjectType
, int (CALLBACK
* lpfn
)(LPVOID
, LPARAM
), LPARAM lpData
)
1361 ATLASSERT(m_hDC
!= NULL
);
1363 return ::EnumObjects(m_hDC
, nObjectType
, (GOBJENUMPROC
)lpfn
, lpData
);
1365 return ::EnumObjects(m_hDC
, nObjectType
, (GOBJENUMPROC
)lpfn
, (LPVOID
)lpData
);
1368 #endif // !_WIN32_WCE
1370 // Type-safe selection helpers
1371 HPEN
SelectPen(HPEN hPen
)
1373 ATLASSERT(m_hDC
!= NULL
);
1375 ATLASSERT(hPen
== NULL
|| ::GetObjectType(hPen
) == OBJ_PEN
|| ::GetObjectType(hPen
) == OBJ_EXTPEN
);
1376 #else // CE specific
1377 ATLASSERT(hPen
== NULL
|| ::GetObjectType(hPen
) == OBJ_PEN
);
1378 #endif // _WIN32_WCE
1379 return (HPEN
)::SelectObject(m_hDC
, hPen
);
1382 HBRUSH
SelectBrush(HBRUSH hBrush
)
1384 ATLASSERT(m_hDC
!= NULL
);
1385 ATLASSERT(hBrush
== NULL
|| ::GetObjectType(hBrush
) == OBJ_BRUSH
);
1386 return (HBRUSH
)::SelectObject(m_hDC
, hBrush
);
1389 HFONT
SelectFont(HFONT hFont
)
1391 ATLASSERT(m_hDC
!= NULL
);
1392 ATLASSERT(hFont
== NULL
|| ::GetObjectType(hFont
) == OBJ_FONT
);
1393 return (HFONT
)::SelectObject(m_hDC
, hFont
);
1396 HBITMAP
SelectBitmap(HBITMAP hBitmap
)
1398 ATLASSERT(m_hDC
!= NULL
);
1399 ATLASSERT(hBitmap
== NULL
|| ::GetObjectType(hBitmap
) == OBJ_BITMAP
);
1400 return (HBITMAP
)::SelectObject(m_hDC
, hBitmap
);
1403 int SelectRgn(HRGN hRgn
) // special return for regions
1405 ATLASSERT(m_hDC
!= NULL
);
1406 ATLASSERT(hRgn
== NULL
|| ::GetObjectType(hRgn
) == OBJ_REGION
);
1407 return PtrToInt(::SelectObject(m_hDC
, hRgn
));
1410 // Type-safe selection helpers for stock objects
1411 HPEN
SelectStockPen(int nPen
)
1413 ATLASSERT(m_hDC
!= NULL
);
1414 #if (_WIN32_WINNT >= 0x0500)
1415 ATLASSERT(nPen
== WHITE_PEN
|| nPen
== BLACK_PEN
|| nPen
== NULL_PEN
|| nPen
== DC_PEN
);
1417 ATLASSERT(nPen
== WHITE_PEN
|| nPen
== BLACK_PEN
|| nPen
== NULL_PEN
);
1418 #endif // !(_WIN32_WINNT >= 0x0500)
1419 return SelectPen((HPEN
)::GetStockObject(nPen
));
1422 HBRUSH
SelectStockBrush(int nBrush
)
1424 #if (_WIN32_WINNT >= 0x0500)
1425 ATLASSERT((nBrush
>= WHITE_BRUSH
&& nBrush
<= HOLLOW_BRUSH
) || nBrush
== DC_BRUSH
);
1427 ATLASSERT(nBrush
>= WHITE_BRUSH
&& nBrush
<= HOLLOW_BRUSH
);
1428 #endif // !(_WIN32_WINNT >= 0x0500)
1429 return SelectBrush((HBRUSH
)::GetStockObject(nBrush
));
1432 HFONT
SelectStockFont(int nFont
)
1435 ATLASSERT((nFont
>= OEM_FIXED_FONT
&& nFont
<= SYSTEM_FIXED_FONT
) || nFont
== DEFAULT_GUI_FONT
);
1436 #else // CE specific
1437 ATLASSERT(nFont
== SYSTEM_FONT
);
1438 #endif // _WIN32_WCE
1439 return SelectFont((HFONT
)::GetStockObject(nFont
));
1442 HPALETTE
SelectStockPalette(int nPalette
, BOOL bForceBackground
)
1444 ATLASSERT(nPalette
== DEFAULT_PALETTE
); // the only one supported
1445 return SelectPalette((HPALETTE
)::GetStockObject(nPalette
), bForceBackground
);
1448 // Color and Color Palette Functions
1449 COLORREF
GetNearestColor(COLORREF crColor
) const
1451 ATLASSERT(m_hDC
!= NULL
);
1452 return ::GetNearestColor(m_hDC
, crColor
);
1455 HPALETTE
SelectPalette(HPALETTE hPalette
, BOOL bForceBackground
)
1457 ATLASSERT(m_hDC
!= NULL
);
1459 return ::SelectPalette(m_hDC
, hPalette
, bForceBackground
);
1462 UINT
RealizePalette()
1464 ATLASSERT(m_hDC
!= NULL
);
1465 return ::RealizePalette(m_hDC
);
1471 ATLASSERT(m_hDC
!= NULL
);
1472 ::UpdateColors(m_hDC
);
1474 #endif // !_WIN32_WCE
1476 // Drawing-Attribute Functions
1477 COLORREF
GetBkColor() const
1479 ATLASSERT(m_hDC
!= NULL
);
1480 return ::GetBkColor(m_hDC
);
1483 int GetBkMode() const
1485 ATLASSERT(m_hDC
!= NULL
);
1486 return ::GetBkMode(m_hDC
);
1490 int GetPolyFillMode() const
1492 ATLASSERT(m_hDC
!= NULL
);
1493 return ::GetPolyFillMode(m_hDC
);
1498 ATLASSERT(m_hDC
!= NULL
);
1499 return ::GetROP2(m_hDC
);
1502 int GetStretchBltMode() const
1504 ATLASSERT(m_hDC
!= NULL
);
1505 return ::GetStretchBltMode(m_hDC
);
1507 #endif // !_WIN32_WCE
1509 COLORREF
GetTextColor() const
1511 ATLASSERT(m_hDC
!= NULL
);
1512 return ::GetTextColor(m_hDC
);
1515 COLORREF
SetBkColor(COLORREF crColor
)
1517 ATLASSERT(m_hDC
!= NULL
);
1518 return ::SetBkColor(m_hDC
, crColor
);
1521 int SetBkMode(int nBkMode
)
1523 ATLASSERT(m_hDC
!= NULL
);
1524 return ::SetBkMode(m_hDC
, nBkMode
);
1528 int SetPolyFillMode(int nPolyFillMode
)
1530 ATLASSERT(m_hDC
!= NULL
);
1531 return ::SetPolyFillMode(m_hDC
, nPolyFillMode
);
1533 #endif // !_WIN32_WCE
1535 int SetROP2(int nDrawMode
)
1537 ATLASSERT(m_hDC
!= NULL
);
1538 return ::SetROP2(m_hDC
, nDrawMode
);
1542 int SetStretchBltMode(int nStretchMode
)
1544 ATLASSERT(m_hDC
!= NULL
);
1545 return ::SetStretchBltMode(m_hDC
, nStretchMode
);
1547 #endif // !_WIN32_WCE
1549 COLORREF
SetTextColor(COLORREF crColor
)
1551 ATLASSERT(m_hDC
!= NULL
);
1552 return ::SetTextColor(m_hDC
, crColor
);
1556 BOOL
GetColorAdjustment(LPCOLORADJUSTMENT lpColorAdjust
) const
1558 ATLASSERT(m_hDC
!= NULL
);
1559 return ::GetColorAdjustment(m_hDC
, lpColorAdjust
);
1562 BOOL
SetColorAdjustment(const COLORADJUSTMENT
* lpColorAdjust
)
1564 ATLASSERT(m_hDC
!= NULL
);
1565 return ::SetColorAdjustment(m_hDC
, lpColorAdjust
);
1568 // Mapping Functions
1569 int GetMapMode() const
1571 ATLASSERT(m_hDC
!= NULL
);
1572 return ::GetMapMode(m_hDC
);
1575 BOOL
GetViewportOrg(LPPOINT lpPoint
) const
1577 ATLASSERT(m_hDC
!= NULL
);
1578 return ::GetViewportOrgEx(m_hDC
, lpPoint
);
1581 int SetMapMode(int nMapMode
)
1583 ATLASSERT(m_hDC
!= NULL
);
1584 return ::SetMapMode(m_hDC
, nMapMode
);
1586 #endif // !_WIN32_WCE
1589 BOOL
SetViewportOrg(int x
, int y
, LPPOINT lpPoint
= NULL
)
1591 ATLASSERT(m_hDC
!= NULL
);
1592 return ::SetViewportOrgEx(m_hDC
, x
, y
, lpPoint
);
1595 BOOL
SetViewportOrg(POINT point
, LPPOINT lpPointRet
= NULL
)
1597 ATLASSERT(m_hDC
!= NULL
);
1598 return SetViewportOrg(point
.x
, point
.y
, lpPointRet
);
1602 BOOL
OffsetViewportOrg(int nWidth
, int nHeight
, LPPOINT lpPoint
= NULL
)
1604 ATLASSERT(m_hDC
!= NULL
);
1605 return ::OffsetViewportOrgEx(m_hDC
, nWidth
, nHeight
, lpPoint
);
1609 BOOL
GetViewportExt(LPSIZE lpSize
) const
1611 ATLASSERT(m_hDC
!= NULL
);
1612 return ::GetViewportExtEx(m_hDC
, lpSize
);
1615 BOOL
SetViewportExt(int x
, int y
, LPSIZE lpSize
= NULL
)
1617 ATLASSERT(m_hDC
!= NULL
);
1618 return ::SetViewportExtEx(m_hDC
, x
, y
, lpSize
);
1621 BOOL
SetViewportExt(SIZE size
, LPSIZE lpSizeRet
= NULL
)
1623 ATLASSERT(m_hDC
!= NULL
);
1624 return SetViewportExt(size
.cx
, size
.cy
, lpSizeRet
);
1627 BOOL
ScaleViewportExt(int xNum
, int xDenom
, int yNum
, int yDenom
, LPSIZE lpSize
= NULL
)
1629 ATLASSERT(m_hDC
!= NULL
);
1630 return ::ScaleViewportExtEx(m_hDC
, xNum
, xDenom
, yNum
, yDenom
, lpSize
);
1632 #endif // !_WIN32_WCE
1636 BOOL
GetWindowOrg(LPPOINT lpPoint
) const
1638 ATLASSERT(m_hDC
!= NULL
);
1639 return ::GetWindowOrgEx(m_hDC
, lpPoint
);
1642 BOOL
SetWindowOrg(int x
, int y
, LPPOINT lpPoint
= NULL
)
1644 ATLASSERT(m_hDC
!= NULL
);
1645 return ::SetWindowOrgEx(m_hDC
, x
, y
, lpPoint
);
1648 BOOL
SetWindowOrg(POINT point
, LPPOINT lpPointRet
= NULL
)
1650 ATLASSERT(m_hDC
!= NULL
);
1651 return SetWindowOrg(point
.x
, point
.y
, lpPointRet
);
1654 BOOL
OffsetWindowOrg(int nWidth
, int nHeight
, LPPOINT lpPoint
= NULL
)
1656 ATLASSERT(m_hDC
!= NULL
);
1657 return ::OffsetWindowOrgEx(m_hDC
, nWidth
, nHeight
, lpPoint
);
1661 BOOL
GetWindowExt(LPSIZE lpSize
) const
1663 ATLASSERT(m_hDC
!= NULL
);
1664 return ::GetWindowExtEx(m_hDC
, lpSize
);
1667 BOOL
SetWindowExt(int x
, int y
, LPSIZE lpSize
= NULL
)
1669 ATLASSERT(m_hDC
!= NULL
);
1670 return ::SetWindowExtEx(m_hDC
, x
, y
, lpSize
);
1673 BOOL
SetWindowExt(SIZE size
, LPSIZE lpSizeRet
= NULL
)
1675 ATLASSERT(m_hDC
!= NULL
);
1676 return SetWindowExt(size
.cx
, size
.cy
, lpSizeRet
);
1679 BOOL
ScaleWindowExt(int xNum
, int xDenom
, int yNum
, int yDenom
, LPSIZE lpSize
= NULL
)
1681 ATLASSERT(m_hDC
!= NULL
);
1682 return ::ScaleWindowExtEx(m_hDC
, xNum
, xDenom
, yNum
, yDenom
, lpSize
);
1685 // Coordinate Functions
1686 BOOL
DPtoLP(LPPOINT lpPoints
, int nCount
= 1) const
1688 ATLASSERT(m_hDC
!= NULL
);
1689 return ::DPtoLP(m_hDC
, lpPoints
, nCount
);
1692 BOOL
DPtoLP(LPRECT lpRect
) const
1694 ATLASSERT(m_hDC
!= NULL
);
1695 return ::DPtoLP(m_hDC
, (LPPOINT
)lpRect
, 2);
1698 BOOL
DPtoLP(LPSIZE lpSize
) const
1700 SIZE sizeWinExt
= { 0, 0 };
1701 if(!GetWindowExt(&sizeWinExt
))
1703 SIZE sizeVpExt
= { 0, 0 };
1704 if(!GetViewportExt(&sizeVpExt
))
1706 lpSize
->cx
= ::MulDiv(lpSize
->cx
, abs(sizeWinExt
.cx
), abs(sizeVpExt
.cx
));
1707 lpSize
->cy
= ::MulDiv(lpSize
->cy
, abs(sizeWinExt
.cy
), abs(sizeVpExt
.cy
));
1711 BOOL
LPtoDP(LPPOINT lpPoints
, int nCount
= 1) const
1713 ATLASSERT(m_hDC
!= NULL
);
1714 return ::LPtoDP(m_hDC
, lpPoints
, nCount
);
1717 BOOL
LPtoDP(LPRECT lpRect
) const
1719 ATLASSERT(m_hDC
!= NULL
);
1720 return ::LPtoDP(m_hDC
, (LPPOINT
)lpRect
, 2);
1723 BOOL
LPtoDP(LPSIZE lpSize
) const
1725 SIZE sizeWinExt
= { 0, 0 };
1726 if(!GetWindowExt(&sizeWinExt
))
1728 SIZE sizeVpExt
= { 0, 0 };
1729 if(!GetViewportExt(&sizeVpExt
))
1731 lpSize
->cx
= ::MulDiv(lpSize
->cx
, abs(sizeVpExt
.cx
), abs(sizeWinExt
.cx
));
1732 lpSize
->cy
= ::MulDiv(lpSize
->cy
, abs(sizeVpExt
.cy
), abs(sizeWinExt
.cy
));
1736 // Special Coordinate Functions (useful for dealing with metafiles and OLE)
1737 #define HIMETRIC_INCH 2540 // HIMETRIC units per inch
1739 void DPtoHIMETRIC(LPSIZE lpSize
) const
1741 ATLASSERT(m_hDC
!= NULL
);
1743 if((nMapMode
= GetMapMode()) < MM_ISOTROPIC
&& nMapMode
!= MM_TEXT
)
1745 // when using a constrained map mode, map against physical inch
1746 ((CDCHandle
*)this)->SetMapMode(MM_HIMETRIC
);
1748 ((CDCHandle
*)this)->SetMapMode(nMapMode
);
1752 // map against logical inch for non-constrained mapping modes
1753 int cxPerInch
= GetDeviceCaps(LOGPIXELSX
);
1754 int cyPerInch
= GetDeviceCaps(LOGPIXELSY
);
1755 ATLASSERT(cxPerInch
!= 0 && cyPerInch
!= 0);
1756 lpSize
->cx
= ::MulDiv(lpSize
->cx
, HIMETRIC_INCH
, cxPerInch
);
1757 lpSize
->cy
= ::MulDiv(lpSize
->cy
, HIMETRIC_INCH
, cyPerInch
);
1761 void HIMETRICtoDP(LPSIZE lpSize
) const
1763 ATLASSERT(m_hDC
!= NULL
);
1765 if((nMapMode
= GetMapMode()) < MM_ISOTROPIC
&& nMapMode
!= MM_TEXT
)
1767 // when using a constrained map mode, map against physical inch
1768 ((CDCHandle
*)this)->SetMapMode(MM_HIMETRIC
);
1770 ((CDCHandle
*)this)->SetMapMode(nMapMode
);
1774 // map against logical inch for non-constrained mapping modes
1775 int cxPerInch
= GetDeviceCaps(LOGPIXELSX
);
1776 int cyPerInch
= GetDeviceCaps(LOGPIXELSY
);
1777 ATLASSERT(cxPerInch
!= 0 && cyPerInch
!= 0);
1778 lpSize
->cx
= ::MulDiv(lpSize
->cx
, cxPerInch
, HIMETRIC_INCH
);
1779 lpSize
->cy
= ::MulDiv(lpSize
->cy
, cyPerInch
, HIMETRIC_INCH
);
1783 void LPtoHIMETRIC(LPSIZE lpSize
) const
1786 DPtoHIMETRIC(lpSize
);
1789 void HIMETRICtoLP(LPSIZE lpSize
) const
1791 HIMETRICtoDP(lpSize
);
1794 #endif // !_WIN32_WCE
1797 BOOL
FillRgn(HRGN hRgn
, HBRUSH hBrush
)
1799 ATLASSERT(m_hDC
!= NULL
);
1800 return ::FillRgn(m_hDC
, hRgn
, hBrush
);
1804 BOOL
FrameRgn(HRGN hRgn
, HBRUSH hBrush
, int nWidth
, int nHeight
)
1806 ATLASSERT(m_hDC
!= NULL
);
1807 return ::FrameRgn(m_hDC
, hRgn
, hBrush
, nWidth
, nHeight
);
1810 BOOL
InvertRgn(HRGN hRgn
)
1812 ATLASSERT(m_hDC
!= NULL
);
1813 return ::InvertRgn(m_hDC
, hRgn
);
1816 BOOL
PaintRgn(HRGN hRgn
)
1818 ATLASSERT(m_hDC
!= NULL
);
1819 return ::PaintRgn(m_hDC
, hRgn
);
1821 #endif // !_WIN32_WCE
1823 // Clipping Functions
1824 int GetClipBox(LPRECT lpRect
) const
1826 ATLASSERT(m_hDC
!= NULL
);
1827 return ::GetClipBox(m_hDC
, lpRect
);
1830 int GetClipRgn(CRgn
& region
) const
1832 ATLASSERT(m_hDC
!= NULL
);
1834 region
.CreateRectRgn(0, 0, 0, 0);
1836 int nRet
= ::GetClipRgn(m_hDC
, region
);
1838 region
.DeleteObject();
1844 BOOL
PtVisible(int x
, int y
) const
1846 ATLASSERT(m_hDC
!= NULL
);
1847 return ::PtVisible(m_hDC
, x
, y
);
1850 BOOL
PtVisible(POINT point
) const
1852 ATLASSERT(m_hDC
!= NULL
);
1853 return ::PtVisible(m_hDC
, point
.x
, point
.y
);
1855 #endif // !_WIN32_WCE
1857 BOOL
RectVisible(LPCRECT lpRect
) const
1859 ATLASSERT(m_hDC
!= NULL
);
1860 return ::RectVisible(m_hDC
, lpRect
);
1863 int SelectClipRgn(HRGN hRgn
)
1865 ATLASSERT(m_hDC
!= NULL
);
1866 return ::SelectClipRgn(m_hDC
, (HRGN
)hRgn
);
1869 int ExcludeClipRect(int x1
, int y1
, int x2
, int y2
)
1871 ATLASSERT(m_hDC
!= NULL
);
1872 return ::ExcludeClipRect(m_hDC
, x1
, y1
, x2
, y2
);
1875 int ExcludeClipRect(LPCRECT lpRect
)
1877 ATLASSERT(m_hDC
!= NULL
);
1878 return ::ExcludeClipRect(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
1882 int ExcludeUpdateRgn(HWND hWnd
)
1884 ATLASSERT(m_hDC
!= NULL
);
1885 return ::ExcludeUpdateRgn(m_hDC
, hWnd
);
1887 #endif // !_WIN32_WCE
1889 int IntersectClipRect(int x1
, int y1
, int x2
, int y2
)
1891 ATLASSERT(m_hDC
!= NULL
);
1892 return ::IntersectClipRect(m_hDC
, x1
, y1
, x2
, y2
);
1895 int IntersectClipRect(LPCRECT lpRect
)
1897 ATLASSERT(m_hDC
!= NULL
);
1898 return ::IntersectClipRect(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
1902 int OffsetClipRgn(int x
, int y
)
1904 ATLASSERT(m_hDC
!= NULL
);
1905 return ::OffsetClipRgn(m_hDC
, x
, y
);
1908 int OffsetClipRgn(SIZE size
)
1910 ATLASSERT(m_hDC
!= NULL
);
1911 return ::OffsetClipRgn(m_hDC
, size
.cx
, size
.cy
);
1914 int SelectClipRgn(HRGN hRgn
, int nMode
)
1916 ATLASSERT(m_hDC
!= NULL
);
1917 return ::ExtSelectClipRgn(m_hDC
, hRgn
, nMode
);
1919 #endif // !_WIN32_WCE
1921 // Line-Output Functions
1922 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
1923 BOOL
GetCurrentPosition(LPPOINT lpPoint
) const
1925 ATLASSERT(m_hDC
!= NULL
);
1926 return ::GetCurrentPositionEx(m_hDC
, lpPoint
);
1929 BOOL
MoveTo(int x
, int y
, LPPOINT lpPoint
= NULL
)
1931 ATLASSERT(m_hDC
!= NULL
);
1932 return ::MoveToEx(m_hDC
, x
, y
, lpPoint
);
1935 BOOL
MoveTo(POINT point
, LPPOINT lpPointRet
= NULL
)
1937 ATLASSERT(m_hDC
!= NULL
);
1938 return MoveTo(point
.x
, point
.y
, lpPointRet
);
1941 BOOL
LineTo(int x
, int y
)
1943 ATLASSERT(m_hDC
!= NULL
);
1944 return ::LineTo(m_hDC
, x
, y
);
1947 BOOL
LineTo(POINT point
)
1949 ATLASSERT(m_hDC
!= NULL
);
1950 return LineTo(point
.x
, point
.y
);
1952 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
1955 BOOL
Arc(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
, int x4
, int y4
)
1957 ATLASSERT(m_hDC
!= NULL
);
1958 return ::Arc(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
1961 BOOL
Arc(LPCRECT lpRect
, POINT ptStart
, POINT ptEnd
)
1963 ATLASSERT(m_hDC
!= NULL
);
1964 return ::Arc(m_hDC
, lpRect
->left
, lpRect
->top
,
1965 lpRect
->right
, lpRect
->bottom
, ptStart
.x
, ptStart
.y
,
1968 #endif // !_WIN32_WCE
1970 BOOL
Polyline(LPPOINT lpPoints
, int nCount
)
1972 ATLASSERT(m_hDC
!= NULL
);
1973 return ::Polyline(m_hDC
, lpPoints
, nCount
);
1977 BOOL
AngleArc(int x
, int y
, int nRadius
, float fStartAngle
, float fSweepAngle
)
1979 ATLASSERT(m_hDC
!= NULL
);
1980 return ::AngleArc(m_hDC
, x
, y
, nRadius
, fStartAngle
, fSweepAngle
);
1983 BOOL
ArcTo(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
, int x4
, int y4
)
1985 ATLASSERT(m_hDC
!= NULL
);
1986 return ::ArcTo(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
1989 BOOL
ArcTo(LPCRECT lpRect
, POINT ptStart
, POINT ptEnd
)
1991 ATLASSERT(m_hDC
!= NULL
);
1992 return ArcTo(lpRect
->left
, lpRect
->top
, lpRect
->right
,
1993 lpRect
->bottom
, ptStart
.x
, ptStart
.y
, ptEnd
.x
, ptEnd
.y
);
1996 int GetArcDirection() const
1998 ATLASSERT(m_hDC
!= NULL
);
1999 return ::GetArcDirection(m_hDC
);
2002 int SetArcDirection(int nArcDirection
)
2004 ATLASSERT(m_hDC
!= NULL
);
2005 return ::SetArcDirection(m_hDC
, nArcDirection
);
2008 BOOL
PolyDraw(const POINT
* lpPoints
, const BYTE
* lpTypes
, int nCount
)
2010 ATLASSERT(m_hDC
!= NULL
);
2011 return ::PolyDraw(m_hDC
, lpPoints
, lpTypes
, nCount
);
2014 BOOL
PolylineTo(const POINT
* lpPoints
, int nCount
)
2016 ATLASSERT(m_hDC
!= NULL
);
2017 return ::PolylineTo(m_hDC
, lpPoints
, nCount
);
2020 BOOL
PolyPolyline(const POINT
* lpPoints
,
2021 const DWORD
* lpPolyPoints
, int nCount
)
2023 ATLASSERT(m_hDC
!= NULL
);
2024 return ::PolyPolyline(m_hDC
, lpPoints
, lpPolyPoints
, nCount
);
2027 BOOL
PolyBezier(const POINT
* lpPoints
, int nCount
)
2029 ATLASSERT(m_hDC
!= NULL
);
2030 return ::PolyBezier(m_hDC
, lpPoints
, nCount
);
2033 BOOL
PolyBezierTo(const POINT
* lpPoints
, int nCount
)
2035 ATLASSERT(m_hDC
!= NULL
);
2036 return ::PolyBezierTo(m_hDC
, lpPoints
, nCount
);
2038 #endif // !_WIN32_WCE
2040 // Simple Drawing Functions
2041 BOOL
FillRect(LPCRECT lpRect
, HBRUSH hBrush
)
2043 ATLASSERT(m_hDC
!= NULL
);
2044 return ::FillRect(m_hDC
, lpRect
, hBrush
);
2047 BOOL
FillRect(LPCRECT lpRect
, int nColorIndex
)
2049 ATLASSERT(m_hDC
!= NULL
);
2051 return ::FillRect(m_hDC
, lpRect
, (HBRUSH
)LongToPtr(nColorIndex
+ 1));
2052 #else // CE specific
2053 return ::FillRect(m_hDC
, lpRect
, ::GetSysColorBrush(nColorIndex
));
2054 #endif // _WIN32_WCE
2058 BOOL
FrameRect(LPCRECT lpRect
, HBRUSH hBrush
)
2060 ATLASSERT(m_hDC
!= NULL
);
2061 return ::FrameRect(m_hDC
, lpRect
, hBrush
);
2063 #endif // !_WIN32_WCE
2065 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 420)
2066 BOOL
InvertRect(LPCRECT lpRect
)
2068 ATLASSERT(m_hDC
!= NULL
);
2069 return ::InvertRect(m_hDC
, lpRect
);
2071 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 420)
2073 BOOL
DrawIcon(int x
, int y
, HICON hIcon
)
2075 ATLASSERT(m_hDC
!= NULL
);
2077 return ::DrawIcon(m_hDC
, x
, y
, hIcon
);
2078 #else // CE specific
2079 return ::DrawIconEx(m_hDC
, x
, y
, hIcon
, 0, 0, 0, NULL
, DI_NORMAL
);
2080 #endif // _WIN32_WCE
2083 BOOL
DrawIcon(POINT point
, HICON hIcon
)
2085 ATLASSERT(m_hDC
!= NULL
);
2087 return ::DrawIcon(m_hDC
, point
.x
, point
.y
, hIcon
);
2088 #else // CE specific
2089 return ::DrawIconEx(m_hDC
, point
.x
, point
.y
, hIcon
, 0, 0, 0, NULL
, DI_NORMAL
);
2090 #endif // _WIN32_WCE
2093 BOOL
DrawIconEx(int x
, int y
, HICON hIcon
, int cxWidth
, int cyWidth
, UINT uStepIfAniCur
= 0, HBRUSH hbrFlickerFreeDraw
= NULL
, UINT uFlags
= DI_NORMAL
)
2095 ATLASSERT(m_hDC
!= NULL
);
2096 return ::DrawIconEx(m_hDC
, x
, y
, hIcon
, cxWidth
, cyWidth
, uStepIfAniCur
, hbrFlickerFreeDraw
, uFlags
);
2099 BOOL
DrawIconEx(POINT point
, HICON hIcon
, SIZE size
, UINT uStepIfAniCur
= 0, HBRUSH hbrFlickerFreeDraw
= NULL
, UINT uFlags
= DI_NORMAL
)
2101 ATLASSERT(m_hDC
!= NULL
);
2102 return ::DrawIconEx(m_hDC
, point
.x
, point
.y
, hIcon
, size
.cx
, size
.cy
, uStepIfAniCur
, hbrFlickerFreeDraw
, uFlags
);
2106 BOOL
DrawState(POINT pt
, SIZE size
, HBITMAP hBitmap
, UINT nFlags
, HBRUSH hBrush
= NULL
)
2108 ATLASSERT(m_hDC
!= NULL
);
2109 return ::DrawState(m_hDC
, hBrush
, NULL
, (LPARAM
)hBitmap
, 0, pt
.x
, pt
.y
, size
.cx
, size
.cy
, nFlags
| DST_BITMAP
);
2112 BOOL
DrawState(POINT pt
, SIZE size
, HICON hIcon
, UINT nFlags
, HBRUSH hBrush
= NULL
)
2114 ATLASSERT(m_hDC
!= NULL
);
2115 return ::DrawState(m_hDC
, hBrush
, NULL
, (LPARAM
)hIcon
, 0, pt
.x
, pt
.y
, size
.cx
, size
.cy
, nFlags
| DST_ICON
);
2118 BOOL
DrawState(POINT pt
, SIZE size
, LPCTSTR lpszText
, UINT nFlags
, BOOL bPrefixText
= TRUE
, int nTextLen
= 0, HBRUSH hBrush
= NULL
)
2120 ATLASSERT(m_hDC
!= NULL
);
2121 return ::DrawState(m_hDC
, hBrush
, NULL
, (LPARAM
)lpszText
, (WPARAM
)nTextLen
, pt
.x
, pt
.y
, size
.cx
, size
.cy
, nFlags
| (bPrefixText
? DST_PREFIXTEXT
: DST_TEXT
));
2124 BOOL
DrawState(POINT pt
, SIZE size
, DRAWSTATEPROC lpDrawProc
, LPARAM lData
, UINT nFlags
, HBRUSH hBrush
= NULL
)
2126 ATLASSERT(m_hDC
!= NULL
);
2127 return ::DrawState(m_hDC
, hBrush
, lpDrawProc
, lData
, 0, pt
.x
, pt
.y
, size
.cx
, size
.cy
, nFlags
| DST_COMPLEX
);
2129 #endif // !_WIN32_WCE
2131 // Ellipse and Polygon Functions
2133 BOOL
Chord(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
, int x4
, int y4
)
2135 ATLASSERT(m_hDC
!= NULL
);
2136 return ::Chord(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
2139 BOOL
Chord(LPCRECT lpRect
, POINT ptStart
, POINT ptEnd
)
2141 ATLASSERT(m_hDC
!= NULL
);
2142 return ::Chord(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
, ptStart
.x
, ptStart
.y
, ptEnd
.x
, ptEnd
.y
);
2144 #endif // !_WIN32_WCE
2146 void DrawFocusRect(LPCRECT lpRect
)
2148 ATLASSERT(m_hDC
!= NULL
);
2149 ::DrawFocusRect(m_hDC
, lpRect
);
2152 BOOL
Ellipse(int x1
, int y1
, int x2
, int y2
)
2154 ATLASSERT(m_hDC
!= NULL
);
2155 return ::Ellipse(m_hDC
, x1
, y1
, x2
, y2
);
2158 BOOL
Ellipse(LPCRECT lpRect
)
2160 ATLASSERT(m_hDC
!= NULL
);
2161 return ::Ellipse(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
2165 BOOL
Pie(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
, int x4
, int y4
)
2167 ATLASSERT(m_hDC
!= NULL
);
2168 return ::Pie(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
2171 BOOL
Pie(LPCRECT lpRect
, POINT ptStart
, POINT ptEnd
)
2173 ATLASSERT(m_hDC
!= NULL
);
2174 return ::Pie(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
, ptStart
.x
, ptStart
.y
, ptEnd
.x
, ptEnd
.y
);
2176 #endif // !_WIN32_WCE
2178 BOOL
Polygon(LPPOINT lpPoints
, int nCount
)
2180 ATLASSERT(m_hDC
!= NULL
);
2181 return ::Polygon(m_hDC
, lpPoints
, nCount
);
2185 BOOL
PolyPolygon(LPPOINT lpPoints
, LPINT lpPolyCounts
, int nCount
)
2187 ATLASSERT(m_hDC
!= NULL
);
2188 return ::PolyPolygon(m_hDC
, lpPoints
, lpPolyCounts
, nCount
);
2190 #endif // !_WIN32_WCE
2192 BOOL
Rectangle(int x1
, int y1
, int x2
, int y2
)
2194 ATLASSERT(m_hDC
!= NULL
);
2195 return ::Rectangle(m_hDC
, x1
, y1
, x2
, y2
);
2198 BOOL
Rectangle(LPCRECT lpRect
)
2200 ATLASSERT(m_hDC
!= NULL
);
2201 return ::Rectangle(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
2204 BOOL
RoundRect(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
)
2206 ATLASSERT(m_hDC
!= NULL
);
2207 return ::RoundRect(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
);
2210 BOOL
RoundRect(LPCRECT lpRect
, POINT point
)
2212 ATLASSERT(m_hDC
!= NULL
);
2213 return ::RoundRect(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
, point
.x
, point
.y
);
2217 BOOL
PatBlt(int x
, int y
, int nWidth
, int nHeight
, DWORD dwRop
)
2219 ATLASSERT(m_hDC
!= NULL
);
2220 return ::PatBlt(m_hDC
, x
, y
, nWidth
, nHeight
, dwRop
);
2223 BOOL
BitBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
,
2224 int xSrc
, int ySrc
, DWORD dwRop
)
2226 ATLASSERT(m_hDC
!= NULL
);
2227 return ::BitBlt(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, dwRop
);
2230 BOOL
StretchBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, int nSrcWidth
, int nSrcHeight
, DWORD dwRop
)
2232 ATLASSERT(m_hDC
!= NULL
);
2233 return ::StretchBlt(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, dwRop
);
2236 COLORREF
GetPixel(int x
, int y
) const
2238 ATLASSERT(m_hDC
!= NULL
);
2239 return ::GetPixel(m_hDC
, x
, y
);
2242 COLORREF
GetPixel(POINT point
) const
2244 ATLASSERT(m_hDC
!= NULL
);
2245 return ::GetPixel(m_hDC
, point
.x
, point
.y
);
2248 COLORREF
SetPixel(int x
, int y
, COLORREF crColor
)
2250 ATLASSERT(m_hDC
!= NULL
);
2251 return ::SetPixel(m_hDC
, x
, y
, crColor
);
2254 COLORREF
SetPixel(POINT point
, COLORREF crColor
)
2256 ATLASSERT(m_hDC
!= NULL
);
2257 return ::SetPixel(m_hDC
, point
.x
, point
.y
, crColor
);
2261 BOOL
FloodFill(int x
, int y
, COLORREF crColor
)
2263 ATLASSERT(m_hDC
!= NULL
);
2264 return ::FloodFill(m_hDC
, x
, y
, crColor
);
2267 BOOL
ExtFloodFill(int x
, int y
, COLORREF crColor
, UINT nFillType
)
2269 ATLASSERT(m_hDC
!= NULL
);
2270 return ::ExtFloodFill(m_hDC
, x
, y
, crColor
, nFillType
);
2272 #endif // !_WIN32_WCE
2274 BOOL
MaskBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, HBITMAP hMaskBitmap
, int xMask
, int yMask
, DWORD dwRop
)
2276 ATLASSERT(m_hDC
!= NULL
);
2277 return ::MaskBlt(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, hMaskBitmap
, xMask
, yMask
, dwRop
);
2281 BOOL
PlgBlt(LPPOINT lpPoint
, HDC hSrcDC
, int xSrc
, int ySrc
, int nWidth
, int nHeight
, HBITMAP hMaskBitmap
, int xMask
, int yMask
)
2283 ATLASSERT(m_hDC
!= NULL
);
2284 return ::PlgBlt(m_hDC
, lpPoint
, hSrcDC
, xSrc
, ySrc
, nWidth
, nHeight
, hMaskBitmap
, xMask
, yMask
);
2287 BOOL
SetPixelV(int x
, int y
, COLORREF crColor
)
2289 ATLASSERT(m_hDC
!= NULL
);
2290 return ::SetPixelV(m_hDC
, x
, y
, crColor
);
2293 BOOL
SetPixelV(POINT point
, COLORREF crColor
)
2295 ATLASSERT(m_hDC
!= NULL
);
2296 return ::SetPixelV(m_hDC
, point
.x
, point
.y
, crColor
);
2298 #endif // !_WIN32_WCE
2300 #if !defined(_ATL_NO_MSIMG) || defined(_WIN32_WCE)
2302 BOOL
TransparentBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, int nSrcWidth
, int nSrcHeight
, UINT crTransparent
)
2304 ATLASSERT(m_hDC
!= NULL
);
2305 return ::TransparentBlt(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, crTransparent
);
2307 #else // CE specific
2308 BOOL
TransparentImage(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, int nSrcWidth
, int nSrcHeight
, UINT crTransparent
)
2310 ATLASSERT(m_hDC
!= NULL
);
2311 return ::TransparentImage(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, crTransparent
);
2313 #endif // _WIN32_WCE
2315 #if (!defined(_WIN32_WCE) || (_WIN32_WCE >= 420))
2316 BOOL
GradientFill(const PTRIVERTEX pVertices
, DWORD nVertices
, void* pMeshElements
, DWORD nMeshElements
, DWORD dwMode
)
2318 ATLASSERT(m_hDC
!= NULL
);
2319 return ::GradientFill(m_hDC
, pVertices
, nVertices
, pMeshElements
, nMeshElements
, dwMode
);
2321 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 420)
2323 #if !defined(_WIN32_WCE) || (_WIN32_WCE > 0x500)
2324 BOOL
AlphaBlend(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, int nSrcWidth
, int nSrcHeight
, BLENDFUNCTION bf
)
2326 ATLASSERT(m_hDC
!= NULL
);
2327 return ::AlphaBlend(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, bf
);
2329 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE > 0x500)
2330 #endif // !defined(_ATL_NO_MSIMG) || defined(_WIN32_WCE)
2332 // Extra bitmap functions
2333 // Helper function for painting a disabled toolbar or menu bitmap
2334 // This function can take either an HBITMAP (for SS) or a DC with
2335 // the bitmap already painted (for cmdbar)
2336 BOOL
DitherBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, HBITMAP hBitmap
, int xSrc
, int ySrc
,
2337 HBRUSH hBrushBackground
= ::GetSysColorBrush(COLOR_3DFACE
),
2338 HBRUSH hBrush3DEffect
= ::GetSysColorBrush(COLOR_3DHILIGHT
),
2339 HBRUSH hBrushDisabledImage
= ::GetSysColorBrush(COLOR_3DSHADOW
))
2341 ATLASSERT(m_hDC
!= NULL
|| hBitmap
!= NULL
);
2342 ATLASSERT(nWidth
> 0 && nHeight
> 0);
2344 // Create a generic DC for all BitBlts
2345 CDCHandle dc
= (hSrcDC
!= NULL
) ? hSrcDC
: ::CreateCompatibleDC(m_hDC
);
2346 ATLASSERT(dc
.m_hDC
!= NULL
);
2347 if(dc
.m_hDC
== NULL
)
2350 // Create a DC for the monochrome DIB section
2351 CDC dcBW
= ::CreateCompatibleDC(m_hDC
);
2352 ATLASSERT(dcBW
.m_hDC
!= NULL
);
2353 if(dcBW
.m_hDC
== NULL
)
2360 // Create the monochrome DIB section with a black and white palette
2361 struct RGBBWBITMAPINFO
2363 BITMAPINFOHEADER bmiHeader
;
2364 RGBQUAD bmiColors
[2];
2367 RGBBWBITMAPINFO rgbBWBitmapInfo
=
2369 { sizeof(BITMAPINFOHEADER
), nWidth
, nHeight
, 1, 1, BI_RGB
, 0, 0, 0, 0, 0 },
2370 { { 0x00, 0x00, 0x00, 0x00 }, { 0xFF, 0xFF, 0xFF, 0x00 } }
2374 CBitmap bmpBW
= ::CreateDIBSection(dcBW
, (LPBITMAPINFO
)&rgbBWBitmapInfo
, DIB_RGB_COLORS
, &pbitsBW
, NULL
, 0);
2375 ATLASSERT(bmpBW
.m_hBitmap
!= NULL
);
2376 if(bmpBW
.m_hBitmap
== NULL
)
2383 // Attach the monochrome DIB section and the bitmap to the DCs
2384 HBITMAP hbmOldBW
= dcBW
.SelectBitmap(bmpBW
);
2385 HBITMAP hbmOldDC
= NULL
;
2387 hbmOldDC
= dc
.SelectBitmap(hBitmap
);
2389 // Block: Dark gray removal: we want (128, 128, 128) pixels to become black and not white
2391 CDC dcTemp1
= ::CreateCompatibleDC(m_hDC
);
2392 CDC dcTemp2
= ::CreateCompatibleDC(m_hDC
);
2394 bmpTemp1
.CreateCompatibleBitmap(dc
, nWidth
, nHeight
);
2396 bmpTemp2
.CreateBitmap(nWidth
, nHeight
, 1, 1, NULL
);
2397 HBITMAP hOldBmp1
= dcTemp1
.SelectBitmap(bmpTemp1
);
2398 HBITMAP hOldBmp2
= dcTemp2
.SelectBitmap(bmpTemp2
);
2399 // Let's copy our image, it will be altered
2400 dcTemp1
.BitBlt(0, 0, nWidth
, nHeight
, dc
, xSrc
, ySrc
, SRCCOPY
);
2402 // All dark gray pixels will become white, the others black
2403 dcTemp1
.SetBkColor(RGB(128, 128, 128));
2404 dcTemp2
.BitBlt(0, 0, nWidth
, nHeight
, dcTemp1
, 0, 0, SRCCOPY
);
2405 // Do an XOR to set to black these white pixels
2406 dcTemp1
.BitBlt(0, 0, nWidth
, nHeight
, dcTemp2
, 0, 0, SRCINVERT
);
2408 // BitBlt the bitmap into the monochrome DIB section
2409 // The DIB section will do a true monochrome conversion
2410 // The magenta background being closer to white will become white
2411 dcBW
.BitBlt(0, 0, nWidth
, nHeight
, dcTemp1
, 0, 0, SRCCOPY
);
2414 dcTemp1
.SelectBitmap(hOldBmp1
);
2415 dcTemp2
.SelectBitmap(hOldBmp2
);
2418 // Paint the destination rectangle using hBrushBackground
2419 if(hBrushBackground
!= NULL
)
2421 RECT rc
= { x
, y
, x
+ nWidth
, y
+ nHeight
};
2422 FillRect(&rc
, hBrushBackground
);
2425 // BitBlt the black bits in the monochrome bitmap into hBrush3DEffect color in the destination DC
2426 // The magic ROP comes from the Charles Petzold's book
2427 HBRUSH hOldBrush
= SelectBrush(hBrush3DEffect
);
2428 BitBlt(x
+ 1, y
+ 1, nWidth
, nHeight
, dcBW
, 0, 0, 0xB8074A);
2430 // BitBlt the black bits in the monochrome bitmap into hBrushDisabledImage color in the destination DC
2431 SelectBrush(hBrushDisabledImage
);
2432 BitBlt(x
, y
, nWidth
, nHeight
, dcBW
, 0, 0, 0xB8074A);
2434 SelectBrush(hOldBrush
);
2435 dcBW
.SelectBitmap(hbmOldBW
);
2436 dc
.SelectBitmap(hbmOldDC
);
2446 BOOL
TextOut(int x
, int y
, LPCTSTR lpszString
, int nCount
= -1)
2448 ATLASSERT(m_hDC
!= NULL
);
2450 nCount
= lstrlen(lpszString
);
2451 return ::TextOut(m_hDC
, x
, y
, lpszString
, nCount
);
2453 #endif // !_WIN32_WCE
2455 BOOL
ExtTextOut(int x
, int y
, UINT nOptions
, LPCRECT lpRect
, LPCTSTR lpszString
, UINT nCount
= -1, LPINT lpDxWidths
= NULL
)
2457 ATLASSERT(m_hDC
!= NULL
);
2459 nCount
= lstrlen(lpszString
);
2460 return ::ExtTextOut(m_hDC
, x
, y
, nOptions
, lpRect
, lpszString
, nCount
, lpDxWidths
);
2464 SIZE
TabbedTextOut(int x
, int y
, LPCTSTR lpszString
, int nCount
= -1, int nTabPositions
= 0, LPINT lpnTabStopPositions
= NULL
, int nTabOrigin
= 0)
2466 ATLASSERT(m_hDC
!= NULL
);
2468 nCount
= lstrlen(lpszString
);
2469 LONG lRes
= ::TabbedTextOut(m_hDC
, x
, y
, lpszString
, nCount
, nTabPositions
, lpnTabStopPositions
, nTabOrigin
);
2470 SIZE size
= { GET_X_LPARAM(lRes
), GET_Y_LPARAM(lRes
) };
2473 #endif // !_WIN32_WCE
2475 int DrawText(LPCTSTR lpstrText
, int cchText
, LPRECT lpRect
, UINT uFormat
)
2477 ATLASSERT(m_hDC
!= NULL
);
2479 ATLASSERT((uFormat
& DT_MODIFYSTRING
) == 0);
2480 #endif // !_WIN32_WCE
2481 return ::DrawText(m_hDC
, lpstrText
, cchText
, lpRect
, uFormat
);
2484 int DrawText(LPTSTR lpstrText
, int cchText
, LPRECT lpRect
, UINT uFormat
)
2486 ATLASSERT(m_hDC
!= NULL
);
2487 return ::DrawText(m_hDC
, lpstrText
, cchText
, lpRect
, uFormat
);
2491 int DrawTextEx(LPTSTR lpstrText
, int cchText
, LPRECT lpRect
, UINT uFormat
, LPDRAWTEXTPARAMS lpDTParams
= NULL
)
2493 ATLASSERT(m_hDC
!= NULL
);
2494 return ::DrawTextEx(m_hDC
, lpstrText
, cchText
, lpRect
, uFormat
, lpDTParams
);
2496 #endif // !_WIN32_WCE
2498 #if (_WIN32_WINNT >= 0x0501)
2499 int DrawShadowText(LPCWSTR lpstrText
, int cchText
, LPRECT lpRect
, DWORD dwFlags
, COLORREF clrText
, COLORREF clrShadow
, int xOffset
, int yOffset
)
2501 ATLASSERT(m_hDC
!= NULL
);
2502 // This function is present only if comctl32.dll version 6 is loaded;
2503 // we use LoadLibrary/GetProcAddress to allow apps compiled with
2504 // _WIN32_WINNT >= 0x0501 to run on older Windows/CommCtrl
2506 HMODULE hCommCtrlDLL
= ::LoadLibrary(_T("comctl32.dll"));
2507 ATLASSERT(hCommCtrlDLL
!= NULL
);
2508 if(hCommCtrlDLL
!= NULL
)
2510 typedef int (WINAPI
*PFN_DrawShadowText
)(HDC hDC
, LPCWSTR lpstrText
, UINT cchText
, LPRECT lpRect
, DWORD dwFlags
, COLORREF clrText
, COLORREF clrShadow
, int xOffset
, int yOffset
);
2511 PFN_DrawShadowText pfnDrawShadowText
= (PFN_DrawShadowText
)::GetProcAddress(hCommCtrlDLL
, "DrawShadowText");
2512 ATLASSERT(pfnDrawShadowText
!= NULL
); // this function requires CommCtrl6
2513 if(pfnDrawShadowText
!= NULL
)
2514 nRet
= pfnDrawShadowText(m_hDC
, lpstrText
, cchText
, lpRect
, dwFlags
, clrText
, clrShadow
, xOffset
, yOffset
);
2515 ::FreeLibrary(hCommCtrlDLL
);
2519 #endif // (_WIN32_WINNT >= 0x0501)
2521 BOOL
GetTextExtent(LPCTSTR lpszString
, int nCount
, LPSIZE lpSize
) const
2523 ATLASSERT(m_hDC
!= NULL
);
2525 nCount
= lstrlen(lpszString
);
2526 return ::GetTextExtentPoint32(m_hDC
, lpszString
, nCount
, lpSize
);
2529 BOOL
GetTextExtentExPoint(LPCTSTR lpszString
, int cchString
, LPSIZE lpSize
, int nMaxExtent
, LPINT lpnFit
= NULL
, LPINT alpDx
= NULL
)
2531 ATLASSERT(m_hDC
!= NULL
);
2532 return ::GetTextExtentExPoint(m_hDC
, lpszString
, cchString
, nMaxExtent
, lpnFit
, alpDx
, lpSize
);
2536 DWORD
GetTabbedTextExtent(LPCTSTR lpszString
, int nCount
= -1, int nTabPositions
= 0, LPINT lpnTabStopPositions
= NULL
) const
2538 ATLASSERT(m_hDC
!= NULL
);
2540 nCount
= lstrlen(lpszString
);
2541 return ::GetTabbedTextExtent(m_hDC
, lpszString
, nCount
, nTabPositions
, lpnTabStopPositions
);
2544 BOOL
GrayString(HBRUSH hBrush
, BOOL (CALLBACK
* lpfnOutput
)(HDC
, LPARAM
, int), LPARAM lpData
, int nCount
, int x
, int y
, int nWidth
, int nHeight
)
2546 ATLASSERT(m_hDC
!= NULL
);
2547 return ::GrayString(m_hDC
, hBrush
, (GRAYSTRINGPROC
)lpfnOutput
, lpData
, nCount
, x
, y
, nWidth
, nHeight
);
2549 #endif // !_WIN32_WCE
2551 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
2552 UINT
GetTextAlign() const
2554 ATLASSERT(m_hDC
!= NULL
);
2555 return ::GetTextAlign(m_hDC
);
2558 UINT
SetTextAlign(UINT nFlags
)
2560 ATLASSERT(m_hDC
!= NULL
);
2561 return ::SetTextAlign(m_hDC
, nFlags
);
2563 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
2565 int GetTextFace(LPTSTR lpszFacename
, int nCount
) const
2567 ATLASSERT(m_hDC
!= NULL
);
2568 return ::GetTextFace(m_hDC
, nCount
, lpszFacename
);
2571 int GetTextFaceLen() const
2573 ATLASSERT(m_hDC
!= NULL
);
2574 return ::GetTextFace(m_hDC
, 0, NULL
);
2579 BOOL
GetTextFace(BSTR
& bstrFace
) const
2582 ATLASSERT(m_hDC
!= NULL
);
2583 ATLASSERT(bstrFace
== NULL
);
2585 int nLen
= GetTextFaceLen();
2589 CTempBuffer
<TCHAR
, _WTL_STACK_ALLOC_THRESHOLD
> buff
;
2590 LPTSTR lpszText
= buff
.Allocate(nLen
);
2591 if(lpszText
== NULL
)
2594 if(!GetTextFace(lpszText
, nLen
))
2597 bstrFace
= ::SysAllocString(T2OLE(lpszText
));
2598 return (bstrFace
!= NULL
) ? TRUE
: FALSE
;
2601 #endif // !_ATL_NO_COM
2603 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
2604 int GetTextFace(_CSTRING_NS::CString
& strFace
) const
2606 ATLASSERT(m_hDC
!= NULL
);
2608 int nLen
= GetTextFaceLen();
2612 LPTSTR lpstr
= strFace
.GetBufferSetLength(nLen
);
2615 int nRet
= GetTextFace(lpstr
, nLen
);
2616 strFace
.ReleaseBuffer();
2619 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
2621 BOOL
GetTextMetrics(LPTEXTMETRIC lpMetrics
) const
2623 ATLASSERT(m_hDC
!= NULL
);
2624 return ::GetTextMetrics(m_hDC
, lpMetrics
);
2628 int SetTextJustification(int nBreakExtra
, int nBreakCount
)
2630 ATLASSERT(m_hDC
!= NULL
);
2631 return ::SetTextJustification(m_hDC
, nBreakExtra
, nBreakCount
);
2634 int GetTextCharacterExtra() const
2636 ATLASSERT(m_hDC
!= NULL
);
2637 return ::GetTextCharacterExtra(m_hDC
);
2640 int SetTextCharacterExtra(int nCharExtra
)
2642 ATLASSERT(m_hDC
!= NULL
);
2643 return ::SetTextCharacterExtra(m_hDC
, nCharExtra
);
2645 #endif // !_WIN32_WCE
2648 BOOL
DrawEdge(LPRECT lpRect
, UINT nEdge
, UINT nFlags
)
2650 ATLASSERT(m_hDC
!= NULL
);
2651 return ::DrawEdge(m_hDC
, lpRect
, nEdge
, nFlags
);
2654 BOOL
DrawFrameControl(LPRECT lpRect
, UINT nType
, UINT nState
)
2656 ATLASSERT(m_hDC
!= NULL
);
2657 return ::DrawFrameControl(m_hDC
, lpRect
, nType
, nState
);
2660 // Scrolling Functions
2661 BOOL
ScrollDC(int dx
, int dy
, LPCRECT lpRectScroll
, LPCRECT lpRectClip
, HRGN hRgnUpdate
, LPRECT lpRectUpdate
)
2663 ATLASSERT(m_hDC
!= NULL
);
2664 return ::ScrollDC(m_hDC
, dx
, dy
, lpRectScroll
, lpRectClip
, hRgnUpdate
, lpRectUpdate
);
2669 BOOL
GetCharWidth(UINT nFirstChar
, UINT nLastChar
, LPINT lpBuffer
) const
2671 ATLASSERT(m_hDC
!= NULL
);
2672 return ::GetCharWidth(m_hDC
, nFirstChar
, nLastChar
, lpBuffer
);
2675 // GetCharWidth32 is not supported under Win9x
2676 BOOL
GetCharWidth32(UINT nFirstChar
, UINT nLastChar
, LPINT lpBuffer
) const
2678 ATLASSERT(m_hDC
!= NULL
);
2679 return ::GetCharWidth32(m_hDC
, nFirstChar
, nLastChar
, lpBuffer
);
2682 DWORD
SetMapperFlags(DWORD dwFlag
)
2684 ATLASSERT(m_hDC
!= NULL
);
2685 return ::SetMapperFlags(m_hDC
, dwFlag
);
2688 BOOL
GetAspectRatioFilter(LPSIZE lpSize
) const
2690 ATLASSERT(m_hDC
!= NULL
);
2691 return ::GetAspectRatioFilterEx(m_hDC
, lpSize
);
2694 BOOL
GetCharABCWidths(UINT nFirstChar
, UINT nLastChar
, LPABC lpabc
) const
2696 ATLASSERT(m_hDC
!= NULL
);
2697 return ::GetCharABCWidths(m_hDC
, nFirstChar
, nLastChar
, lpabc
);
2700 DWORD
GetFontData(DWORD dwTable
, DWORD dwOffset
, LPVOID lpData
, DWORD cbData
) const
2702 ATLASSERT(m_hDC
!= NULL
);
2703 return ::GetFontData(m_hDC
, dwTable
, dwOffset
, lpData
, cbData
);
2706 int GetKerningPairs(int nPairs
, LPKERNINGPAIR lpkrnpair
) const
2708 ATLASSERT(m_hDC
!= NULL
);
2709 return ::GetKerningPairs(m_hDC
, nPairs
, lpkrnpair
);
2712 UINT
GetOutlineTextMetrics(UINT cbData
, LPOUTLINETEXTMETRIC lpotm
) const
2714 ATLASSERT(m_hDC
!= NULL
);
2715 return ::GetOutlineTextMetrics(m_hDC
, cbData
, lpotm
);
2718 DWORD
GetGlyphOutline(UINT nChar
, UINT nFormat
, LPGLYPHMETRICS lpgm
, DWORD cbBuffer
, LPVOID lpBuffer
, const MAT2
* lpmat2
) const
2720 ATLASSERT(m_hDC
!= NULL
);
2721 return ::GetGlyphOutline(m_hDC
, nChar
, nFormat
, lpgm
, cbBuffer
, lpBuffer
, lpmat2
);
2724 BOOL
GetCharABCWidths(UINT nFirstChar
, UINT nLastChar
, LPABCFLOAT lpABCF
) const
2726 ATLASSERT(m_hDC
!= NULL
);
2727 return ::GetCharABCWidthsFloat(m_hDC
, nFirstChar
, nLastChar
, lpABCF
);
2730 BOOL
GetCharWidth(UINT nFirstChar
, UINT nLastChar
, float* lpFloatBuffer
) const
2732 ATLASSERT(m_hDC
!= NULL
);
2733 return ::GetCharWidthFloat(m_hDC
, nFirstChar
, nLastChar
, lpFloatBuffer
);
2735 #endif // !_WIN32_WCE
2737 // Printer/Device Escape Functions
2739 int Escape(int nEscape
, int nCount
, LPCSTR lpszInData
, LPVOID lpOutData
)
2741 ATLASSERT(m_hDC
!= NULL
);
2742 return ::Escape(m_hDC
, nEscape
, nCount
, lpszInData
, lpOutData
);
2744 #endif // !_WIN32_WCE
2746 int Escape(int nEscape
, int nInputSize
, LPCSTR lpszInputData
,
2747 int nOutputSize
, LPSTR lpszOutputData
)
2749 ATLASSERT(m_hDC
!= NULL
);
2750 return ::ExtEscape(m_hDC
, nEscape
, nInputSize
, lpszInputData
, nOutputSize
, lpszOutputData
);
2754 int DrawEscape(int nEscape
, int nInputSize
, LPCSTR lpszInputData
)
2756 ATLASSERT(m_hDC
!= NULL
);
2757 return ::DrawEscape(m_hDC
, nEscape
, nInputSize
, lpszInputData
);
2759 #endif // !_WIN32_WCE
2762 #if !defined(_WIN32_WCE) || ((_WIN32_WCE >= 200) && defined(StartDoc))
2763 int StartDoc(LPCTSTR lpszDocName
) // old Win3.0 version
2766 di
.cbSize
= sizeof(DOCINFO
);
2767 di
.lpszDocName
= lpszDocName
;
2768 return StartDoc(&di
);
2771 int StartDoc(LPDOCINFO lpDocInfo
)
2773 ATLASSERT(m_hDC
!= NULL
);
2774 return ::StartDoc(m_hDC
, lpDocInfo
);
2779 ATLASSERT(m_hDC
!= NULL
);
2780 return ::StartPage(m_hDC
);
2785 ATLASSERT(m_hDC
!= NULL
);
2786 return ::EndPage(m_hDC
);
2789 int SetAbortProc(BOOL (CALLBACK
* lpfn
)(HDC
, int))
2791 ATLASSERT(m_hDC
!= NULL
);
2792 return ::SetAbortProc(m_hDC
, (ABORTPROC
)lpfn
);
2797 ATLASSERT(m_hDC
!= NULL
);
2798 return ::AbortDoc(m_hDC
);
2803 ATLASSERT(m_hDC
!= NULL
);
2804 return ::EndDoc(m_hDC
);
2806 #endif // !defined(_WIN32_WCE) || ((_WIN32_WCE >= 200) && defined(StartDoc))
2808 // MetaFile Functions
2810 BOOL
PlayMetaFile(HMETAFILE hMF
)
2812 ATLASSERT(m_hDC
!= NULL
);
2813 if(::GetDeviceCaps(m_hDC
, TECHNOLOGY
) == DT_METAFILE
)
2815 // playing metafile in metafile, just use core windows API
2816 return ::PlayMetaFile(m_hDC
, hMF
);
2819 // for special playback, lParam == pDC
2820 return ::EnumMetaFile(m_hDC
, hMF
, EnumMetaFileProc
, (LPARAM
)this);
2823 BOOL
PlayMetaFile(HENHMETAFILE hEnhMetaFile
, LPCRECT lpBounds
)
2825 ATLASSERT(m_hDC
!= NULL
);
2826 return ::PlayEnhMetaFile(m_hDC
, hEnhMetaFile
, lpBounds
);
2829 BOOL
AddMetaFileComment(UINT nDataSize
, const BYTE
* pCommentData
) // can be used for enhanced metafiles only
2831 ATLASSERT(m_hDC
!= NULL
);
2832 return ::GdiComment(m_hDC
, nDataSize
, pCommentData
);
2835 // Special handling for metafile playback
2836 static int CALLBACK
EnumMetaFileProc(HDC hDC
, HANDLETABLE
* pHandleTable
, METARECORD
* pMetaRec
, int nHandles
, LPARAM lParam
)
2838 CDCHandle
* pDC
= (CDCHandle
*)lParam
;
2840 switch (pMetaRec
->rdFunction
)
2842 case META_SETMAPMODE
:
2843 pDC
->SetMapMode((int)(short)pMetaRec
->rdParm
[0]);
2845 case META_SETWINDOWEXT
:
2846 pDC
->SetWindowExt((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2848 case META_SETWINDOWORG
:
2849 pDC
->SetWindowOrg((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2851 case META_SETVIEWPORTEXT
:
2852 pDC
->SetViewportExt((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2854 case META_SETVIEWPORTORG
:
2855 pDC
->SetViewportOrg((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2857 case META_SCALEWINDOWEXT
:
2858 pDC
->ScaleWindowExt((int)(short)pMetaRec
->rdParm
[3], (int)(short)pMetaRec
->rdParm
[2],
2859 (int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2861 case META_SCALEVIEWPORTEXT
:
2862 pDC
->ScaleViewportExt((int)(short)pMetaRec
->rdParm
[3], (int)(short)pMetaRec
->rdParm
[2],
2863 (int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2865 case META_OFFSETVIEWPORTORG
:
2866 pDC
->OffsetViewportOrg((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2871 case META_RESTOREDC
:
2872 pDC
->RestoreDC((int)(short)pMetaRec
->rdParm
[0]);
2874 case META_SETBKCOLOR
:
2875 pDC
->SetBkColor(*(UNALIGNED COLORREF
*)&pMetaRec
->rdParm
[0]);
2877 case META_SETTEXTCOLOR
:
2878 pDC
->SetTextColor(*(UNALIGNED COLORREF
*)&pMetaRec
->rdParm
[0]);
2881 // need to watch out for SelectObject(HFONT), for custom font mapping
2882 case META_SELECTOBJECT
:
2884 HGDIOBJ hObject
= pHandleTable
->objectHandle
[pMetaRec
->rdParm
[0]];
2885 UINT nObjType
= ::GetObjectType(hObject
);
2888 // object type is unknown, determine if it is a font
2889 HFONT hStockFont
= (HFONT
)::GetStockObject(SYSTEM_FONT
);
2890 HFONT hFontOld
= (HFONT
)::SelectObject(pDC
->m_hDC
, hStockFont
);
2891 HGDIOBJ hObjOld
= ::SelectObject(pDC
->m_hDC
, hObject
);
2892 if(hObjOld
== hStockFont
)
2894 // got the stock object back, so must be selecting a font
2895 pDC
->SelectFont((HFONT
)hObject
);
2896 break; // don't play the default record
2900 // didn't get the stock object back, so restore everything
2901 ::SelectObject(pDC
->m_hDC
, hFontOld
);
2902 ::SelectObject(pDC
->m_hDC
, hObjOld
);
2904 // and fall through to PlayMetaFileRecord...
2906 else if(nObjType
== OBJ_FONT
)
2908 // play back as CDCHandle::SelectFont(HFONT)
2909 pDC
->SelectFont((HFONT
)hObject
);
2910 break; // don't play the default record
2916 ::PlayMetaFileRecord(hDC
, pHandleTable
, pMetaRec
, nHandles
);
2922 #endif // !_WIN32_WCE
2928 ATLASSERT(m_hDC
!= NULL
);
2929 return ::AbortPath(m_hDC
);
2934 ATLASSERT(m_hDC
!= NULL
);
2935 return ::BeginPath(m_hDC
);
2940 ATLASSERT(m_hDC
!= NULL
);
2941 return ::CloseFigure(m_hDC
);
2946 ATLASSERT(m_hDC
!= NULL
);
2947 return ::EndPath(m_hDC
);
2952 ATLASSERT(m_hDC
!= NULL
);
2953 return ::FillPath(m_hDC
);
2958 ATLASSERT(m_hDC
!= NULL
);
2959 return ::FlattenPath(m_hDC
);
2962 BOOL
StrokeAndFillPath()
2964 ATLASSERT(m_hDC
!= NULL
);
2965 return ::StrokeAndFillPath(m_hDC
);
2970 ATLASSERT(m_hDC
!= NULL
);
2971 return ::StrokePath(m_hDC
);
2976 ATLASSERT(m_hDC
!= NULL
);
2977 return ::WidenPath(m_hDC
);
2980 BOOL
GetMiterLimit(PFLOAT pfMiterLimit
) const
2982 ATLASSERT(m_hDC
!= NULL
);
2983 return ::GetMiterLimit(m_hDC
, pfMiterLimit
);
2986 BOOL
SetMiterLimit(float fMiterLimit
)
2988 ATLASSERT(m_hDC
!= NULL
);
2989 return ::SetMiterLimit(m_hDC
, fMiterLimit
, NULL
);
2992 int GetPath(LPPOINT lpPoints
, LPBYTE lpTypes
, int nCount
) const
2994 ATLASSERT(m_hDC
!= NULL
);
2995 return ::GetPath(m_hDC
, lpPoints
, lpTypes
, nCount
);
2998 BOOL
SelectClipPath(int nMode
)
3000 ATLASSERT(m_hDC
!= NULL
);
3001 return ::SelectClipPath(m_hDC
, nMode
);
3003 #endif // !_WIN32_WCE
3005 // Misc Helper Functions
3006 static CBrushHandle PASCAL
GetHalftoneBrush()
3008 HBRUSH halftoneBrush
= NULL
;
3009 WORD grayPattern
[8];
3010 for(int i
= 0; i
< 8; i
++)
3011 grayPattern
[i
] = (WORD
)(0x5555 << (i
& 1));
3012 HBITMAP grayBitmap
= CreateBitmap(8, 8, 1, 1, &grayPattern
);
3013 if(grayBitmap
!= NULL
)
3015 halftoneBrush
= ::CreatePatternBrush(grayBitmap
);
3016 DeleteObject(grayBitmap
);
3018 return CBrushHandle(halftoneBrush
);
3021 void DrawDragRect(LPCRECT lpRect
, SIZE size
, LPCRECT lpRectLast
, SIZE sizeLast
, HBRUSH hBrush
= NULL
, HBRUSH hBrushLast
= NULL
)
3023 // first, determine the update region and select it
3025 rgnOutside
.CreateRectRgnIndirect(lpRect
);
3026 RECT rect
= *lpRect
;
3027 ::InflateRect(&rect
, -size
.cx
, -size
.cy
);
3028 ::IntersectRect(&rect
, &rect
, lpRect
);
3030 rgnInside
.CreateRectRgnIndirect(&rect
);
3032 rgnNew
.CreateRectRgn(0, 0, 0, 0);
3033 rgnNew
.CombineRgn(rgnOutside
, rgnInside
, RGN_XOR
);
3035 HBRUSH hBrushOld
= NULL
;
3036 CBrush brushHalftone
;
3038 brushHalftone
= hBrush
= CDCHandle::GetHalftoneBrush();
3039 if(hBrushLast
== NULL
)
3040 hBrushLast
= hBrush
;
3044 if(lpRectLast
!= NULL
)
3046 // find difference between new region and old region
3047 rgnLast
.CreateRectRgn(0, 0, 0, 0);
3048 rgnOutside
.SetRectRgn(lpRectLast
->left
, lpRectLast
->top
, lpRectLast
->right
, lpRectLast
->bottom
);
3050 ::InflateRect(&rect
, -sizeLast
.cx
, -sizeLast
.cy
);
3051 ::IntersectRect(&rect
, &rect
, lpRectLast
);
3052 rgnInside
.SetRectRgn(rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3053 rgnLast
.CombineRgn(rgnOutside
, rgnInside
, RGN_XOR
);
3055 // only diff them if brushes are the same
3056 if(hBrush
== hBrushLast
)
3058 rgnUpdate
.CreateRectRgn(0, 0, 0, 0);
3059 rgnUpdate
.CombineRgn(rgnLast
, rgnNew
, RGN_XOR
);
3062 if(hBrush
!= hBrushLast
&& lpRectLast
!= NULL
)
3064 // brushes are different -- erase old region first
3065 SelectClipRgn(rgnLast
);
3067 hBrushOld
= SelectBrush(hBrushLast
);
3068 PatBlt(rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, PATINVERT
);
3069 SelectBrush(hBrushOld
);
3073 // draw into the update/new region
3074 SelectClipRgn(rgnUpdate
.IsNull() ? rgnNew
: rgnUpdate
);
3076 hBrushOld
= SelectBrush(hBrush
);
3077 PatBlt(rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, PATINVERT
);
3080 if(hBrushOld
!= NULL
)
3081 SelectBrush(hBrushOld
);
3082 SelectClipRgn(NULL
);
3085 void FillSolidRect(LPCRECT lpRect
, COLORREF clr
)
3087 ATLASSERT(m_hDC
!= NULL
);
3089 COLORREF clrOld
= ::SetBkColor(m_hDC
, clr
);
3090 ATLASSERT(clrOld
!= CLR_INVALID
);
3091 if(clrOld
!= CLR_INVALID
)
3093 ::ExtTextOut(m_hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
3094 ::SetBkColor(m_hDC
, clrOld
);
3098 void FillSolidRect(int x
, int y
, int cx
, int cy
, COLORREF clr
)
3100 ATLASSERT(m_hDC
!= NULL
);
3102 RECT rect
= { x
, y
, x
+ cx
, y
+ cy
};
3103 FillSolidRect(&rect
, clr
);
3106 void Draw3dRect(LPCRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
3108 Draw3dRect(lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
3109 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
3112 void Draw3dRect(int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
3114 FillSolidRect(x
, y
, cx
- 1, 1, clrTopLeft
);
3115 FillSolidRect(x
, y
, 1, cy
- 1, clrTopLeft
);
3116 FillSolidRect(x
+ cx
, y
, -1, cy
, clrBottomRight
);
3117 FillSolidRect(x
, y
+ cy
, cx
, -1, clrBottomRight
);
3121 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
3122 int SetDIBitsToDevice(int x
, int y
, DWORD dwWidth
, DWORD dwHeight
, int xSrc
, int ySrc
, UINT uStartScan
, UINT cScanLines
, CONST VOID
* lpvBits
, CONST BITMAPINFO
* lpbmi
, UINT uColorUse
)
3124 ATLASSERT(m_hDC
!= NULL
);
3125 return ::SetDIBitsToDevice(m_hDC
, x
, y
, dwWidth
, dwHeight
, xSrc
, ySrc
, uStartScan
, cScanLines
, lpvBits
, lpbmi
, uColorUse
);
3127 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
3129 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
3130 int StretchDIBits(int x
, int y
, int nWidth
, int nHeight
, int xSrc
, int ySrc
, int nSrcWidth
, int nSrcHeight
, CONST VOID
* lpvBits
, CONST BITMAPINFO
* lpbmi
, UINT uColorUse
, DWORD dwRop
)
3132 ATLASSERT(m_hDC
!= NULL
);
3133 return ::StretchDIBits(m_hDC
, x
, y
, nWidth
, nHeight
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, lpvBits
, lpbmi
, uColorUse
, dwRop
);
3136 UINT
GetDIBColorTable(UINT uStartIndex
, UINT cEntries
, RGBQUAD
* pColors
) const
3138 ATLASSERT(m_hDC
!= NULL
);
3139 return ::GetDIBColorTable(m_hDC
, uStartIndex
, cEntries
, pColors
);
3142 UINT
SetDIBColorTable(UINT uStartIndex
, UINT cEntries
, CONST RGBQUAD
* pColors
)
3144 ATLASSERT(m_hDC
!= NULL
);
3145 return ::SetDIBColorTable(m_hDC
, uStartIndex
, cEntries
, pColors
);
3147 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
3150 #if !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
3151 int ChoosePixelFormat(CONST PIXELFORMATDESCRIPTOR
* ppfd
)
3153 ATLASSERT(m_hDC
!= NULL
);
3154 return ::ChoosePixelFormat(m_hDC
, ppfd
);
3157 int DescribePixelFormat(int iPixelFormat
, UINT nBytes
, LPPIXELFORMATDESCRIPTOR ppfd
)
3159 ATLASSERT(m_hDC
!= NULL
);
3160 return ::DescribePixelFormat(m_hDC
, iPixelFormat
, nBytes
, ppfd
);
3163 int GetPixelFormat() const
3165 ATLASSERT(m_hDC
!= NULL
);
3166 return ::GetPixelFormat(m_hDC
);
3169 BOOL
SetPixelFormat(int iPixelFormat
, CONST PIXELFORMATDESCRIPTOR
* ppfd
)
3171 ATLASSERT(m_hDC
!= NULL
);
3172 return ::SetPixelFormat(m_hDC
, iPixelFormat
, ppfd
);
3177 ATLASSERT(m_hDC
!= NULL
);
3178 return ::SwapBuffers(m_hDC
);
3181 HGLRC
wglCreateContext()
3183 ATLASSERT(m_hDC
!= NULL
);
3184 return ::wglCreateContext(m_hDC
);
3187 HGLRC
wglCreateLayerContext(int iLayerPlane
)
3189 ATLASSERT(m_hDC
!= NULL
);
3190 return ::wglCreateLayerContext(m_hDC
, iLayerPlane
);
3193 BOOL
wglMakeCurrent(HGLRC hglrc
)
3195 ATLASSERT(m_hDC
!= NULL
);
3196 return ::wglMakeCurrent(m_hDC
, hglrc
);
3199 BOOL
wglUseFontBitmaps(DWORD dwFirst
, DWORD dwCount
, DWORD listBase
)
3201 ATLASSERT(m_hDC
!= NULL
);
3202 return ::wglUseFontBitmaps(m_hDC
, dwFirst
, dwCount
, listBase
);
3205 BOOL
wglUseFontOutlines(DWORD dwFirst
, DWORD dwCount
, DWORD listBase
, FLOAT deviation
, FLOAT extrusion
, int format
, LPGLYPHMETRICSFLOAT lpgmf
)
3207 ATLASSERT(m_hDC
!= NULL
);
3208 return ::wglUseFontOutlines(m_hDC
, dwFirst
, dwCount
, listBase
, deviation
, extrusion
, format
, lpgmf
);
3211 BOOL
wglDescribeLayerPlane(int iPixelFormat
, int iLayerPlane
, UINT nBytes
, LPLAYERPLANEDESCRIPTOR plpd
)
3213 ATLASSERT(m_hDC
!= NULL
);
3214 return ::wglDescribeLayerPlane(m_hDC
, iPixelFormat
, iLayerPlane
, nBytes
, plpd
);
3217 int wglSetLayerPaletteEntries(int iLayerPlane
, int iStart
, int cEntries
, CONST COLORREF
* pclr
)
3219 ATLASSERT(m_hDC
!= NULL
);
3220 return ::wglSetLayerPaletteEntries(m_hDC
, iLayerPlane
, iStart
, cEntries
, pclr
);
3223 int wglGetLayerPaletteEntries(int iLayerPlane
, int iStart
, int cEntries
, COLORREF
* pclr
)
3225 ATLASSERT(m_hDC
!= NULL
);
3226 return ::wglGetLayerPaletteEntries(m_hDC
, iLayerPlane
, iStart
, cEntries
, pclr
);
3229 BOOL
wglRealizeLayerPalette(int iLayerPlane
, BOOL bRealize
)
3231 ATLASSERT(m_hDC
!= NULL
);
3232 return ::wglRealizeLayerPalette(m_hDC
, iLayerPlane
, bRealize
);
3235 BOOL
wglSwapLayerBuffers(UINT uPlanes
)
3237 ATLASSERT(m_hDC
!= NULL
);
3238 return ::wglSwapLayerBuffers(m_hDC
, uPlanes
);
3240 #endif // !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
3242 // New for Windows 2000 only
3243 #if (_WIN32_WINNT >= 0x0500)
3244 COLORREF
GetDCPenColor() const
3246 ATLASSERT(m_hDC
!= NULL
);
3247 return ::GetDCPenColor(m_hDC
);
3250 COLORREF
SetDCPenColor(COLORREF clr
)
3252 ATLASSERT(m_hDC
!= NULL
);
3253 return ::SetDCPenColor(m_hDC
, clr
);
3256 COLORREF
GetDCBrushColor() const
3258 ATLASSERT(m_hDC
!= NULL
);
3259 return ::GetDCBrushColor(m_hDC
);
3262 COLORREF
SetDCBrushColor(COLORREF clr
)
3264 ATLASSERT(m_hDC
!= NULL
);
3265 return ::SetDCBrushColor(m_hDC
, clr
);
3269 DWORD
GetFontUnicodeRanges(LPGLYPHSET lpgs
) const
3271 ATLASSERT(m_hDC
!= NULL
);
3272 return ::GetFontUnicodeRanges(m_hDC
, lpgs
);
3274 #endif // !_WIN32_WCE
3276 DWORD
GetGlyphIndices(LPCTSTR lpstr
, int cch
, LPWORD pgi
, DWORD dwFlags
) const
3278 ATLASSERT(m_hDC
!= NULL
);
3279 return ::GetGlyphIndices(m_hDC
, lpstr
, cch
, pgi
, dwFlags
);
3282 BOOL
GetTextExtentPointI(LPWORD pgiIn
, int cgi
, LPSIZE lpSize
) const
3284 ATLASSERT(m_hDC
!= NULL
);
3285 return ::GetTextExtentPointI(m_hDC
, pgiIn
, cgi
, lpSize
);
3288 BOOL
GetTextExtentExPointI(LPWORD pgiIn
, int cgi
, int nMaxExtent
, LPINT lpnFit
, LPINT alpDx
, LPSIZE lpSize
) const
3290 ATLASSERT(m_hDC
!= NULL
);
3291 return ::GetTextExtentExPointI(m_hDC
, pgiIn
, cgi
, nMaxExtent
, lpnFit
, alpDx
, lpSize
);
3294 BOOL
GetCharWidthI(UINT giFirst
, UINT cgi
, LPWORD pgi
, LPINT lpBuffer
) const
3296 ATLASSERT(m_hDC
!= NULL
);
3297 return ::GetCharWidthI(m_hDC
, giFirst
, cgi
, pgi
, lpBuffer
);
3300 BOOL
GetCharABCWidthsI(UINT giFirst
, UINT cgi
, LPWORD pgi
, LPABC lpabc
) const
3302 ATLASSERT(m_hDC
!= NULL
);
3303 return ::GetCharABCWidthsI(m_hDC
, giFirst
, cgi
, pgi
, lpabc
);
3305 #endif // (_WIN32_WINNT >= 0x0500)
3307 // New for Windows 2000 and Windows 98
3308 #if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
3309 BOOL
ColorCorrectPalette(HPALETTE hPalette
, DWORD dwFirstEntry
, DWORD dwNumOfEntries
)
3311 ATLASSERT(m_hDC
!= NULL
);
3312 return ::ColorCorrectPalette(m_hDC
, hPalette
, dwFirstEntry
, dwNumOfEntries
);
3314 #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
3317 typedef CDCT
<false> CDCHandle
;
3318 typedef CDCT
<true> CDC
;
3321 ///////////////////////////////////////////////////////////////////////////////
3324 class CPaintDC
: public CDC
3331 // Constructor/destructor
3334 ATLASSERT(::IsWindow(hWnd
));
3336 m_hDC
= ::BeginPaint(hWnd
, &m_ps
);
3341 ATLASSERT(m_hDC
!= NULL
);
3342 ATLASSERT(::IsWindow(m_hWnd
));
3343 ::EndPaint(m_hWnd
, &m_ps
);
3348 class CClientDC
: public CDC
3354 // Constructor/destructor
3355 CClientDC(HWND hWnd
)
3357 ATLASSERT(hWnd
== NULL
|| ::IsWindow(hWnd
));
3359 m_hDC
= ::GetDC(hWnd
);
3364 ATLASSERT(m_hDC
!= NULL
);
3365 ::ReleaseDC(m_hWnd
, Detach());
3369 class CWindowDC
: public CDC
3375 // Constructor/destructor
3376 CWindowDC(HWND hWnd
)
3378 ATLASSERT(hWnd
== NULL
|| ::IsWindow(hWnd
));
3380 m_hDC
= ::GetWindowDC(hWnd
);
3385 ATLASSERT(m_hDC
!= NULL
);
3386 ::ReleaseDC(m_hWnd
, Detach());
3390 class CMemoryDC
: public CDC
3399 // Constructor/destructor
3400 CMemoryDC(HDC hDC
, RECT
& rcPaint
) : m_hDCOriginal(hDC
), m_hBmpOld(NULL
)
3402 m_rcPaint
= rcPaint
;
3403 CreateCompatibleDC(m_hDCOriginal
);
3404 ATLASSERT(m_hDC
!= NULL
);
3405 m_bmp
.CreateCompatibleBitmap(m_hDCOriginal
, m_rcPaint
.right
- m_rcPaint
.left
, m_rcPaint
.bottom
- m_rcPaint
.top
);
3406 ATLASSERT(m_bmp
.m_hBitmap
!= NULL
);
3407 m_hBmpOld
= SelectBitmap(m_bmp
);
3408 SetViewportOrg(-m_rcPaint
.left
, -m_rcPaint
.top
);
3413 ::BitBlt(m_hDCOriginal
, m_rcPaint
.left
, m_rcPaint
.top
, m_rcPaint
.right
- m_rcPaint
.left
, m_rcPaint
.bottom
- m_rcPaint
.top
, m_hDC
, m_rcPaint
.left
, m_rcPaint
.top
, SRCCOPY
);
3414 SelectBitmap(m_hBmpOld
);
3419 ///////////////////////////////////////////////////////////////////////////////
3420 // Enhanced metafile support
3424 class CEnhMetaFileInfo
3428 HENHMETAFILE m_hEMF
;
3431 ENHMETAHEADER m_header
;
3432 PIXELFORMATDESCRIPTOR m_pfd
;
3434 // Constructor/destructor
3435 CEnhMetaFileInfo(HENHMETAFILE hEMF
) : m_pBits(NULL
), m_pDesc(NULL
), m_hEMF(hEMF
)
3445 BYTE
* GetEnhMetaFileBits()
3447 ATLASSERT(m_hEMF
!= NULL
);
3448 UINT nBytes
= ::GetEnhMetaFileBits(m_hEMF
, 0, NULL
);
3451 ATLTRY(m_pBits
= new BYTE
[nBytes
]);
3452 if (m_pBits
!= NULL
)
3453 ::GetEnhMetaFileBits(m_hEMF
, nBytes
, m_pBits
);
3457 LPTSTR
GetEnhMetaFileDescription()
3459 ATLASSERT(m_hEMF
!= NULL
);
3460 UINT nLen
= ::GetEnhMetaFileDescription(m_hEMF
, 0, NULL
);
3463 ATLTRY(m_pDesc
= new TCHAR
[nLen
]);
3464 if (m_pDesc
!= NULL
)
3465 nLen
= ::GetEnhMetaFileDescription(m_hEMF
, nLen
, m_pDesc
);
3469 ENHMETAHEADER
* GetEnhMetaFileHeader()
3471 ATLASSERT(m_hEMF
!= NULL
);
3472 memset(&m_header
, 0, sizeof(m_header
));
3473 m_header
.iType
= EMR_HEADER
;
3474 m_header
.nSize
= sizeof(ENHMETAHEADER
);
3475 UINT n
= ::GetEnhMetaFileHeader(m_hEMF
, sizeof(ENHMETAHEADER
), &m_header
);
3476 return (n
!= 0) ? &m_header
: NULL
;
3479 PIXELFORMATDESCRIPTOR
* GetEnhMetaFilePixelFormat()
3481 ATLASSERT(m_hEMF
!= NULL
);
3482 memset(&m_pfd
, 0, sizeof(m_pfd
));
3483 UINT n
= ::GetEnhMetaFilePixelFormat(m_hEMF
, sizeof(m_pfd
), &m_pfd
);
3484 return (n
!= 0) ? &m_pfd
: NULL
;
3489 template <bool t_bManaged
>
3494 HENHMETAFILE m_hEMF
;
3496 // Constructor/destructor
3497 CEnhMetaFileT(HENHMETAFILE hEMF
= NULL
) : m_hEMF(hEMF
)
3503 if(t_bManaged
&& m_hEMF
!= NULL
)
3508 CEnhMetaFileT
<t_bManaged
>& operator =(HENHMETAFILE hEMF
)
3514 void Attach(HENHMETAFILE hEMF
)
3516 if(t_bManaged
&& m_hEMF
!= NULL
&& m_hEMF
!= hEMF
)
3521 HENHMETAFILE
Detach()
3523 HENHMETAFILE hEMF
= m_hEMF
;
3528 operator HENHMETAFILE() const { return m_hEMF
; }
3530 bool IsNull() const { return (m_hEMF
== NULL
); }
3534 ATLASSERT(m_hEMF
!= NULL
);
3535 BOOL bRet
= ::DeleteEnhMetaFile(m_hEMF
);
3540 UINT
GetEnhMetaFileBits(UINT cbBuffer
, LPBYTE lpbBuffer
) const
3542 ATLASSERT(m_hEMF
!= NULL
);
3543 return ::GetEnhMetaFileBits(m_hEMF
, cbBuffer
, lpbBuffer
);
3546 UINT
GetEnhMetaFileDescription(UINT cchBuffer
, LPTSTR lpszDescription
) const
3548 ATLASSERT(m_hEMF
!= NULL
);
3549 return ::GetEnhMetaFileDescription(m_hEMF
, cchBuffer
, lpszDescription
);
3552 UINT
GetEnhMetaFileHeader(LPENHMETAHEADER lpemh
) const
3554 ATLASSERT(m_hEMF
!= NULL
);
3555 lpemh
->iType
= EMR_HEADER
;
3556 lpemh
->nSize
= sizeof(ENHMETAHEADER
);
3557 return ::GetEnhMetaFileHeader(m_hEMF
, sizeof(ENHMETAHEADER
), lpemh
);
3560 UINT
GetEnhMetaFilePaletteEntries(UINT cEntries
, LPPALETTEENTRY lppe
) const
3562 ATLASSERT(m_hEMF
!= NULL
);
3563 return ::GetEnhMetaFilePaletteEntries(m_hEMF
, cEntries
, lppe
);
3566 UINT
GetEnhMetaFilePixelFormat(DWORD cbBuffer
, PIXELFORMATDESCRIPTOR
* ppfd
) const
3568 ATLASSERT(m_hEMF
!= NULL
);
3569 return ::GetEnhMetaFilePixelFormat(m_hEMF
, cbBuffer
, ppfd
);
3573 typedef CEnhMetaFileT
<false> CEnhMetaFileHandle
;
3574 typedef CEnhMetaFileT
<true> CEnhMetaFile
;
3577 class CEnhMetaFileDC
: public CDC
3580 // Constructor/destructor
3585 CEnhMetaFileDC(HDC hdc
, LPCRECT lpRect
)
3587 Create(hdc
, NULL
, lpRect
, NULL
);
3588 ATLASSERT(m_hDC
!= NULL
);
3591 CEnhMetaFileDC(HDC hdcRef
, LPCTSTR lpFilename
, LPCRECT lpRect
, LPCTSTR lpDescription
)
3593 Create(hdcRef
, lpFilename
, lpRect
, lpDescription
);
3594 ATLASSERT(m_hDC
!= NULL
);
3599 HENHMETAFILE hEMF
= Close();
3601 ::DeleteEnhMetaFile(hEMF
);
3605 void Create(HDC hdcRef
, LPCTSTR lpFilename
, LPCRECT lpRect
, LPCTSTR lpDescription
)
3607 ATLASSERT(m_hDC
== NULL
);
3608 m_hDC
= ::CreateEnhMetaFile(hdcRef
, lpFilename
, lpRect
, lpDescription
);
3611 HENHMETAFILE
Close()
3613 HENHMETAFILE hEMF
= NULL
;
3616 hEMF
= ::CloseEnhMetaFile(m_hDC
);
3623 #endif // !_WIN32_WCE
3626 ///////////////////////////////////////////////////////////////////////////////
3627 // WinCE compatible clipboard CF_DIB format support functions
3629 #ifndef _WTL_NO_DIB16
3631 #define DIBINFO16_BITFIELDS { 31744, 992, 31 }
3633 // DIBINFO16 - To avoid color table problems in WinCE we only create this type of Dib
3634 struct DIBINFO16
// a BITMAPINFO with 2 additional color bitfields
3636 BITMAPINFOHEADER bmiHeader
;
3637 RGBQUAD bmiColors
[3];
3639 DIBINFO16(SIZE size
)
3641 BITMAPINFOHEADER bmih
= { sizeof(BITMAPINFOHEADER
), size
.cx
, size
.cy
,
3642 1, 16, BI_BITFIELDS
, 2 * size
.cx
* size
.cy
, 0, 0, 3 };
3643 DWORD dw
[3] = DIBINFO16_BITFIELDS
;
3646 memcpy(bmiColors
, dw
, 3 * sizeof(DWORD
));
3651 // AtlxxxDibxxx minimal packed DIB implementation and helpers to copy and paste CF_DIB
3653 inline bool AtlIsDib16(LPBITMAPINFOHEADER pbmih
)
3655 return (pbmih
->biBitCount
== 16) && (pbmih
->biCompression
== BI_BITFIELDS
);
3658 inline int AtlGetDibColorTableSize(LPBITMAPINFOHEADER pbmih
)
3660 switch (pbmih
->biBitCount
)
3665 return pbmih
->biClrUsed
? pbmih
->biClrUsed
: 1 << pbmih
->biBitCount
;
3670 return pbmih
->biCompression
== BI_BITFIELDS
? 3 : 0;
3672 ATLASSERT(FALSE
); // should never come here
3678 inline int AtlGetDibNumColors(LPBITMAPINFOHEADER pbmih
)
3680 switch (pbmih
->biBitCount
)
3685 if (pbmih
->biClrUsed
)
3686 return pbmih
->biClrUsed
;
3690 if (pbmih
->biCompression
== BI_BITFIELDS
)
3697 if (pbmih
->biCompression
== BI_BITFIELDS
)
3705 return 1 << pbmih
->biBitCount
;
3708 inline HBITMAP
AtlGetDibBitmap(LPBITMAPINFO pbmi
)
3712 void * pBits
= NULL
;
3714 LPBYTE pDibBits
= (LPBYTE
)pbmi
+ sizeof(BITMAPINFOHEADER
) + AtlGetDibColorTableSize(&pbmi
->bmiHeader
) * sizeof(RGBQUAD
);
3715 if (hbm
= CreateDIBSection(dc
, pbmi
, DIB_RGB_COLORS
, &pBits
, NULL
, NULL
))
3716 memcpy(pBits
, pDibBits
, pbmi
->bmiHeader
.biSizeImage
);
3721 inline HBITMAP
AtlCopyBitmap(HBITMAP hbm
, SIZE sizeDst
, bool bAsBitmap
= false)
3723 CDC hdcSrc
= CreateCompatibleDC(NULL
);
3724 CDC hdcDst
= CreateCompatibleDC(NULL
);
3726 CBitmapHandle hbmOld
= NULL
, hbmOld2
= NULL
, bmSrc
= hbm
;
3728 CBitmap bmNew
= NULL
;
3730 SIZE sizeSrc
= { 0 };
3731 bmSrc
.GetSize(sizeSrc
);
3733 hbmOld
= hdcSrc
.SelectBitmap(bmSrc
);
3737 bmNew
.CreateCompatibleBitmap(hdcSrc
, sizeDst
.cx
, sizeDst
.cy
);
3741 DIBINFO16
dib16(sizeDst
);
3742 LPVOID pBits
= NULL
;
3743 bmNew
= CreateDIBSection(hdcDst
, (const BITMAPINFO
*)&dib16
, DIB_RGB_COLORS
, &pBits
, NULL
, NULL
);
3746 ATLASSERT(!bmNew
.IsNull());
3748 hbmOld2
= hdcDst
.SelectBitmap(bmNew
);
3751 if ((sizeDst
.cx
== sizeSrc
.cx
) && (sizeDst
.cy
== sizeSrc
.cy
))
3752 bOK
= hdcDst
.BitBlt(0, 0, sizeDst
.cx
, sizeDst
.cy
, hdcSrc
, 0, 0, SRCCOPY
);
3754 bOK
= hdcDst
.StretchBlt(0, 0, sizeDst
.cx
, sizeDst
.cy
, hdcSrc
, 0, 0, sizeSrc
.cx
, sizeSrc
.cy
, SRCCOPY
);
3756 hdcSrc
.SelectBitmap(hbmOld
);
3757 hdcDst
.SelectBitmap(hbmOld2
);
3760 bmNew
.DeleteObject();
3762 return bmNew
.Detach();
3765 inline HLOCAL
AtlCreatePackedDib16(HBITMAP hbm
, SIZE size
)
3767 DIBSECTION ds
= { 0 };
3769 bool bCopied
= false;
3771 bool bOK
= GetObject(hbm
, sizeof(ds
), &ds
) == sizeof(ds
);
3772 if ((bOK
== FALSE
) || (ds
.dsBm
.bmBits
== NULL
) || (AtlIsDib16(&ds
.dsBmih
) == FALSE
) ||
3773 (ds
.dsBmih
.biWidth
!= size
.cx
) || (ds
.dsBmih
.biHeight
!= size
.cy
))
3775 if ((hbm
= AtlCopyBitmap(hbm
, size
)) != NULL
)
3778 bOK
= GetObject(hbm
, sizeof(ds
), &ds
) == sizeof(ds
);
3786 if((bOK
== TRUE
) && (AtlIsDib16(&ds
.dsBmih
) == TRUE
) && (ds
.dsBm
.bmBits
!= NULL
))
3788 pDib
= (LPBYTE
)LocalAlloc(LMEM_ZEROINIT
, sizeof(DIBINFO16
) + ds
.dsBmih
.biSizeImage
);
3791 memcpy(pDib
, &ds
.dsBmih
, sizeof(DIBINFO16
));
3792 memcpy(pDib
+ sizeof(DIBINFO16
), ds
.dsBm
.bmBits
, ds
.dsBmih
.biSizeImage
);
3796 if (bCopied
== true)
3799 return (HLOCAL
)pDib
;
3802 inline bool AtlSetClipboardDib16(HBITMAP hbm
, SIZE size
, HWND hWnd
)
3804 ATLASSERT(::IsWindow(hWnd
));
3805 BOOL bOK
= OpenClipboard(hWnd
);
3808 if ((bOK
= EmptyClipboard()) == TRUE
)
3810 HLOCAL hDib
= AtlCreatePackedDib16(hbm
, size
);
3813 bOK
= SetClipboardData(CF_DIB
, hDib
) != NULL
;
3828 inline HBITMAP
AtlGetClipboardDib(HWND hWnd
)
3830 ATLASSERT(::IsWindow(hWnd
) == TRUE
);
3832 if (OpenClipboard(hWnd
) == TRUE
)
3834 LPBITMAPINFO pbmi
= (LPBITMAPINFO
)GetClipboardData(CF_DIB
);
3836 hbm
= AtlGetDibBitmap(pbmi
);
3843 #endif // _WTL_NO_DIB16
3847 #endif // __ATLGDI_H__