1 // Windows Template Library - WTL version 9.0
2 // Copyright (C) Microsoft Corporation, WTL Team. 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 // Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
7 // which can be found in the file CPL.TXT at the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by
9 // the terms of this license. You must not remove this notice, or
10 // any other, from this software.
18 #error atlgdi.h requires atlapp.h to be included first
22 // protect template members from windowsx.h macros
31 #endif // _INC_WINDOWSX
34 #if !defined(_ATL_NO_MSIMG) && !defined(_WIN32_WCE)
35 #pragma comment(lib, "msimg32.lib")
37 #if !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
38 #pragma comment(lib, "opengl32.lib")
42 ///////////////////////////////////////////////////////////////////////////////
43 // Classes in this file:
46 // CBrushT<t_bManaged>
49 // CBitmapT<t_bManaged>
50 // CPaletteT<t_bManaged>
58 // CEnhMetaFileT<t_bManaged>
62 // AtlGetBitmapResourceInfo()
63 // AtlGetBitmapResourceBitsPerPixel()
64 // AtlIsAlphaBitmapResource()
66 // AtlGetDibColorTableSize()
67 // AtlGetDibNumColors(),
70 // AtlCreatePackedDib16()
71 // AtlSetClipboardDib16()
72 // AtlGetClipboardDib()
78 ///////////////////////////////////////////////////////////////////////////////
79 // Bitmap resource helpers to extract bitmap information for a bitmap resource
81 inline LPBITMAPINFOHEADER
AtlGetBitmapResourceInfo(HMODULE hModule
, ATL::_U_STRINGorID image
)
83 HRSRC hResource
= ::FindResource(hModule
, image
.m_lpstr
, RT_BITMAP
);
84 ATLASSERT(hResource
!= NULL
);
85 HGLOBAL hGlobal
= ::LoadResource(hModule
, hResource
);
86 ATLASSERT(hGlobal
!= NULL
);
87 LPBITMAPINFOHEADER pBitmapInfoHeader
= (LPBITMAPINFOHEADER
)::LockResource(hGlobal
);
88 ATLASSERT(pBitmapInfoHeader
!= NULL
);
89 return pBitmapInfoHeader
;
92 inline WORD
AtlGetBitmapResourceBitsPerPixel(HMODULE hModule
, ATL::_U_STRINGorID image
)
94 LPBITMAPINFOHEADER pBitmapInfoHeader
= AtlGetBitmapResourceInfo(hModule
, image
);
95 ATLASSERT(pBitmapInfoHeader
!= NULL
);
96 return pBitmapInfoHeader
->biBitCount
;
99 inline WORD
AtlGetBitmapResourceBitsPerPixel(ATL::_U_STRINGorID image
)
101 return AtlGetBitmapResourceBitsPerPixel(ModuleHelper::GetResourceInstance(), image
);
104 ///////////////////////////////////////////////////////////////////////////////
105 // 32-bit (alpha channel) bitmap resource helper
107 // Note: 32-bit (alpha channel) images work only on Windows XP with Common Controls version 6.
108 // If you want your app to work on older version of Windows, load non-alpha images if Common
109 // Controls version is less than 6.
111 inline bool AtlIsAlphaBitmapResource(ATL::_U_STRINGorID image
)
113 return (AtlGetBitmapResourceBitsPerPixel(image
) == 32);
117 ///////////////////////////////////////////////////////////////////////////////
120 template <bool t_bManaged
>
127 // Constructor/destructor/operators
128 CPenT(HPEN hPen
= NULL
) : m_hPen(hPen
)
133 if(t_bManaged
&& m_hPen
!= NULL
)
137 CPenT
<t_bManaged
>& operator =(HPEN hPen
)
143 void Attach(HPEN hPen
)
145 if(t_bManaged
&& m_hPen
!= NULL
&& m_hPen
!= hPen
)
146 ::DeleteObject(m_hPen
);
157 operator HPEN() const { return m_hPen
; }
159 bool IsNull() const { return (m_hPen
== NULL
); }
162 HPEN
CreatePen(int nPenStyle
, int nWidth
, COLORREF crColor
)
164 ATLASSERT(m_hPen
== NULL
);
165 m_hPen
= ::CreatePen(nPenStyle
, nWidth
, crColor
);
170 HPEN
CreatePen(int nPenStyle
, int nWidth
, const LOGBRUSH
* pLogBrush
, int nStyleCount
= 0, const DWORD
* lpStyle
= NULL
)
172 ATLASSERT(m_hPen
== NULL
);
173 m_hPen
= ::ExtCreatePen(nPenStyle
, nWidth
, pLogBrush
, nStyleCount
, lpStyle
);
176 #endif // !_WIN32_WCE
178 HPEN
CreatePenIndirect(LPLOGPEN lpLogPen
)
180 ATLASSERT(m_hPen
== NULL
);
181 m_hPen
= ::CreatePenIndirect(lpLogPen
);
187 ATLASSERT(m_hPen
!= NULL
);
188 BOOL bRet
= ::DeleteObject(m_hPen
);
195 int GetLogPen(LOGPEN
* pLogPen
) const
197 ATLASSERT(m_hPen
!= NULL
);
198 return ::GetObject(m_hPen
, sizeof(LOGPEN
), pLogPen
);
201 bool GetLogPen(LOGPEN
& LogPen
) const
203 ATLASSERT(m_hPen
!= NULL
);
204 return (::GetObject(m_hPen
, sizeof(LOGPEN
), &LogPen
) == sizeof(LOGPEN
));
208 int GetExtLogPen(EXTLOGPEN
* pLogPen
, int nSize
= sizeof(EXTLOGPEN
)) const
210 ATLASSERT(m_hPen
!= NULL
);
211 return ::GetObject(m_hPen
, nSize
, pLogPen
);
214 bool GetExtLogPen(EXTLOGPEN
& ExtLogPen
, int nSize
= sizeof(EXTLOGPEN
)) const
216 ATLASSERT(m_hPen
!= NULL
);
217 int nRet
= ::GetObject(m_hPen
, nSize
, &ExtLogPen
);
218 return ((nRet
> 0) && (nRet
<= nSize
));
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 HDC hDC1
= (hDC
!= NULL
) ? hDC
: ::GetDC(NULL
);
412 // For MM_TEXT mapping mode
413 lfHeight
= -::MulDiv(nPointSize
, ::GetDeviceCaps(hDC1
, LOGPIXELSY
), 72);
415 ::ReleaseDC(NULL
, hDC1
);
418 LONG
GetHeight(HDC hDC
= NULL
) const
420 HDC hDC1
= (hDC
!= NULL
) ? hDC
: ::GetDC(NULL
);
421 // For MM_TEXT mapping mode
422 LONG nPointSize
= ::MulDiv(-lfHeight
, 72, ::GetDeviceCaps(hDC1
, LOGPIXELSY
));
424 ::ReleaseDC(NULL
, hDC1
);
429 LONG
GetDeciPointHeight(HDC hDC
= NULL
) const
431 HDC hDC1
= (hDC
!= NULL
) ? hDC
: ::GetDC(NULL
);
433 POINT ptOrg
= { 0, 0 };
434 ::DPtoLP(hDC1
, &ptOrg
, 1);
436 pt
.y
= abs(lfHeight
) + ptOrg
.y
;
437 ::LPtoDP(hDC1
, &pt
,1);
438 LONG nDeciPoint
= ::MulDiv(pt
.y
, 720, ::GetDeviceCaps(hDC1
, LOGPIXELSY
)); // 72 points/inch, 10 decipoints/point
440 // DP and LP are always the same on CE
441 LONG nDeciPoint
= ::MulDiv(abs(lfHeight
), 720, ::GetDeviceCaps(hDC1
, LOGPIXELSY
)); // 72 points/inch, 10 decipoints/point
444 ::ReleaseDC(NULL
, hDC1
);
449 void SetHeightFromDeciPoint(LONG nDeciPtHeight
, HDC hDC
= NULL
)
451 HDC hDC1
= (hDC
!= NULL
) ? hDC
: ::GetDC(NULL
);
454 pt
.y
= ::MulDiv(::GetDeviceCaps(hDC1
, LOGPIXELSY
), nDeciPtHeight
, 720); // 72 points/inch, 10 decipoints/point
455 ::DPtoLP(hDC1
, &pt
, 1);
456 POINT ptOrg
= { 0, 0 };
457 ::DPtoLP(hDC1
, &ptOrg
, 1);
458 lfHeight
= -abs(pt
.y
- ptOrg
.y
);
460 // DP and LP are always the same on CE
461 lfHeight
= -abs(::MulDiv(::GetDeviceCaps(hDC1
, LOGPIXELSY
), nDeciPtHeight
, 720)); // 72 points/inch, 10 decipoints/point
464 ::ReleaseDC(NULL
, hDC1
);
468 void SetCaptionFont()
470 NONCLIENTMETRICS ncm
= { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
471 ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0));
472 Copy(&ncm
.lfCaptionFont
);
477 NONCLIENTMETRICS ncm
= { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
478 ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0));
479 Copy(&ncm
.lfMenuFont
);
484 NONCLIENTMETRICS ncm
= { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
485 ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0));
486 Copy(&ncm
.lfStatusFont
);
489 void SetMessageBoxFont()
491 NONCLIENTMETRICS ncm
= { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
492 ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0));
493 Copy(&ncm
.lfMessageFont
);
495 #endif // !_WIN32_WCE
497 void Copy(const LOGFONT
* pLogFont
)
499 ATLASSERT(pLogFont
!= NULL
);
500 *(LOGFONT
*)this = *pLogFont
;
503 CLogFont
& operator =(const CLogFont
& src
)
509 CLogFont
& operator =(const LOGFONT
& src
)
515 CLogFont
& operator =(HFONT hFont
)
517 ATLASSERT(::GetObjectType(hFont
) == OBJ_FONT
);
518 ::GetObject(hFont
, sizeof(LOGFONT
), (LOGFONT
*)this);
522 bool operator ==(const LOGFONT
& logfont
) const
524 return(logfont
.lfHeight
== lfHeight
&&
525 logfont
.lfWidth
== lfWidth
&&
526 logfont
.lfEscapement
== lfEscapement
&&
527 logfont
.lfOrientation
== lfOrientation
&&
528 logfont
.lfWeight
== lfWeight
&&
529 logfont
.lfItalic
== lfItalic
&&
530 logfont
.lfUnderline
== lfUnderline
&&
531 logfont
.lfStrikeOut
== lfStrikeOut
&&
532 logfont
.lfCharSet
== lfCharSet
&&
533 logfont
.lfOutPrecision
== lfOutPrecision
&&
534 logfont
.lfClipPrecision
== lfClipPrecision
&&
535 logfont
.lfQuality
== lfQuality
&&
536 logfont
.lfPitchAndFamily
== lfPitchAndFamily
&&
537 lstrcmp(logfont
.lfFaceName
, lfFaceName
) == 0);
542 template <bool t_bManaged
>
549 // Constructor/destructor/operators
550 CFontT(HFONT hFont
= NULL
) : m_hFont(hFont
)
555 if(t_bManaged
&& m_hFont
!= NULL
)
559 CFontT
<t_bManaged
>& operator =(HFONT hFont
)
565 void Attach(HFONT hFont
)
567 if(t_bManaged
&& m_hFont
!= NULL
&& m_hFont
!= hFont
)
568 ::DeleteObject(m_hFont
);
574 HFONT hFont
= m_hFont
;
579 operator HFONT() const { return m_hFont
; }
581 bool IsNull() const { return (m_hFont
== NULL
); }
584 HFONT
CreateFontIndirect(const LOGFONT
* lpLogFont
)
586 ATLASSERT(m_hFont
== NULL
);
587 m_hFont
= ::CreateFontIndirect(lpLogFont
);
591 #if !defined(_WIN32_WCE) && (_WIN32_WINNT >= 0x0500)
592 HFONT
CreateFontIndirectEx(CONST ENUMLOGFONTEXDV
* penumlfex
)
594 ATLASSERT(m_hFont
== NULL
);
595 m_hFont
= ::CreateFontIndirectEx(penumlfex
);
598 #endif // !defined(_WIN32_WCE) && (_WIN32_WINNT >= 0x0500)
600 #if !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
601 HFONT
CreateFont(int nHeight
, int nWidth
, int nEscapement
,
602 int nOrientation
, int nWeight
, BYTE bItalic
, BYTE bUnderline
,
603 BYTE cStrikeOut
, BYTE nCharSet
, BYTE nOutPrecision
,
604 BYTE nClipPrecision
, BYTE nQuality
, BYTE nPitchAndFamily
,
605 LPCTSTR lpszFacename
)
607 ATLASSERT(m_hFont
== NULL
);
609 m_hFont
= ::CreateFont(nHeight
, nWidth
, nEscapement
,
610 nOrientation
, nWeight
, bItalic
, bUnderline
, cStrikeOut
,
611 nCharSet
, nOutPrecision
, nClipPrecision
, nQuality
,
612 nPitchAndFamily
, lpszFacename
);
614 m_hFont
= ATL::CreateFont(nHeight
, nWidth
, nEscapement
,
615 nOrientation
, nWeight
, bItalic
, bUnderline
, cStrikeOut
,
616 nCharSet
, nOutPrecision
, nClipPrecision
, nQuality
,
617 nPitchAndFamily
, lpszFacename
);
621 #endif // !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
623 HFONT
CreatePointFont(int nPointSize
, LPCTSTR lpszFaceName
, HDC hDC
= NULL
, bool bBold
= false, bool bItalic
= false)
625 LOGFONT logFont
= { 0 };
626 logFont
.lfCharSet
= DEFAULT_CHARSET
;
627 logFont
.lfHeight
= nPointSize
;
628 SecureHelper::strncpy_x(logFont
.lfFaceName
, _countof(logFont
.lfFaceName
), lpszFaceName
, _TRUNCATE
);
631 logFont
.lfWeight
= FW_BOLD
;
633 logFont
.lfItalic
= (BYTE
)TRUE
;
635 return CreatePointFontIndirect(&logFont
, hDC
);
638 HFONT
CreatePointFontIndirect(const LOGFONT
* lpLogFont
, HDC hDC
= NULL
)
640 HDC hDC1
= (hDC
!= NULL
) ? hDC
: ::GetDC(NULL
);
642 // convert nPointSize to logical units based on hDC
643 LOGFONT logFont
= *lpLogFont
;
646 pt
.y
= ::MulDiv(::GetDeviceCaps(hDC1
, LOGPIXELSY
), logFont
.lfHeight
, 720); // 72 points/inch, 10 decipoints/point
647 ::DPtoLP(hDC1
, &pt
, 1);
648 POINT ptOrg
= { 0, 0 };
649 ::DPtoLP(hDC1
, &ptOrg
, 1);
650 logFont
.lfHeight
= -abs(pt
.y
- ptOrg
.y
);
652 // DP and LP are always the same on CE
653 logFont
.lfHeight
= -abs(::MulDiv(::GetDeviceCaps(hDC1
, LOGPIXELSY
), logFont
.lfHeight
, 720)); // 72 points/inch, 10 decipoints/point
657 ::ReleaseDC(NULL
, hDC1
);
659 return CreateFontIndirect(&logFont
);
664 ATLASSERT(m_hFont
!= NULL
);
665 BOOL bRet
= ::DeleteObject(m_hFont
);
672 int GetLogFont(LOGFONT
* pLogFont
) const
674 ATLASSERT(m_hFont
!= NULL
);
675 return ::GetObject(m_hFont
, sizeof(LOGFONT
), pLogFont
);
678 bool GetLogFont(LOGFONT
& LogFont
) const
680 ATLASSERT(m_hFont
!= NULL
);
681 return (::GetObject(m_hFont
, sizeof(LOGFONT
), &LogFont
) == sizeof(LOGFONT
));
685 typedef CFontT
<false> CFontHandle
;
686 typedef CFontT
<true> CFont
;
689 ///////////////////////////////////////////////////////////////////////////////
692 template <bool t_bManaged
>
699 // Constructor/destructor/operators
700 CBitmapT(HBITMAP hBitmap
= NULL
) : m_hBitmap(hBitmap
)
705 if(t_bManaged
&& m_hBitmap
!= NULL
)
709 CBitmapT
<t_bManaged
>& operator =(HBITMAP hBitmap
)
715 void Attach(HBITMAP hBitmap
)
717 if(t_bManaged
&& m_hBitmap
!= NULL
&& m_hBitmap
!= hBitmap
)
718 ::DeleteObject(m_hBitmap
);
724 HBITMAP hBitmap
= m_hBitmap
;
729 operator HBITMAP() const { return m_hBitmap
; }
731 bool IsNull() const { return (m_hBitmap
== NULL
); }
733 // Create and load methods
734 HBITMAP
LoadBitmap(ATL::_U_STRINGorID bitmap
)
736 ATLASSERT(m_hBitmap
== NULL
);
737 m_hBitmap
= ::LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap
.m_lpstr
);
741 HBITMAP
LoadOEMBitmap(UINT nIDBitmap
) // for OBM_/OCR_/OIC_
743 ATLASSERT(m_hBitmap
== NULL
);
744 m_hBitmap
= ::LoadBitmap(NULL
, MAKEINTRESOURCE(nIDBitmap
));
749 HBITMAP
LoadMappedBitmap(UINT nIDBitmap
, UINT nFlags
= 0, LPCOLORMAP lpColorMap
= NULL
, int nMapSize
= 0)
751 ATLASSERT(m_hBitmap
== NULL
);
752 m_hBitmap
= ::CreateMappedBitmap(ModuleHelper::GetResourceInstance(), nIDBitmap
, (WORD
)nFlags
, lpColorMap
, nMapSize
);
755 #endif // !_WIN32_WCE
757 HBITMAP
CreateBitmap(int nWidth
, int nHeight
, UINT nPlanes
, UINT nBitsPerPixel
, const void* lpBits
)
759 ATLASSERT(m_hBitmap
== NULL
);
760 m_hBitmap
= ::CreateBitmap(nWidth
, nHeight
, nPlanes
, nBitsPerPixel
, lpBits
);
765 HBITMAP
CreateBitmapIndirect(LPBITMAP lpBitmap
)
767 ATLASSERT(m_hBitmap
== NULL
);
768 m_hBitmap
= ::CreateBitmapIndirect(lpBitmap
);
771 #endif // !_WIN32_WCE
773 HBITMAP
CreateCompatibleBitmap(HDC hDC
, int nWidth
, int nHeight
)
775 ATLASSERT(m_hBitmap
== NULL
);
776 m_hBitmap
= ::CreateCompatibleBitmap(hDC
, nWidth
, nHeight
);
781 HBITMAP
CreateDiscardableBitmap(HDC hDC
, int nWidth
, int nHeight
)
783 ATLASSERT(m_hBitmap
== NULL
);
784 m_hBitmap
= ::CreateDiscardableBitmap(hDC
, nWidth
, nHeight
);
787 #endif // !_WIN32_WCE
791 ATLASSERT(m_hBitmap
!= NULL
);
792 BOOL bRet
= ::DeleteObject(m_hBitmap
);
799 int GetBitmap(BITMAP
* pBitMap
) const
801 ATLASSERT(m_hBitmap
!= NULL
);
802 return ::GetObject(m_hBitmap
, sizeof(BITMAP
), pBitMap
);
805 bool GetBitmap(BITMAP
& bm
) const
807 ATLASSERT(m_hBitmap
!= NULL
);
808 return (::GetObject(m_hBitmap
, sizeof(BITMAP
), &bm
) == sizeof(BITMAP
));
811 bool GetSize(SIZE
& size
) const
813 ATLASSERT(m_hBitmap
!= NULL
);
817 size
.cx
= bm
.bmWidth
;
818 size
.cy
= bm
.bmHeight
;
823 DWORD
GetBitmapBits(DWORD dwCount
, LPVOID lpBits
) const
825 ATLASSERT(m_hBitmap
!= NULL
);
826 return ::GetBitmapBits(m_hBitmap
, dwCount
, lpBits
);
828 #endif // !_WIN32_WCE
830 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
831 DWORD
SetBitmapBits(DWORD dwCount
, const void* lpBits
)
833 ATLASSERT(m_hBitmap
!= NULL
);
834 return ::SetBitmapBits(m_hBitmap
, dwCount
, lpBits
);
836 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
839 BOOL
GetBitmapDimension(LPSIZE lpSize
) const
841 ATLASSERT(m_hBitmap
!= NULL
);
842 return ::GetBitmapDimensionEx(m_hBitmap
, lpSize
);
845 BOOL
SetBitmapDimension(int nWidth
, int nHeight
, LPSIZE lpSize
= NULL
)
847 ATLASSERT(m_hBitmap
!= NULL
);
848 return ::SetBitmapDimensionEx(m_hBitmap
, nWidth
, nHeight
, lpSize
);
852 HBITMAP
CreateDIBitmap(HDC hDC
, CONST BITMAPINFOHEADER
* lpbmih
, DWORD dwInit
, CONST VOID
* lpbInit
, CONST BITMAPINFO
* lpbmi
, UINT uColorUse
)
854 ATLASSERT(m_hBitmap
== NULL
);
855 m_hBitmap
= ::CreateDIBitmap(hDC
, lpbmih
, dwInit
, lpbInit
, lpbmi
, uColorUse
);
858 #endif // !_WIN32_WCE
860 HBITMAP
CreateDIBSection(HDC hDC
, CONST BITMAPINFO
* lpbmi
, UINT uColorUse
, VOID
** ppvBits
, HANDLE hSection
, DWORD dwOffset
)
862 ATLASSERT(m_hBitmap
== NULL
);
863 m_hBitmap
= ::CreateDIBSection(hDC
, lpbmi
, uColorUse
, ppvBits
, hSection
, dwOffset
);
868 int GetDIBits(HDC hDC
, UINT uStartScan
, UINT cScanLines
, LPVOID lpvBits
, LPBITMAPINFO lpbmi
, UINT uColorUse
) const
870 ATLASSERT(m_hBitmap
!= NULL
);
871 return ::GetDIBits(hDC
, m_hBitmap
, uStartScan
, cScanLines
, lpvBits
, lpbmi
, uColorUse
);
874 int SetDIBits(HDC hDC
, UINT uStartScan
, UINT cScanLines
, CONST VOID
* lpvBits
, CONST BITMAPINFO
* lpbmi
, UINT uColorUse
)
876 ATLASSERT(m_hBitmap
!= NULL
);
877 return ::SetDIBits(hDC
, m_hBitmap
, uStartScan
, cScanLines
, lpvBits
, lpbmi
, uColorUse
);
879 #endif // !_WIN32_WCE
882 typedef CBitmapT
<false> CBitmapHandle
;
883 typedef CBitmapT
<true> CBitmap
;
886 ///////////////////////////////////////////////////////////////////////////////
889 template <bool t_bManaged
>
896 // Constructor/destructor/operators
897 CPaletteT(HPALETTE hPalette
= NULL
) : m_hPalette(hPalette
)
902 if(t_bManaged
&& m_hPalette
!= NULL
)
906 CPaletteT
<t_bManaged
>& operator =(HPALETTE hPalette
)
912 void Attach(HPALETTE hPalette
)
914 if(t_bManaged
&& m_hPalette
!= NULL
&& m_hPalette
!= hPalette
)
915 ::DeleteObject(m_hPalette
);
916 m_hPalette
= hPalette
;
921 HPALETTE hPalette
= m_hPalette
;
926 operator HPALETTE() const { return m_hPalette
; }
928 bool IsNull() const { return (m_hPalette
== NULL
); }
931 HPALETTE
CreatePalette(LPLOGPALETTE lpLogPalette
)
933 ATLASSERT(m_hPalette
== NULL
);
934 m_hPalette
= ::CreatePalette(lpLogPalette
);
939 HPALETTE
CreateHalftonePalette(HDC hDC
)
941 ATLASSERT(m_hPalette
== NULL
);
942 ATLASSERT(hDC
!= NULL
);
943 m_hPalette
= ::CreateHalftonePalette(hDC
);
946 #endif // !_WIN32_WCE
950 ATLASSERT(m_hPalette
!= NULL
);
951 BOOL bRet
= ::DeleteObject(m_hPalette
);
958 int GetEntryCount() const
960 ATLASSERT(m_hPalette
!= NULL
);
962 ::GetObject(m_hPalette
, sizeof(WORD
), &nEntries
);
963 return (int)nEntries
;
966 UINT
GetPaletteEntries(UINT nStartIndex
, UINT nNumEntries
, LPPALETTEENTRY lpPaletteColors
) const
968 ATLASSERT(m_hPalette
!= NULL
);
969 return ::GetPaletteEntries(m_hPalette
, nStartIndex
, nNumEntries
, lpPaletteColors
);
972 UINT
SetPaletteEntries(UINT nStartIndex
, UINT nNumEntries
, LPPALETTEENTRY lpPaletteColors
)
974 ATLASSERT(m_hPalette
!= NULL
);
975 return ::SetPaletteEntries(m_hPalette
, nStartIndex
, nNumEntries
, lpPaletteColors
);
980 void AnimatePalette(UINT nStartIndex
, UINT nNumEntries
, LPPALETTEENTRY lpPaletteColors
)
982 ATLASSERT(m_hPalette
!= NULL
);
983 ::AnimatePalette(m_hPalette
, nStartIndex
, nNumEntries
, lpPaletteColors
);
986 BOOL
ResizePalette(UINT nNumEntries
)
988 ATLASSERT(m_hPalette
!= NULL
);
989 return ::ResizePalette(m_hPalette
, nNumEntries
);
991 #endif // !_WIN32_WCE
993 UINT
GetNearestPaletteIndex(COLORREF crColor
) const
995 ATLASSERT(m_hPalette
!= NULL
);
996 return ::GetNearestPaletteIndex(m_hPalette
, crColor
);
1000 typedef CPaletteT
<false> CPaletteHandle
;
1001 typedef CPaletteT
<true> CPalette
;
1004 ///////////////////////////////////////////////////////////////////////////////
1007 template <bool t_bManaged
>
1014 // Constructor/destructor/operators
1015 CRgnT(HRGN hRgn
= NULL
) : m_hRgn(hRgn
)
1020 if(t_bManaged
&& m_hRgn
!= NULL
)
1024 CRgnT
<t_bManaged
>& operator =(HRGN hRgn
)
1030 void Attach(HRGN hRgn
)
1032 if(t_bManaged
&& m_hRgn
!= NULL
&& m_hRgn
!= hRgn
)
1033 ::DeleteObject(m_hRgn
);
1044 operator HRGN() const { return m_hRgn
; }
1046 bool IsNull() const { return (m_hRgn
== NULL
); }
1049 HRGN
CreateRectRgn(int x1
, int y1
, int x2
, int y2
)
1051 ATLASSERT(m_hRgn
== NULL
);
1052 m_hRgn
= ::CreateRectRgn(x1
, y1
, x2
, y2
);
1056 HRGN
CreateRectRgnIndirect(LPCRECT lpRect
)
1058 ATLASSERT(m_hRgn
== NULL
);
1059 m_hRgn
= ::CreateRectRgnIndirect(lpRect
);
1064 HRGN
CreateEllipticRgn(int x1
, int y1
, int x2
, int y2
)
1066 ATLASSERT(m_hRgn
== NULL
);
1067 m_hRgn
= ::CreateEllipticRgn(x1
, y1
, x2
, y2
);
1071 HRGN
CreateEllipticRgnIndirect(LPCRECT lpRect
)
1073 ATLASSERT(m_hRgn
== NULL
);
1074 m_hRgn
= ::CreateEllipticRgnIndirect(lpRect
);
1078 HRGN
CreatePolygonRgn(LPPOINT lpPoints
, int nCount
, int nMode
)
1080 ATLASSERT(m_hRgn
== NULL
);
1081 m_hRgn
= ::CreatePolygonRgn(lpPoints
, nCount
, nMode
);
1085 HRGN
CreatePolyPolygonRgn(LPPOINT lpPoints
, LPINT lpPolyCounts
, int nCount
, int nPolyFillMode
)
1087 ATLASSERT(m_hRgn
== NULL
);
1088 m_hRgn
= ::CreatePolyPolygonRgn(lpPoints
, lpPolyCounts
, nCount
, nPolyFillMode
);
1092 HRGN
CreateRoundRectRgn(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
)
1094 ATLASSERT(m_hRgn
== NULL
);
1095 m_hRgn
= ::CreateRoundRectRgn(x1
, y1
, x2
, y2
, x3
, y3
);
1099 HRGN
CreateFromPath(HDC hDC
)
1101 ATLASSERT(m_hRgn
== NULL
);
1102 ATLASSERT(hDC
!= NULL
);
1103 m_hRgn
= ::PathToRegion(hDC
);
1107 HRGN
CreateFromData(const XFORM
* lpXForm
, int nCount
, const RGNDATA
* pRgnData
)
1109 ATLASSERT(m_hRgn
== NULL
);
1110 m_hRgn
= ::ExtCreateRegion(lpXForm
, nCount
, pRgnData
);
1113 #endif // !_WIN32_WCE
1117 ATLASSERT(m_hRgn
!= NULL
);
1118 BOOL bRet
= ::DeleteObject(m_hRgn
);
1125 void SetRectRgn(int x1
, int y1
, int x2
, int y2
)
1127 ATLASSERT(m_hRgn
!= NULL
);
1128 ::SetRectRgn(m_hRgn
, x1
, y1
, x2
, y2
);
1131 void SetRectRgn(LPCRECT lpRect
)
1133 ATLASSERT(m_hRgn
!= NULL
);
1134 ::SetRectRgn(m_hRgn
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
1137 int CombineRgn(HRGN hRgnSrc1
, HRGN hRgnSrc2
, int nCombineMode
)
1139 ATLASSERT(m_hRgn
!= NULL
);
1140 return ::CombineRgn(m_hRgn
, hRgnSrc1
, hRgnSrc2
, nCombineMode
);
1143 int CombineRgn(HRGN hRgnSrc
, int nCombineMode
)
1145 ATLASSERT(m_hRgn
!= NULL
);
1146 return ::CombineRgn(m_hRgn
, m_hRgn
, hRgnSrc
, nCombineMode
);
1149 int CopyRgn(HRGN hRgnSrc
)
1151 ATLASSERT(m_hRgn
!= NULL
);
1152 return ::CombineRgn(m_hRgn
, hRgnSrc
, NULL
, RGN_COPY
);
1155 BOOL
EqualRgn(HRGN hRgn
) const
1157 ATLASSERT(m_hRgn
!= NULL
);
1158 return ::EqualRgn(m_hRgn
, hRgn
);
1161 int OffsetRgn(int x
, int y
)
1163 ATLASSERT(m_hRgn
!= NULL
);
1164 return ::OffsetRgn(m_hRgn
, x
, y
);
1167 int OffsetRgn(POINT point
)
1169 ATLASSERT(m_hRgn
!= NULL
);
1170 return ::OffsetRgn(m_hRgn
, point
.x
, point
.y
);
1173 int GetRgnBox(LPRECT lpRect
) const
1175 ATLASSERT(m_hRgn
!= NULL
);
1176 return ::GetRgnBox(m_hRgn
, lpRect
);
1179 BOOL
PtInRegion(int x
, int y
) const
1181 ATLASSERT(m_hRgn
!= NULL
);
1182 return ::PtInRegion(m_hRgn
, x
, y
);
1185 BOOL
PtInRegion(POINT point
) const
1187 ATLASSERT(m_hRgn
!= NULL
);
1188 return ::PtInRegion(m_hRgn
, point
.x
, point
.y
);
1191 BOOL
RectInRegion(LPCRECT lpRect
) const
1193 ATLASSERT(m_hRgn
!= NULL
);
1194 return ::RectInRegion(m_hRgn
, lpRect
);
1197 int GetRegionData(LPRGNDATA lpRgnData
, int nDataSize
) const
1199 ATLASSERT(m_hRgn
!= NULL
);
1200 return (int)::GetRegionData(m_hRgn
, nDataSize
, lpRgnData
);
1204 typedef CRgnT
<false> CRgnHandle
;
1205 typedef CRgnT
<true> CRgn
;
1208 ///////////////////////////////////////////////////////////////////////////////
1209 // CDC - The device context class
1211 template <bool t_bManaged
>
1218 // Constructor/destructor/operators
1219 CDCT(HDC hDC
= NULL
) : m_hDC(hDC
)
1225 if(t_bManaged
&& m_hDC
!= NULL
)
1226 ::DeleteDC(Detach());
1229 CDCT
<t_bManaged
>& operator =(HDC hDC
)
1235 void Attach(HDC hDC
)
1237 if(t_bManaged
&& m_hDC
!= NULL
&& m_hDC
!= hDC
)
1249 operator HDC() const { return m_hDC
; }
1251 bool IsNull() const { return (m_hDC
== NULL
); }
1255 HWND
WindowFromDC() const
1257 ATLASSERT(m_hDC
!= NULL
);
1258 return ::WindowFromDC(m_hDC
);
1260 #endif // !_WIN32_WCE
1262 CPenHandle
GetCurrentPen() const
1264 ATLASSERT(m_hDC
!= NULL
);
1265 return CPenHandle((HPEN
)::GetCurrentObject(m_hDC
, OBJ_PEN
));
1268 CBrushHandle
GetCurrentBrush() const
1270 ATLASSERT(m_hDC
!= NULL
);
1271 return CBrushHandle((HBRUSH
)::GetCurrentObject(m_hDC
, OBJ_BRUSH
));
1274 CPaletteHandle
GetCurrentPalette() const
1276 ATLASSERT(m_hDC
!= NULL
);
1277 return CPaletteHandle((HPALETTE
)::GetCurrentObject(m_hDC
, OBJ_PAL
));
1280 CFontHandle
GetCurrentFont() const
1282 ATLASSERT(m_hDC
!= NULL
);
1283 return CFontHandle((HFONT
)::GetCurrentObject(m_hDC
, OBJ_FONT
));
1286 CBitmapHandle
GetCurrentBitmap() const
1288 ATLASSERT(m_hDC
!= NULL
);
1289 return CBitmapHandle((HBITMAP
)::GetCurrentObject(m_hDC
, OBJ_BITMAP
));
1292 HDC
CreateDC(LPCTSTR lpszDriverName
, LPCTSTR lpszDeviceName
, LPCTSTR lpszOutput
, const DEVMODE
* lpInitData
)
1294 ATLASSERT(m_hDC
== NULL
);
1295 m_hDC
= ::CreateDC(lpszDriverName
, lpszDeviceName
, lpszOutput
, lpInitData
);
1299 HDC
CreateCompatibleDC(HDC hDC
= NULL
)
1301 ATLASSERT(m_hDC
== NULL
);
1302 m_hDC
= ::CreateCompatibleDC(hDC
);
1310 BOOL bRet
= ::DeleteDC(m_hDC
);
1316 // Device-Context Functions
1319 ATLASSERT(m_hDC
!= NULL
);
1320 return ::SaveDC(m_hDC
);
1323 BOOL
RestoreDC(int nSavedDC
)
1325 ATLASSERT(m_hDC
!= NULL
);
1326 return ::RestoreDC(m_hDC
, nSavedDC
);
1329 int GetDeviceCaps(int nIndex
) const
1331 ATLASSERT(m_hDC
!= NULL
);
1332 return ::GetDeviceCaps(m_hDC
, nIndex
);
1336 UINT
SetBoundsRect(LPCRECT lpRectBounds
, UINT flags
)
1338 ATLASSERT(m_hDC
!= NULL
);
1339 return ::SetBoundsRect(m_hDC
, lpRectBounds
, flags
);
1342 UINT
GetBoundsRect(LPRECT lpRectBounds
, UINT flags
) const
1344 ATLASSERT(m_hDC
!= NULL
);
1345 return ::GetBoundsRect(m_hDC
, lpRectBounds
, flags
);
1348 BOOL
ResetDC(const DEVMODE
* lpDevMode
)
1350 ATLASSERT(m_hDC
!= NULL
);
1351 return ::ResetDC(m_hDC
, lpDevMode
) != NULL
;
1354 // Drawing-Tool Functions
1355 BOOL
GetBrushOrg(LPPOINT lpPoint
) const
1357 ATLASSERT(m_hDC
!= NULL
);
1358 return ::GetBrushOrgEx(m_hDC
, lpPoint
);
1360 #endif // !_WIN32_WCE
1362 BOOL
SetBrushOrg(int x
, int y
, LPPOINT lpPoint
= NULL
)
1364 ATLASSERT(m_hDC
!= NULL
);
1365 return ::SetBrushOrgEx(m_hDC
, x
, y
, lpPoint
);
1368 BOOL
SetBrushOrg(POINT point
, LPPOINT lpPointRet
= NULL
)
1370 ATLASSERT(m_hDC
!= NULL
);
1371 return ::SetBrushOrgEx(m_hDC
, point
.x
, point
.y
, lpPointRet
);
1375 int EnumObjects(int nObjectType
, int (CALLBACK
* lpfn
)(LPVOID
, LPARAM
), LPARAM lpData
)
1377 ATLASSERT(m_hDC
!= NULL
);
1379 return ::EnumObjects(m_hDC
, nObjectType
, (GOBJENUMPROC
)lpfn
, lpData
);
1381 return ::EnumObjects(m_hDC
, nObjectType
, (GOBJENUMPROC
)lpfn
, (LPVOID
)lpData
);
1384 #endif // !_WIN32_WCE
1386 // Type-safe selection helpers
1387 HPEN
SelectPen(HPEN hPen
)
1389 ATLASSERT(m_hDC
!= NULL
);
1391 ATLASSERT(hPen
== NULL
|| ::GetObjectType(hPen
) == OBJ_PEN
|| ::GetObjectType(hPen
) == OBJ_EXTPEN
);
1392 #else // CE specific
1393 ATLASSERT(hPen
== NULL
|| ::GetObjectType(hPen
) == OBJ_PEN
);
1394 #endif // _WIN32_WCE
1395 return (HPEN
)::SelectObject(m_hDC
, hPen
);
1398 HBRUSH
SelectBrush(HBRUSH hBrush
)
1400 ATLASSERT(m_hDC
!= NULL
);
1401 ATLASSERT(hBrush
== NULL
|| ::GetObjectType(hBrush
) == OBJ_BRUSH
);
1402 return (HBRUSH
)::SelectObject(m_hDC
, hBrush
);
1405 HFONT
SelectFont(HFONT hFont
)
1407 ATLASSERT(m_hDC
!= NULL
);
1408 ATLASSERT(hFont
== NULL
|| ::GetObjectType(hFont
) == OBJ_FONT
);
1409 return (HFONT
)::SelectObject(m_hDC
, hFont
);
1412 HBITMAP
SelectBitmap(HBITMAP hBitmap
)
1414 ATLASSERT(m_hDC
!= NULL
);
1415 ATLASSERT(hBitmap
== NULL
|| ::GetObjectType(hBitmap
) == OBJ_BITMAP
);
1416 return (HBITMAP
)::SelectObject(m_hDC
, hBitmap
);
1419 int SelectRgn(HRGN hRgn
) // special return for regions
1421 ATLASSERT(m_hDC
!= NULL
);
1422 ATLASSERT(hRgn
== NULL
|| ::GetObjectType(hRgn
) == OBJ_REGION
);
1423 return PtrToInt(::SelectObject(m_hDC
, hRgn
));
1426 // Type-safe selection helpers for stock objects
1427 HPEN
SelectStockPen(int nPen
)
1429 ATLASSERT(m_hDC
!= NULL
);
1430 #if (_WIN32_WINNT >= 0x0500)
1431 ATLASSERT(nPen
== WHITE_PEN
|| nPen
== BLACK_PEN
|| nPen
== NULL_PEN
|| nPen
== DC_PEN
);
1433 ATLASSERT(nPen
== WHITE_PEN
|| nPen
== BLACK_PEN
|| nPen
== NULL_PEN
);
1434 #endif // !(_WIN32_WINNT >= 0x0500)
1435 return SelectPen((HPEN
)::GetStockObject(nPen
));
1438 HBRUSH
SelectStockBrush(int nBrush
)
1440 #if (_WIN32_WINNT >= 0x0500)
1441 ATLASSERT((nBrush
>= WHITE_BRUSH
&& nBrush
<= HOLLOW_BRUSH
) || nBrush
== DC_BRUSH
);
1443 ATLASSERT(nBrush
>= WHITE_BRUSH
&& nBrush
<= HOLLOW_BRUSH
);
1444 #endif // !(_WIN32_WINNT >= 0x0500)
1445 return SelectBrush((HBRUSH
)::GetStockObject(nBrush
));
1448 HFONT
SelectStockFont(int nFont
)
1451 ATLASSERT((nFont
>= OEM_FIXED_FONT
&& nFont
<= SYSTEM_FIXED_FONT
) || nFont
== DEFAULT_GUI_FONT
);
1452 #else // CE specific
1453 ATLASSERT(nFont
== SYSTEM_FONT
);
1454 #endif // _WIN32_WCE
1455 return SelectFont((HFONT
)::GetStockObject(nFont
));
1458 HPALETTE
SelectStockPalette(int nPalette
, BOOL bForceBackground
)
1460 ATLASSERT(nPalette
== DEFAULT_PALETTE
); // the only one supported
1461 return SelectPalette((HPALETTE
)::GetStockObject(nPalette
), bForceBackground
);
1464 // Color and Color Palette Functions
1465 COLORREF
GetNearestColor(COLORREF crColor
) const
1467 ATLASSERT(m_hDC
!= NULL
);
1468 return ::GetNearestColor(m_hDC
, crColor
);
1471 HPALETTE
SelectPalette(HPALETTE hPalette
, BOOL bForceBackground
)
1473 ATLASSERT(m_hDC
!= NULL
);
1475 return ::SelectPalette(m_hDC
, hPalette
, bForceBackground
);
1478 UINT
RealizePalette()
1480 ATLASSERT(m_hDC
!= NULL
);
1481 return ::RealizePalette(m_hDC
);
1487 ATLASSERT(m_hDC
!= NULL
);
1488 ::UpdateColors(m_hDC
);
1490 #endif // !_WIN32_WCE
1492 // Drawing-Attribute Functions
1493 COLORREF
GetBkColor() const
1495 ATLASSERT(m_hDC
!= NULL
);
1496 return ::GetBkColor(m_hDC
);
1499 int GetBkMode() const
1501 ATLASSERT(m_hDC
!= NULL
);
1502 return ::GetBkMode(m_hDC
);
1506 int GetPolyFillMode() const
1508 ATLASSERT(m_hDC
!= NULL
);
1509 return ::GetPolyFillMode(m_hDC
);
1514 ATLASSERT(m_hDC
!= NULL
);
1515 return ::GetROP2(m_hDC
);
1518 int GetStretchBltMode() const
1520 ATLASSERT(m_hDC
!= NULL
);
1521 return ::GetStretchBltMode(m_hDC
);
1523 #endif // !_WIN32_WCE
1525 COLORREF
GetTextColor() const
1527 ATLASSERT(m_hDC
!= NULL
);
1528 return ::GetTextColor(m_hDC
);
1531 COLORREF
SetBkColor(COLORREF crColor
)
1533 ATLASSERT(m_hDC
!= NULL
);
1534 return ::SetBkColor(m_hDC
, crColor
);
1537 int SetBkMode(int nBkMode
)
1539 ATLASSERT(m_hDC
!= NULL
);
1540 return ::SetBkMode(m_hDC
, nBkMode
);
1544 int SetPolyFillMode(int nPolyFillMode
)
1546 ATLASSERT(m_hDC
!= NULL
);
1547 return ::SetPolyFillMode(m_hDC
, nPolyFillMode
);
1549 #endif // !_WIN32_WCE
1551 int SetROP2(int nDrawMode
)
1553 ATLASSERT(m_hDC
!= NULL
);
1554 return ::SetROP2(m_hDC
, nDrawMode
);
1558 int SetStretchBltMode(int nStretchMode
)
1560 ATLASSERT(m_hDC
!= NULL
);
1561 return ::SetStretchBltMode(m_hDC
, nStretchMode
);
1563 #endif // !_WIN32_WCE
1565 COLORREF
SetTextColor(COLORREF crColor
)
1567 ATLASSERT(m_hDC
!= NULL
);
1568 return ::SetTextColor(m_hDC
, crColor
);
1572 BOOL
GetColorAdjustment(LPCOLORADJUSTMENT lpColorAdjust
) const
1574 ATLASSERT(m_hDC
!= NULL
);
1575 return ::GetColorAdjustment(m_hDC
, lpColorAdjust
);
1578 BOOL
SetColorAdjustment(const COLORADJUSTMENT
* lpColorAdjust
)
1580 ATLASSERT(m_hDC
!= NULL
);
1581 return ::SetColorAdjustment(m_hDC
, lpColorAdjust
);
1584 // Mapping Functions
1585 int GetMapMode() const
1587 ATLASSERT(m_hDC
!= NULL
);
1588 return ::GetMapMode(m_hDC
);
1591 BOOL
GetViewportOrg(LPPOINT lpPoint
) const
1593 ATLASSERT(m_hDC
!= NULL
);
1594 return ::GetViewportOrgEx(m_hDC
, lpPoint
);
1597 int SetMapMode(int nMapMode
)
1599 ATLASSERT(m_hDC
!= NULL
);
1600 return ::SetMapMode(m_hDC
, nMapMode
);
1602 #endif // !_WIN32_WCE
1605 BOOL
SetViewportOrg(int x
, int y
, LPPOINT lpPoint
= NULL
)
1607 ATLASSERT(m_hDC
!= NULL
);
1608 return ::SetViewportOrgEx(m_hDC
, x
, y
, lpPoint
);
1611 BOOL
SetViewportOrg(POINT point
, LPPOINT lpPointRet
= NULL
)
1613 ATLASSERT(m_hDC
!= NULL
);
1614 return SetViewportOrg(point
.x
, point
.y
, lpPointRet
);
1618 BOOL
OffsetViewportOrg(int nWidth
, int nHeight
, LPPOINT lpPoint
= NULL
)
1620 ATLASSERT(m_hDC
!= NULL
);
1621 return ::OffsetViewportOrgEx(m_hDC
, nWidth
, nHeight
, lpPoint
);
1625 BOOL
GetViewportExt(LPSIZE lpSize
) const
1627 ATLASSERT(m_hDC
!= NULL
);
1628 return ::GetViewportExtEx(m_hDC
, lpSize
);
1631 BOOL
SetViewportExt(int x
, int y
, LPSIZE lpSize
= NULL
)
1633 ATLASSERT(m_hDC
!= NULL
);
1634 return ::SetViewportExtEx(m_hDC
, x
, y
, lpSize
);
1637 BOOL
SetViewportExt(SIZE size
, LPSIZE lpSizeRet
= NULL
)
1639 ATLASSERT(m_hDC
!= NULL
);
1640 return SetViewportExt(size
.cx
, size
.cy
, lpSizeRet
);
1643 BOOL
ScaleViewportExt(int xNum
, int xDenom
, int yNum
, int yDenom
, LPSIZE lpSize
= NULL
)
1645 ATLASSERT(m_hDC
!= NULL
);
1646 return ::ScaleViewportExtEx(m_hDC
, xNum
, xDenom
, yNum
, yDenom
, lpSize
);
1648 #endif // !_WIN32_WCE
1652 BOOL
GetWindowOrg(LPPOINT lpPoint
) const
1654 ATLASSERT(m_hDC
!= NULL
);
1655 return ::GetWindowOrgEx(m_hDC
, lpPoint
);
1658 BOOL
SetWindowOrg(int x
, int y
, LPPOINT lpPoint
= NULL
)
1660 ATLASSERT(m_hDC
!= NULL
);
1661 return ::SetWindowOrgEx(m_hDC
, x
, y
, lpPoint
);
1664 BOOL
SetWindowOrg(POINT point
, LPPOINT lpPointRet
= NULL
)
1666 ATLASSERT(m_hDC
!= NULL
);
1667 return SetWindowOrg(point
.x
, point
.y
, lpPointRet
);
1670 BOOL
OffsetWindowOrg(int nWidth
, int nHeight
, LPPOINT lpPoint
= NULL
)
1672 ATLASSERT(m_hDC
!= NULL
);
1673 return ::OffsetWindowOrgEx(m_hDC
, nWidth
, nHeight
, lpPoint
);
1677 BOOL
GetWindowExt(LPSIZE lpSize
) const
1679 ATLASSERT(m_hDC
!= NULL
);
1680 return ::GetWindowExtEx(m_hDC
, lpSize
);
1683 BOOL
SetWindowExt(int x
, int y
, LPSIZE lpSize
= NULL
)
1685 ATLASSERT(m_hDC
!= NULL
);
1686 return ::SetWindowExtEx(m_hDC
, x
, y
, lpSize
);
1689 BOOL
SetWindowExt(SIZE size
, LPSIZE lpSizeRet
= NULL
)
1691 ATLASSERT(m_hDC
!= NULL
);
1692 return SetWindowExt(size
.cx
, size
.cy
, lpSizeRet
);
1695 BOOL
ScaleWindowExt(int xNum
, int xDenom
, int yNum
, int yDenom
, LPSIZE lpSize
= NULL
)
1697 ATLASSERT(m_hDC
!= NULL
);
1698 return ::ScaleWindowExtEx(m_hDC
, xNum
, xDenom
, yNum
, yDenom
, lpSize
);
1701 // Coordinate Functions
1702 BOOL
DPtoLP(LPPOINT lpPoints
, int nCount
= 1) const
1704 ATLASSERT(m_hDC
!= NULL
);
1705 return ::DPtoLP(m_hDC
, lpPoints
, nCount
);
1708 BOOL
DPtoLP(LPRECT lpRect
) const
1710 ATLASSERT(m_hDC
!= NULL
);
1711 return ::DPtoLP(m_hDC
, (LPPOINT
)lpRect
, 2);
1714 BOOL
DPtoLP(LPSIZE lpSize
) const
1716 SIZE sizeWinExt
= { 0, 0 };
1717 if(!GetWindowExt(&sizeWinExt
))
1719 SIZE sizeVpExt
= { 0, 0 };
1720 if(!GetViewportExt(&sizeVpExt
))
1722 lpSize
->cx
= ::MulDiv(lpSize
->cx
, abs(sizeWinExt
.cx
), abs(sizeVpExt
.cx
));
1723 lpSize
->cy
= ::MulDiv(lpSize
->cy
, abs(sizeWinExt
.cy
), abs(sizeVpExt
.cy
));
1727 BOOL
LPtoDP(LPPOINT lpPoints
, int nCount
= 1) const
1729 ATLASSERT(m_hDC
!= NULL
);
1730 return ::LPtoDP(m_hDC
, lpPoints
, nCount
);
1733 BOOL
LPtoDP(LPRECT lpRect
) const
1735 ATLASSERT(m_hDC
!= NULL
);
1736 return ::LPtoDP(m_hDC
, (LPPOINT
)lpRect
, 2);
1739 BOOL
LPtoDP(LPSIZE lpSize
) const
1741 SIZE sizeWinExt
= { 0, 0 };
1742 if(!GetWindowExt(&sizeWinExt
))
1744 SIZE sizeVpExt
= { 0, 0 };
1745 if(!GetViewportExt(&sizeVpExt
))
1747 lpSize
->cx
= ::MulDiv(lpSize
->cx
, abs(sizeVpExt
.cx
), abs(sizeWinExt
.cx
));
1748 lpSize
->cy
= ::MulDiv(lpSize
->cy
, abs(sizeVpExt
.cy
), abs(sizeWinExt
.cy
));
1752 // Special Coordinate Functions (useful for dealing with metafiles and OLE)
1753 #define HIMETRIC_INCH 2540 // HIMETRIC units per inch
1755 void DPtoHIMETRIC(LPSIZE lpSize
) const
1757 ATLASSERT(m_hDC
!= NULL
);
1759 if((nMapMode
= GetMapMode()) < MM_ISOTROPIC
&& nMapMode
!= MM_TEXT
)
1761 // when using a constrained map mode, map against physical inch
1762 ((CDCHandle
*)this)->SetMapMode(MM_HIMETRIC
);
1764 ((CDCHandle
*)this)->SetMapMode(nMapMode
);
1768 // map against logical inch for non-constrained mapping modes
1769 int cxPerInch
= GetDeviceCaps(LOGPIXELSX
);
1770 int cyPerInch
= GetDeviceCaps(LOGPIXELSY
);
1771 ATLASSERT(cxPerInch
!= 0 && cyPerInch
!= 0);
1772 lpSize
->cx
= ::MulDiv(lpSize
->cx
, HIMETRIC_INCH
, cxPerInch
);
1773 lpSize
->cy
= ::MulDiv(lpSize
->cy
, HIMETRIC_INCH
, cyPerInch
);
1777 void HIMETRICtoDP(LPSIZE lpSize
) const
1779 ATLASSERT(m_hDC
!= NULL
);
1781 if((nMapMode
= GetMapMode()) < MM_ISOTROPIC
&& nMapMode
!= MM_TEXT
)
1783 // when using a constrained map mode, map against physical inch
1784 ((CDCHandle
*)this)->SetMapMode(MM_HIMETRIC
);
1786 ((CDCHandle
*)this)->SetMapMode(nMapMode
);
1790 // map against logical inch for non-constrained mapping modes
1791 int cxPerInch
= GetDeviceCaps(LOGPIXELSX
);
1792 int cyPerInch
= GetDeviceCaps(LOGPIXELSY
);
1793 ATLASSERT(cxPerInch
!= 0 && cyPerInch
!= 0);
1794 lpSize
->cx
= ::MulDiv(lpSize
->cx
, cxPerInch
, HIMETRIC_INCH
);
1795 lpSize
->cy
= ::MulDiv(lpSize
->cy
, cyPerInch
, HIMETRIC_INCH
);
1799 void LPtoHIMETRIC(LPSIZE lpSize
) const
1802 DPtoHIMETRIC(lpSize
);
1805 void HIMETRICtoLP(LPSIZE lpSize
) const
1807 HIMETRICtoDP(lpSize
);
1810 #endif // !_WIN32_WCE
1813 BOOL
FillRgn(HRGN hRgn
, HBRUSH hBrush
)
1815 ATLASSERT(m_hDC
!= NULL
);
1816 return ::FillRgn(m_hDC
, hRgn
, hBrush
);
1820 BOOL
FrameRgn(HRGN hRgn
, HBRUSH hBrush
, int nWidth
, int nHeight
)
1822 ATLASSERT(m_hDC
!= NULL
);
1823 return ::FrameRgn(m_hDC
, hRgn
, hBrush
, nWidth
, nHeight
);
1826 BOOL
InvertRgn(HRGN hRgn
)
1828 ATLASSERT(m_hDC
!= NULL
);
1829 return ::InvertRgn(m_hDC
, hRgn
);
1832 BOOL
PaintRgn(HRGN hRgn
)
1834 ATLASSERT(m_hDC
!= NULL
);
1835 return ::PaintRgn(m_hDC
, hRgn
);
1837 #endif // !_WIN32_WCE
1839 // Clipping Functions
1840 int GetClipBox(LPRECT lpRect
) const
1842 ATLASSERT(m_hDC
!= NULL
);
1843 return ::GetClipBox(m_hDC
, lpRect
);
1846 int GetClipRgn(CRgn
& region
) const
1848 ATLASSERT(m_hDC
!= NULL
);
1850 region
.CreateRectRgn(0, 0, 0, 0);
1852 int nRet
= ::GetClipRgn(m_hDC
, region
);
1854 region
.DeleteObject();
1860 BOOL
PtVisible(int x
, int y
) const
1862 ATLASSERT(m_hDC
!= NULL
);
1863 return ::PtVisible(m_hDC
, x
, y
);
1866 BOOL
PtVisible(POINT point
) const
1868 ATLASSERT(m_hDC
!= NULL
);
1869 return ::PtVisible(m_hDC
, point
.x
, point
.y
);
1871 #endif // !_WIN32_WCE
1873 BOOL
RectVisible(LPCRECT lpRect
) const
1875 ATLASSERT(m_hDC
!= NULL
);
1876 return ::RectVisible(m_hDC
, lpRect
);
1879 int SelectClipRgn(HRGN hRgn
)
1881 ATLASSERT(m_hDC
!= NULL
);
1882 return ::SelectClipRgn(m_hDC
, (HRGN
)hRgn
);
1885 int ExcludeClipRect(int x1
, int y1
, int x2
, int y2
)
1887 ATLASSERT(m_hDC
!= NULL
);
1888 return ::ExcludeClipRect(m_hDC
, x1
, y1
, x2
, y2
);
1891 int ExcludeClipRect(LPCRECT lpRect
)
1893 ATLASSERT(m_hDC
!= NULL
);
1894 return ::ExcludeClipRect(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
1898 int ExcludeUpdateRgn(HWND hWnd
)
1900 ATLASSERT(m_hDC
!= NULL
);
1901 return ::ExcludeUpdateRgn(m_hDC
, hWnd
);
1903 #endif // !_WIN32_WCE
1905 int IntersectClipRect(int x1
, int y1
, int x2
, int y2
)
1907 ATLASSERT(m_hDC
!= NULL
);
1908 return ::IntersectClipRect(m_hDC
, x1
, y1
, x2
, y2
);
1911 int IntersectClipRect(LPCRECT lpRect
)
1913 ATLASSERT(m_hDC
!= NULL
);
1914 return ::IntersectClipRect(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
1918 int OffsetClipRgn(int x
, int y
)
1920 ATLASSERT(m_hDC
!= NULL
);
1921 return ::OffsetClipRgn(m_hDC
, x
, y
);
1924 int OffsetClipRgn(SIZE size
)
1926 ATLASSERT(m_hDC
!= NULL
);
1927 return ::OffsetClipRgn(m_hDC
, size
.cx
, size
.cy
);
1930 int SelectClipRgn(HRGN hRgn
, int nMode
)
1932 ATLASSERT(m_hDC
!= NULL
);
1933 return ::ExtSelectClipRgn(m_hDC
, hRgn
, nMode
);
1935 #endif // !_WIN32_WCE
1937 // Line-Output Functions
1938 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
1939 BOOL
GetCurrentPosition(LPPOINT lpPoint
) const
1941 ATLASSERT(m_hDC
!= NULL
);
1942 return ::GetCurrentPositionEx(m_hDC
, lpPoint
);
1945 BOOL
MoveTo(int x
, int y
, LPPOINT lpPoint
= NULL
)
1947 ATLASSERT(m_hDC
!= NULL
);
1948 return ::MoveToEx(m_hDC
, x
, y
, lpPoint
);
1951 BOOL
MoveTo(POINT point
, LPPOINT lpPointRet
= NULL
)
1953 ATLASSERT(m_hDC
!= NULL
);
1954 return MoveTo(point
.x
, point
.y
, lpPointRet
);
1957 BOOL
LineTo(int x
, int y
)
1959 ATLASSERT(m_hDC
!= NULL
);
1960 return ::LineTo(m_hDC
, x
, y
);
1963 BOOL
LineTo(POINT point
)
1965 ATLASSERT(m_hDC
!= NULL
);
1966 return LineTo(point
.x
, point
.y
);
1968 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
1971 BOOL
Arc(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
, int x4
, int y4
)
1973 ATLASSERT(m_hDC
!= NULL
);
1974 return ::Arc(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
1977 BOOL
Arc(LPCRECT lpRect
, POINT ptStart
, POINT ptEnd
)
1979 ATLASSERT(m_hDC
!= NULL
);
1980 return ::Arc(m_hDC
, lpRect
->left
, lpRect
->top
,
1981 lpRect
->right
, lpRect
->bottom
, ptStart
.x
, ptStart
.y
,
1984 #endif // !_WIN32_WCE
1986 BOOL
Polyline(const POINT
* lpPoints
, int nCount
)
1988 ATLASSERT(m_hDC
!= NULL
);
1989 return ::Polyline(m_hDC
, lpPoints
, nCount
);
1993 BOOL
AngleArc(int x
, int y
, int nRadius
, float fStartAngle
, float fSweepAngle
)
1995 ATLASSERT(m_hDC
!= NULL
);
1996 return ::AngleArc(m_hDC
, x
, y
, nRadius
, fStartAngle
, fSweepAngle
);
1999 BOOL
ArcTo(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
, int x4
, int y4
)
2001 ATLASSERT(m_hDC
!= NULL
);
2002 return ::ArcTo(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
2005 BOOL
ArcTo(LPCRECT lpRect
, POINT ptStart
, POINT ptEnd
)
2007 ATLASSERT(m_hDC
!= NULL
);
2008 return ArcTo(lpRect
->left
, lpRect
->top
, lpRect
->right
,
2009 lpRect
->bottom
, ptStart
.x
, ptStart
.y
, ptEnd
.x
, ptEnd
.y
);
2012 int GetArcDirection() const
2014 ATLASSERT(m_hDC
!= NULL
);
2015 return ::GetArcDirection(m_hDC
);
2018 int SetArcDirection(int nArcDirection
)
2020 ATLASSERT(m_hDC
!= NULL
);
2021 return ::SetArcDirection(m_hDC
, nArcDirection
);
2024 BOOL
PolyDraw(const POINT
* lpPoints
, const BYTE
* lpTypes
, int nCount
)
2026 ATLASSERT(m_hDC
!= NULL
);
2027 return ::PolyDraw(m_hDC
, lpPoints
, lpTypes
, nCount
);
2030 BOOL
PolylineTo(const POINT
* lpPoints
, int nCount
)
2032 ATLASSERT(m_hDC
!= NULL
);
2033 return ::PolylineTo(m_hDC
, lpPoints
, nCount
);
2036 BOOL
PolyPolyline(const POINT
* lpPoints
,
2037 const DWORD
* lpPolyPoints
, int nCount
)
2039 ATLASSERT(m_hDC
!= NULL
);
2040 return ::PolyPolyline(m_hDC
, lpPoints
, lpPolyPoints
, nCount
);
2043 BOOL
PolyBezier(const POINT
* lpPoints
, int nCount
)
2045 ATLASSERT(m_hDC
!= NULL
);
2046 return ::PolyBezier(m_hDC
, lpPoints
, nCount
);
2049 BOOL
PolyBezierTo(const POINT
* lpPoints
, int nCount
)
2051 ATLASSERT(m_hDC
!= NULL
);
2052 return ::PolyBezierTo(m_hDC
, lpPoints
, nCount
);
2054 #endif // !_WIN32_WCE
2056 // Simple Drawing Functions
2057 BOOL
FillRect(LPCRECT lpRect
, HBRUSH hBrush
)
2059 ATLASSERT(m_hDC
!= NULL
);
2060 return ::FillRect(m_hDC
, lpRect
, hBrush
);
2063 BOOL
FillRect(LPCRECT lpRect
, int nColorIndex
)
2065 ATLASSERT(m_hDC
!= NULL
);
2067 return ::FillRect(m_hDC
, lpRect
, (HBRUSH
)LongToPtr(nColorIndex
+ 1));
2068 #else // CE specific
2069 return ::FillRect(m_hDC
, lpRect
, ::GetSysColorBrush(nColorIndex
));
2070 #endif // _WIN32_WCE
2074 BOOL
FrameRect(LPCRECT lpRect
, HBRUSH hBrush
)
2076 ATLASSERT(m_hDC
!= NULL
);
2077 return ::FrameRect(m_hDC
, lpRect
, hBrush
);
2079 #endif // !_WIN32_WCE
2081 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 420)
2082 BOOL
InvertRect(LPCRECT lpRect
)
2084 ATLASSERT(m_hDC
!= NULL
);
2085 return ::InvertRect(m_hDC
, lpRect
);
2087 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 420)
2089 BOOL
DrawIcon(int x
, int y
, HICON hIcon
)
2091 ATLASSERT(m_hDC
!= NULL
);
2093 return ::DrawIcon(m_hDC
, x
, y
, hIcon
);
2094 #else // CE specific
2095 return ::DrawIconEx(m_hDC
, x
, y
, hIcon
, 0, 0, 0, NULL
, DI_NORMAL
);
2096 #endif // _WIN32_WCE
2099 BOOL
DrawIcon(POINT point
, HICON hIcon
)
2101 ATLASSERT(m_hDC
!= NULL
);
2103 return ::DrawIcon(m_hDC
, point
.x
, point
.y
, hIcon
);
2104 #else // CE specific
2105 return ::DrawIconEx(m_hDC
, point
.x
, point
.y
, hIcon
, 0, 0, 0, NULL
, DI_NORMAL
);
2106 #endif // _WIN32_WCE
2109 BOOL
DrawIconEx(int x
, int y
, HICON hIcon
, int cxWidth
, int cyWidth
, UINT uStepIfAniCur
= 0, HBRUSH hbrFlickerFreeDraw
= NULL
, UINT uFlags
= DI_NORMAL
)
2111 ATLASSERT(m_hDC
!= NULL
);
2112 return ::DrawIconEx(m_hDC
, x
, y
, hIcon
, cxWidth
, cyWidth
, uStepIfAniCur
, hbrFlickerFreeDraw
, uFlags
);
2115 BOOL
DrawIconEx(POINT point
, HICON hIcon
, SIZE size
, UINT uStepIfAniCur
= 0, HBRUSH hbrFlickerFreeDraw
= NULL
, UINT uFlags
= DI_NORMAL
)
2117 ATLASSERT(m_hDC
!= NULL
);
2118 return ::DrawIconEx(m_hDC
, point
.x
, point
.y
, hIcon
, size
.cx
, size
.cy
, uStepIfAniCur
, hbrFlickerFreeDraw
, uFlags
);
2122 BOOL
DrawState(POINT pt
, SIZE size
, HBITMAP hBitmap
, UINT nFlags
, HBRUSH hBrush
= NULL
)
2124 ATLASSERT(m_hDC
!= NULL
);
2125 return ::DrawState(m_hDC
, hBrush
, NULL
, (LPARAM
)hBitmap
, 0, pt
.x
, pt
.y
, size
.cx
, size
.cy
, nFlags
| DST_BITMAP
);
2128 BOOL
DrawState(POINT pt
, SIZE size
, HICON hIcon
, UINT nFlags
, HBRUSH hBrush
= NULL
)
2130 ATLASSERT(m_hDC
!= NULL
);
2131 return ::DrawState(m_hDC
, hBrush
, NULL
, (LPARAM
)hIcon
, 0, pt
.x
, pt
.y
, size
.cx
, size
.cy
, nFlags
| DST_ICON
);
2134 BOOL
DrawState(POINT pt
, SIZE size
, LPCTSTR lpszText
, UINT nFlags
, BOOL bPrefixText
= TRUE
, int nTextLen
= 0, HBRUSH hBrush
= NULL
)
2136 ATLASSERT(m_hDC
!= NULL
);
2137 return ::DrawState(m_hDC
, hBrush
, NULL
, (LPARAM
)lpszText
, (WPARAM
)nTextLen
, pt
.x
, pt
.y
, size
.cx
, size
.cy
, nFlags
| (bPrefixText
? DST_PREFIXTEXT
: DST_TEXT
));
2140 BOOL
DrawState(POINT pt
, SIZE size
, DRAWSTATEPROC lpDrawProc
, LPARAM lData
, UINT nFlags
, HBRUSH hBrush
= NULL
)
2142 ATLASSERT(m_hDC
!= NULL
);
2143 return ::DrawState(m_hDC
, hBrush
, lpDrawProc
, lData
, 0, pt
.x
, pt
.y
, size
.cx
, size
.cy
, nFlags
| DST_COMPLEX
);
2145 #endif // !_WIN32_WCE
2147 // Ellipse and Polygon Functions
2149 BOOL
Chord(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
, int x4
, int y4
)
2151 ATLASSERT(m_hDC
!= NULL
);
2152 return ::Chord(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
2155 BOOL
Chord(LPCRECT lpRect
, POINT ptStart
, POINT ptEnd
)
2157 ATLASSERT(m_hDC
!= NULL
);
2158 return ::Chord(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
, ptStart
.x
, ptStart
.y
, ptEnd
.x
, ptEnd
.y
);
2160 #endif // !_WIN32_WCE
2162 void DrawFocusRect(LPCRECT lpRect
)
2164 ATLASSERT(m_hDC
!= NULL
);
2165 ::DrawFocusRect(m_hDC
, lpRect
);
2168 BOOL
Ellipse(int x1
, int y1
, int x2
, int y2
)
2170 ATLASSERT(m_hDC
!= NULL
);
2171 return ::Ellipse(m_hDC
, x1
, y1
, x2
, y2
);
2174 BOOL
Ellipse(LPCRECT lpRect
)
2176 ATLASSERT(m_hDC
!= NULL
);
2177 return ::Ellipse(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
2181 BOOL
Pie(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
, int x4
, int y4
)
2183 ATLASSERT(m_hDC
!= NULL
);
2184 return ::Pie(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
);
2187 BOOL
Pie(LPCRECT lpRect
, POINT ptStart
, POINT ptEnd
)
2189 ATLASSERT(m_hDC
!= NULL
);
2190 return ::Pie(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
, ptStart
.x
, ptStart
.y
, ptEnd
.x
, ptEnd
.y
);
2192 #endif // !_WIN32_WCE
2194 BOOL
Polygon(const POINT
* lpPoints
, int nCount
)
2196 ATLASSERT(m_hDC
!= NULL
);
2197 return ::Polygon(m_hDC
, lpPoints
, nCount
);
2201 BOOL
PolyPolygon(const POINT
* lpPoints
, const INT
* lpPolyCounts
, int nCount
)
2203 ATLASSERT(m_hDC
!= NULL
);
2204 return ::PolyPolygon(m_hDC
, lpPoints
, lpPolyCounts
, nCount
);
2206 #endif // !_WIN32_WCE
2208 BOOL
Rectangle(int x1
, int y1
, int x2
, int y2
)
2210 ATLASSERT(m_hDC
!= NULL
);
2211 return ::Rectangle(m_hDC
, x1
, y1
, x2
, y2
);
2214 BOOL
Rectangle(LPCRECT lpRect
)
2216 ATLASSERT(m_hDC
!= NULL
);
2217 return ::Rectangle(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
);
2220 BOOL
RoundRect(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
)
2222 ATLASSERT(m_hDC
!= NULL
);
2223 return ::RoundRect(m_hDC
, x1
, y1
, x2
, y2
, x3
, y3
);
2226 BOOL
RoundRect(LPCRECT lpRect
, POINT point
)
2228 ATLASSERT(m_hDC
!= NULL
);
2229 return ::RoundRect(m_hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
, lpRect
->bottom
, point
.x
, point
.y
);
2233 BOOL
PatBlt(int x
, int y
, int nWidth
, int nHeight
, DWORD dwRop
)
2235 ATLASSERT(m_hDC
!= NULL
);
2236 return ::PatBlt(m_hDC
, x
, y
, nWidth
, nHeight
, dwRop
);
2239 BOOL
BitBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
,
2240 int xSrc
, int ySrc
, DWORD dwRop
)
2242 ATLASSERT(m_hDC
!= NULL
);
2243 return ::BitBlt(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, dwRop
);
2246 BOOL
StretchBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, int nSrcWidth
, int nSrcHeight
, DWORD dwRop
)
2248 ATLASSERT(m_hDC
!= NULL
);
2249 return ::StretchBlt(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, dwRop
);
2252 COLORREF
GetPixel(int x
, int y
) const
2254 ATLASSERT(m_hDC
!= NULL
);
2255 return ::GetPixel(m_hDC
, x
, y
);
2258 COLORREF
GetPixel(POINT point
) const
2260 ATLASSERT(m_hDC
!= NULL
);
2261 return ::GetPixel(m_hDC
, point
.x
, point
.y
);
2264 COLORREF
SetPixel(int x
, int y
, COLORREF crColor
)
2266 ATLASSERT(m_hDC
!= NULL
);
2267 return ::SetPixel(m_hDC
, x
, y
, crColor
);
2270 COLORREF
SetPixel(POINT point
, COLORREF crColor
)
2272 ATLASSERT(m_hDC
!= NULL
);
2273 return ::SetPixel(m_hDC
, point
.x
, point
.y
, crColor
);
2277 BOOL
FloodFill(int x
, int y
, COLORREF crColor
)
2279 ATLASSERT(m_hDC
!= NULL
);
2280 return ::FloodFill(m_hDC
, x
, y
, crColor
);
2283 BOOL
ExtFloodFill(int x
, int y
, COLORREF crColor
, UINT nFillType
)
2285 ATLASSERT(m_hDC
!= NULL
);
2286 return ::ExtFloodFill(m_hDC
, x
, y
, crColor
, nFillType
);
2288 #endif // !_WIN32_WCE
2290 BOOL
MaskBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, HBITMAP hMaskBitmap
, int xMask
, int yMask
, DWORD dwRop
)
2292 ATLASSERT(m_hDC
!= NULL
);
2293 return ::MaskBlt(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, hMaskBitmap
, xMask
, yMask
, dwRop
);
2297 BOOL
PlgBlt(LPPOINT lpPoint
, HDC hSrcDC
, int xSrc
, int ySrc
, int nWidth
, int nHeight
, HBITMAP hMaskBitmap
, int xMask
, int yMask
)
2299 ATLASSERT(m_hDC
!= NULL
);
2300 return ::PlgBlt(m_hDC
, lpPoint
, hSrcDC
, xSrc
, ySrc
, nWidth
, nHeight
, hMaskBitmap
, xMask
, yMask
);
2303 BOOL
SetPixelV(int x
, int y
, COLORREF crColor
)
2305 ATLASSERT(m_hDC
!= NULL
);
2306 return ::SetPixelV(m_hDC
, x
, y
, crColor
);
2309 BOOL
SetPixelV(POINT point
, COLORREF crColor
)
2311 ATLASSERT(m_hDC
!= NULL
);
2312 return ::SetPixelV(m_hDC
, point
.x
, point
.y
, crColor
);
2314 #endif // !_WIN32_WCE
2316 #if !defined(_ATL_NO_MSIMG) || defined(_WIN32_WCE)
2318 BOOL
TransparentBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, int nSrcWidth
, int nSrcHeight
, UINT crTransparent
)
2320 ATLASSERT(m_hDC
!= NULL
);
2321 return ::TransparentBlt(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, crTransparent
);
2323 #else // CE specific
2324 BOOL
TransparentImage(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, int nSrcWidth
, int nSrcHeight
, UINT crTransparent
)
2326 ATLASSERT(m_hDC
!= NULL
);
2327 return ::TransparentImage(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, crTransparent
);
2329 #endif // _WIN32_WCE
2331 #if (!defined(_WIN32_WCE) || (_WIN32_WCE >= 420))
2332 BOOL
GradientFill(const PTRIVERTEX pVertices
, DWORD nVertices
, void* pMeshElements
, DWORD nMeshElements
, DWORD dwMode
)
2334 ATLASSERT(m_hDC
!= NULL
);
2335 return ::GradientFill(m_hDC
, pVertices
, nVertices
, pMeshElements
, nMeshElements
, dwMode
);
2338 BOOL
GradientFillRect(RECT
& rect
, COLORREF clr1
, COLORREF clr2
, bool bHorizontal
)
2340 ATLASSERT(m_hDC
!= NULL
);
2342 TRIVERTEX arrTvx
[2] = { { 0 }, { 0 } };
2344 arrTvx
[0].x
= rect
.left
;
2345 arrTvx
[0].y
= rect
.top
;
2346 arrTvx
[0].Red
= MAKEWORD(0, GetRValue(clr1
));
2347 arrTvx
[0].Green
= MAKEWORD(0, GetGValue(clr1
));
2348 arrTvx
[0].Blue
= MAKEWORD(0, GetBValue(clr1
));
2349 arrTvx
[0].Alpha
= 0;
2351 arrTvx
[1].x
= rect
.right
;
2352 arrTvx
[1].y
= rect
.bottom
;
2353 arrTvx
[1].Red
= MAKEWORD(0, GetRValue(clr2
));
2354 arrTvx
[1].Green
= MAKEWORD(0, GetGValue(clr2
));
2355 arrTvx
[1].Blue
= MAKEWORD(0, GetBValue(clr2
));
2356 arrTvx
[1].Alpha
= 0;
2358 GRADIENT_RECT gr
= { 0, 1 };
2360 return ::GradientFill(m_hDC
, arrTvx
, 2, &gr
, 1, bHorizontal
? GRADIENT_FILL_RECT_H
: GRADIENT_FILL_RECT_V
);
2362 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 420)
2364 #if !defined(_WIN32_WCE) || (_WIN32_WCE > 0x500)
2365 BOOL
AlphaBlend(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, int xSrc
, int ySrc
, int nSrcWidth
, int nSrcHeight
, BLENDFUNCTION bf
)
2367 ATLASSERT(m_hDC
!= NULL
);
2368 return ::AlphaBlend(m_hDC
, x
, y
, nWidth
, nHeight
, hSrcDC
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, bf
);
2370 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE > 0x500)
2371 #endif // !defined(_ATL_NO_MSIMG) || defined(_WIN32_WCE)
2373 // Extra bitmap functions
2374 // Helper function for painting a disabled toolbar or menu bitmap
2375 // This function can take either an HBITMAP (for SS) or a DC with
2376 // the bitmap already painted (for cmdbar)
2377 BOOL
DitherBlt(int x
, int y
, int nWidth
, int nHeight
, HDC hSrcDC
, HBITMAP hBitmap
, int xSrc
, int ySrc
,
2378 HBRUSH hBrushBackground
= ::GetSysColorBrush(COLOR_3DFACE
),
2379 HBRUSH hBrush3DEffect
= ::GetSysColorBrush(COLOR_3DHILIGHT
),
2380 HBRUSH hBrushDisabledImage
= ::GetSysColorBrush(COLOR_3DSHADOW
))
2382 ATLASSERT(m_hDC
!= NULL
|| hBitmap
!= NULL
);
2383 ATLASSERT(nWidth
> 0 && nHeight
> 0);
2385 // Create a generic DC for all BitBlts
2386 CDCHandle dc
= (hSrcDC
!= NULL
) ? hSrcDC
: ::CreateCompatibleDC(m_hDC
);
2387 ATLASSERT(dc
.m_hDC
!= NULL
);
2388 if(dc
.m_hDC
== NULL
)
2391 // Create a DC for the monochrome DIB section
2392 CDC dcBW
= ::CreateCompatibleDC(m_hDC
);
2393 ATLASSERT(dcBW
.m_hDC
!= NULL
);
2394 if(dcBW
.m_hDC
== NULL
)
2401 // Create the monochrome DIB section with a black and white palette
2402 struct RGBBWBITMAPINFO
2404 BITMAPINFOHEADER bmiHeader
;
2405 RGBQUAD bmiColors
[2];
2408 RGBBWBITMAPINFO rgbBWBitmapInfo
=
2410 { sizeof(BITMAPINFOHEADER
), nWidth
, nHeight
, 1, 1, BI_RGB
, 0, 0, 0, 0, 0 },
2411 { { 0x00, 0x00, 0x00, 0x00 }, { 0xFF, 0xFF, 0xFF, 0x00 } }
2415 CBitmap bmpBW
= ::CreateDIBSection(dcBW
, (LPBITMAPINFO
)&rgbBWBitmapInfo
, DIB_RGB_COLORS
, &pbitsBW
, NULL
, 0);
2416 ATLASSERT(bmpBW
.m_hBitmap
!= NULL
);
2417 if(bmpBW
.m_hBitmap
== NULL
)
2424 // Attach the monochrome DIB section and the bitmap to the DCs
2425 HBITMAP hbmOldBW
= dcBW
.SelectBitmap(bmpBW
);
2426 HBITMAP hbmOldDC
= NULL
;
2428 hbmOldDC
= dc
.SelectBitmap(hBitmap
);
2430 // Block: Dark gray removal: we want (128, 128, 128) pixels to become black and not white
2432 CDC dcTemp1
= ::CreateCompatibleDC(m_hDC
);
2433 CDC dcTemp2
= ::CreateCompatibleDC(m_hDC
);
2435 bmpTemp1
.CreateCompatibleBitmap(dc
, nWidth
, nHeight
);
2437 bmpTemp2
.CreateBitmap(nWidth
, nHeight
, 1, 1, NULL
);
2438 HBITMAP hOldBmp1
= dcTemp1
.SelectBitmap(bmpTemp1
);
2439 HBITMAP hOldBmp2
= dcTemp2
.SelectBitmap(bmpTemp2
);
2440 // Let's copy our image, it will be altered
2441 dcTemp1
.BitBlt(0, 0, nWidth
, nHeight
, dc
, xSrc
, ySrc
, SRCCOPY
);
2443 // All dark gray pixels will become white, the others black
2444 dcTemp1
.SetBkColor(RGB(128, 128, 128));
2445 dcTemp2
.BitBlt(0, 0, nWidth
, nHeight
, dcTemp1
, 0, 0, SRCCOPY
);
2446 // Do an XOR to set to black these white pixels
2447 dcTemp1
.BitBlt(0, 0, nWidth
, nHeight
, dcTemp2
, 0, 0, SRCINVERT
);
2449 // BitBlt the bitmap into the monochrome DIB section
2450 // The DIB section will do a true monochrome conversion
2451 // The magenta background being closer to white will become white
2452 dcBW
.BitBlt(0, 0, nWidth
, nHeight
, dcTemp1
, 0, 0, SRCCOPY
);
2455 dcTemp1
.SelectBitmap(hOldBmp1
);
2456 dcTemp2
.SelectBitmap(hOldBmp2
);
2459 // Paint the destination rectangle using hBrushBackground
2460 if(hBrushBackground
!= NULL
)
2462 RECT rc
= { x
, y
, x
+ nWidth
, y
+ nHeight
};
2463 FillRect(&rc
, hBrushBackground
);
2466 // BitBlt the black bits in the monochrome bitmap into hBrush3DEffect color in the destination DC
2467 // The magic ROP comes from the Charles Petzold's book
2468 HBRUSH hOldBrush
= SelectBrush(hBrush3DEffect
);
2469 BitBlt(x
+ 1, y
+ 1, nWidth
, nHeight
, dcBW
, 0, 0, 0xB8074A);
2471 // BitBlt the black bits in the monochrome bitmap into hBrushDisabledImage color in the destination DC
2472 SelectBrush(hBrushDisabledImage
);
2473 BitBlt(x
, y
, nWidth
, nHeight
, dcBW
, 0, 0, 0xB8074A);
2475 SelectBrush(hOldBrush
);
2476 dcBW
.SelectBitmap(hbmOldBW
);
2477 dc
.SelectBitmap(hbmOldDC
);
2487 BOOL
TextOut(int x
, int y
, LPCTSTR lpszString
, int nCount
= -1)
2489 ATLASSERT(m_hDC
!= NULL
);
2491 nCount
= lstrlen(lpszString
);
2492 return ::TextOut(m_hDC
, x
, y
, lpszString
, nCount
);
2494 #endif // !_WIN32_WCE
2496 BOOL
ExtTextOut(int x
, int y
, UINT nOptions
, LPCRECT lpRect
, LPCTSTR lpszString
, UINT nCount
= -1, LPINT lpDxWidths
= NULL
)
2498 ATLASSERT(m_hDC
!= NULL
);
2500 nCount
= lstrlen(lpszString
);
2501 return ::ExtTextOut(m_hDC
, x
, y
, nOptions
, lpRect
, lpszString
, nCount
, lpDxWidths
);
2505 SIZE
TabbedTextOut(int x
, int y
, LPCTSTR lpszString
, int nCount
= -1, int nTabPositions
= 0, LPINT lpnTabStopPositions
= NULL
, int nTabOrigin
= 0)
2507 ATLASSERT(m_hDC
!= NULL
);
2509 nCount
= lstrlen(lpszString
);
2510 LONG lRes
= ::TabbedTextOut(m_hDC
, x
, y
, lpszString
, nCount
, nTabPositions
, lpnTabStopPositions
, nTabOrigin
);
2511 SIZE size
= { GET_X_LPARAM(lRes
), GET_Y_LPARAM(lRes
) };
2514 #endif // !_WIN32_WCE
2516 int DrawText(LPCTSTR lpstrText
, int cchText
, LPRECT lpRect
, UINT uFormat
)
2518 ATLASSERT(m_hDC
!= NULL
);
2520 ATLASSERT((uFormat
& DT_MODIFYSTRING
) == 0);
2521 #endif // !_WIN32_WCE
2522 return ::DrawText(m_hDC
, lpstrText
, cchText
, lpRect
, uFormat
);
2525 int DrawText(LPTSTR lpstrText
, int cchText
, LPRECT lpRect
, UINT uFormat
)
2527 ATLASSERT(m_hDC
!= NULL
);
2528 return ::DrawText(m_hDC
, lpstrText
, cchText
, lpRect
, uFormat
);
2532 int DrawTextEx(LPTSTR lpstrText
, int cchText
, LPRECT lpRect
, UINT uFormat
, LPDRAWTEXTPARAMS lpDTParams
= NULL
)
2534 ATLASSERT(m_hDC
!= NULL
);
2535 return ::DrawTextEx(m_hDC
, lpstrText
, cchText
, lpRect
, uFormat
, lpDTParams
);
2537 #endif // !_WIN32_WCE
2539 #if (_WIN32_WINNT >= 0x0501)
2540 int DrawShadowText(LPCWSTR lpstrText
, int cchText
, LPRECT lpRect
, DWORD dwFlags
, COLORREF clrText
, COLORREF clrShadow
, int xOffset
, int yOffset
)
2542 ATLASSERT(m_hDC
!= NULL
);
2543 // This function is present only if comctl32.dll version 6 is loaded;
2544 // we use LoadLibrary/GetProcAddress to allow apps compiled with
2545 // _WIN32_WINNT >= 0x0501 to run on older Windows/CommCtrl
2547 HMODULE hCommCtrlDLL
= ::LoadLibrary(_T("comctl32.dll"));
2548 ATLASSERT(hCommCtrlDLL
!= NULL
);
2549 if(hCommCtrlDLL
!= NULL
)
2551 typedef int (WINAPI
*PFN_DrawShadowText
)(HDC hDC
, LPCWSTR lpstrText
, UINT cchText
, LPRECT lpRect
, DWORD dwFlags
, COLORREF clrText
, COLORREF clrShadow
, int xOffset
, int yOffset
);
2552 PFN_DrawShadowText pfnDrawShadowText
= (PFN_DrawShadowText
)::GetProcAddress(hCommCtrlDLL
, "DrawShadowText");
2553 ATLASSERT(pfnDrawShadowText
!= NULL
); // this function requires CommCtrl6
2554 if(pfnDrawShadowText
!= NULL
)
2555 nRet
= pfnDrawShadowText(m_hDC
, lpstrText
, cchText
, lpRect
, dwFlags
, clrText
, clrShadow
, xOffset
, yOffset
);
2556 ::FreeLibrary(hCommCtrlDLL
);
2560 #endif // (_WIN32_WINNT >= 0x0501)
2562 BOOL
GetTextExtent(LPCTSTR lpszString
, int nCount
, LPSIZE lpSize
) const
2564 ATLASSERT(m_hDC
!= NULL
);
2566 nCount
= lstrlen(lpszString
);
2567 return ::GetTextExtentPoint32(m_hDC
, lpszString
, nCount
, lpSize
);
2570 BOOL
GetTextExtentExPoint(LPCTSTR lpszString
, int cchString
, LPSIZE lpSize
, int nMaxExtent
, LPINT lpnFit
= NULL
, LPINT alpDx
= NULL
)
2572 ATLASSERT(m_hDC
!= NULL
);
2573 return ::GetTextExtentExPoint(m_hDC
, lpszString
, cchString
, nMaxExtent
, lpnFit
, alpDx
, lpSize
);
2577 DWORD
GetTabbedTextExtent(LPCTSTR lpszString
, int nCount
= -1, int nTabPositions
= 0, LPINT lpnTabStopPositions
= NULL
) const
2579 ATLASSERT(m_hDC
!= NULL
);
2581 nCount
= lstrlen(lpszString
);
2582 return ::GetTabbedTextExtent(m_hDC
, lpszString
, nCount
, nTabPositions
, lpnTabStopPositions
);
2585 BOOL
GrayString(HBRUSH hBrush
, BOOL (CALLBACK
* lpfnOutput
)(HDC
, LPARAM
, int), LPARAM lpData
, int nCount
, int x
, int y
, int nWidth
, int nHeight
)
2587 ATLASSERT(m_hDC
!= NULL
);
2588 return ::GrayString(m_hDC
, hBrush
, (GRAYSTRINGPROC
)lpfnOutput
, lpData
, nCount
, x
, y
, nWidth
, nHeight
);
2590 #endif // !_WIN32_WCE
2592 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
2593 UINT
GetTextAlign() const
2595 ATLASSERT(m_hDC
!= NULL
);
2596 return ::GetTextAlign(m_hDC
);
2599 UINT
SetTextAlign(UINT nFlags
)
2601 ATLASSERT(m_hDC
!= NULL
);
2602 return ::SetTextAlign(m_hDC
, nFlags
);
2604 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
2606 int GetTextFace(LPTSTR lpszFacename
, int nCount
) const
2608 ATLASSERT(m_hDC
!= NULL
);
2609 return ::GetTextFace(m_hDC
, nCount
, lpszFacename
);
2612 int GetTextFaceLen() const
2614 ATLASSERT(m_hDC
!= NULL
);
2615 return ::GetTextFace(m_hDC
, 0, NULL
);
2620 BOOL
GetTextFace(BSTR
& bstrFace
) const
2623 ATLASSERT(m_hDC
!= NULL
);
2624 ATLASSERT(bstrFace
== NULL
);
2626 int nLen
= GetTextFaceLen();
2630 CTempBuffer
<TCHAR
, _WTL_STACK_ALLOC_THRESHOLD
> buff
;
2631 LPTSTR lpszText
= buff
.Allocate(nLen
);
2632 if(lpszText
== NULL
)
2635 if(!GetTextFace(lpszText
, nLen
))
2638 bstrFace
= ::SysAllocString(T2OLE(lpszText
));
2639 return (bstrFace
!= NULL
) ? TRUE
: FALSE
;
2642 #endif // !_ATL_NO_COM
2644 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
2645 int GetTextFace(_CSTRING_NS::CString
& strFace
) const
2647 ATLASSERT(m_hDC
!= NULL
);
2649 int nLen
= GetTextFaceLen();
2653 LPTSTR lpstr
= strFace
.GetBufferSetLength(nLen
);
2656 int nRet
= GetTextFace(lpstr
, nLen
);
2657 strFace
.ReleaseBuffer();
2660 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
2662 BOOL
GetTextMetrics(LPTEXTMETRIC lpMetrics
) const
2664 ATLASSERT(m_hDC
!= NULL
);
2665 return ::GetTextMetrics(m_hDC
, lpMetrics
);
2669 int SetTextJustification(int nBreakExtra
, int nBreakCount
)
2671 ATLASSERT(m_hDC
!= NULL
);
2672 return ::SetTextJustification(m_hDC
, nBreakExtra
, nBreakCount
);
2675 int GetTextCharacterExtra() const
2677 ATLASSERT(m_hDC
!= NULL
);
2678 return ::GetTextCharacterExtra(m_hDC
);
2681 int SetTextCharacterExtra(int nCharExtra
)
2683 ATLASSERT(m_hDC
!= NULL
);
2684 return ::SetTextCharacterExtra(m_hDC
, nCharExtra
);
2686 #endif // !_WIN32_WCE
2689 BOOL
DrawEdge(LPRECT lpRect
, UINT nEdge
, UINT nFlags
)
2691 ATLASSERT(m_hDC
!= NULL
);
2692 return ::DrawEdge(m_hDC
, lpRect
, nEdge
, nFlags
);
2695 BOOL
DrawFrameControl(LPRECT lpRect
, UINT nType
, UINT nState
)
2697 ATLASSERT(m_hDC
!= NULL
);
2698 return ::DrawFrameControl(m_hDC
, lpRect
, nType
, nState
);
2701 // Scrolling Functions
2702 BOOL
ScrollDC(int dx
, int dy
, LPCRECT lpRectScroll
, LPCRECT lpRectClip
, HRGN hRgnUpdate
, LPRECT lpRectUpdate
)
2704 ATLASSERT(m_hDC
!= NULL
);
2705 return ::ScrollDC(m_hDC
, dx
, dy
, lpRectScroll
, lpRectClip
, hRgnUpdate
, lpRectUpdate
);
2710 BOOL
GetCharWidth(UINT nFirstChar
, UINT nLastChar
, LPINT lpBuffer
) const
2712 ATLASSERT(m_hDC
!= NULL
);
2713 return ::GetCharWidth(m_hDC
, nFirstChar
, nLastChar
, lpBuffer
);
2716 // GetCharWidth32 is not supported under Win9x
2717 BOOL
GetCharWidth32(UINT nFirstChar
, UINT nLastChar
, LPINT lpBuffer
) const
2719 ATLASSERT(m_hDC
!= NULL
);
2720 return ::GetCharWidth32(m_hDC
, nFirstChar
, nLastChar
, lpBuffer
);
2723 DWORD
SetMapperFlags(DWORD dwFlag
)
2725 ATLASSERT(m_hDC
!= NULL
);
2726 return ::SetMapperFlags(m_hDC
, dwFlag
);
2729 BOOL
GetAspectRatioFilter(LPSIZE lpSize
) const
2731 ATLASSERT(m_hDC
!= NULL
);
2732 return ::GetAspectRatioFilterEx(m_hDC
, lpSize
);
2735 BOOL
GetCharABCWidths(UINT nFirstChar
, UINT nLastChar
, LPABC lpabc
) const
2737 ATLASSERT(m_hDC
!= NULL
);
2738 return ::GetCharABCWidths(m_hDC
, nFirstChar
, nLastChar
, lpabc
);
2741 DWORD
GetFontData(DWORD dwTable
, DWORD dwOffset
, LPVOID lpData
, DWORD cbData
) const
2743 ATLASSERT(m_hDC
!= NULL
);
2744 return ::GetFontData(m_hDC
, dwTable
, dwOffset
, lpData
, cbData
);
2747 int GetKerningPairs(int nPairs
, LPKERNINGPAIR lpkrnpair
) const
2749 ATLASSERT(m_hDC
!= NULL
);
2750 return ::GetKerningPairs(m_hDC
, nPairs
, lpkrnpair
);
2753 UINT
GetOutlineTextMetrics(UINT cbData
, LPOUTLINETEXTMETRIC lpotm
) const
2755 ATLASSERT(m_hDC
!= NULL
);
2756 return ::GetOutlineTextMetrics(m_hDC
, cbData
, lpotm
);
2759 DWORD
GetGlyphOutline(UINT nChar
, UINT nFormat
, LPGLYPHMETRICS lpgm
, DWORD cbBuffer
, LPVOID lpBuffer
, const MAT2
* lpmat2
) const
2761 ATLASSERT(m_hDC
!= NULL
);
2762 return ::GetGlyphOutline(m_hDC
, nChar
, nFormat
, lpgm
, cbBuffer
, lpBuffer
, lpmat2
);
2765 BOOL
GetCharABCWidths(UINT nFirstChar
, UINT nLastChar
, LPABCFLOAT lpABCF
) const
2767 ATLASSERT(m_hDC
!= NULL
);
2768 return ::GetCharABCWidthsFloat(m_hDC
, nFirstChar
, nLastChar
, lpABCF
);
2771 BOOL
GetCharWidth(UINT nFirstChar
, UINT nLastChar
, float* lpFloatBuffer
) const
2773 ATLASSERT(m_hDC
!= NULL
);
2774 return ::GetCharWidthFloat(m_hDC
, nFirstChar
, nLastChar
, lpFloatBuffer
);
2776 #endif // !_WIN32_WCE
2778 // Printer/Device Escape Functions
2780 int Escape(int nEscape
, int nCount
, LPCSTR lpszInData
, LPVOID lpOutData
)
2782 ATLASSERT(m_hDC
!= NULL
);
2783 return ::Escape(m_hDC
, nEscape
, nCount
, lpszInData
, lpOutData
);
2785 #endif // !_WIN32_WCE
2787 int Escape(int nEscape
, int nInputSize
, LPCSTR lpszInputData
,
2788 int nOutputSize
, LPSTR lpszOutputData
)
2790 ATLASSERT(m_hDC
!= NULL
);
2791 return ::ExtEscape(m_hDC
, nEscape
, nInputSize
, lpszInputData
, nOutputSize
, lpszOutputData
);
2795 int DrawEscape(int nEscape
, int nInputSize
, LPCSTR lpszInputData
)
2797 ATLASSERT(m_hDC
!= NULL
);
2798 return ::DrawEscape(m_hDC
, nEscape
, nInputSize
, lpszInputData
);
2800 #endif // !_WIN32_WCE
2803 #if !defined(_WIN32_WCE) || ((_WIN32_WCE >= 200) && defined(StartDoc))
2804 int StartDoc(LPCTSTR lpszDocName
) // old Win3.0 version
2807 di
.cbSize
= sizeof(DOCINFO
);
2808 di
.lpszDocName
= lpszDocName
;
2809 return StartDoc(&di
);
2812 int StartDoc(LPDOCINFO lpDocInfo
)
2814 ATLASSERT(m_hDC
!= NULL
);
2815 return ::StartDoc(m_hDC
, lpDocInfo
);
2820 ATLASSERT(m_hDC
!= NULL
);
2821 return ::StartPage(m_hDC
);
2826 ATLASSERT(m_hDC
!= NULL
);
2827 return ::EndPage(m_hDC
);
2830 int SetAbortProc(BOOL (CALLBACK
* lpfn
)(HDC
, int))
2832 ATLASSERT(m_hDC
!= NULL
);
2833 return ::SetAbortProc(m_hDC
, (ABORTPROC
)lpfn
);
2838 ATLASSERT(m_hDC
!= NULL
);
2839 return ::AbortDoc(m_hDC
);
2844 ATLASSERT(m_hDC
!= NULL
);
2845 return ::EndDoc(m_hDC
);
2847 #endif // !defined(_WIN32_WCE) || ((_WIN32_WCE >= 200) && defined(StartDoc))
2849 // MetaFile Functions
2851 BOOL
PlayMetaFile(HMETAFILE hMF
)
2853 ATLASSERT(m_hDC
!= NULL
);
2854 if(::GetDeviceCaps(m_hDC
, TECHNOLOGY
) == DT_METAFILE
)
2856 // playing metafile in metafile, just use core windows API
2857 return ::PlayMetaFile(m_hDC
, hMF
);
2860 // for special playback, lParam == pDC
2861 return ::EnumMetaFile(m_hDC
, hMF
, EnumMetaFileProc
, (LPARAM
)this);
2864 BOOL
PlayMetaFile(HENHMETAFILE hEnhMetaFile
, LPCRECT lpBounds
)
2866 ATLASSERT(m_hDC
!= NULL
);
2867 return ::PlayEnhMetaFile(m_hDC
, hEnhMetaFile
, lpBounds
);
2870 BOOL
AddMetaFileComment(UINT nDataSize
, const BYTE
* pCommentData
) // can be used for enhanced metafiles only
2872 ATLASSERT(m_hDC
!= NULL
);
2873 return ::GdiComment(m_hDC
, nDataSize
, pCommentData
);
2876 // Special handling for metafile playback
2877 static int CALLBACK
EnumMetaFileProc(HDC hDC
, HANDLETABLE
* pHandleTable
, METARECORD
* pMetaRec
, int nHandles
, LPARAM lParam
)
2879 CDCHandle
* pDC
= (CDCHandle
*)lParam
;
2881 switch (pMetaRec
->rdFunction
)
2883 case META_SETMAPMODE
:
2884 pDC
->SetMapMode((int)(short)pMetaRec
->rdParm
[0]);
2886 case META_SETWINDOWEXT
:
2887 pDC
->SetWindowExt((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2889 case META_SETWINDOWORG
:
2890 pDC
->SetWindowOrg((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2892 case META_SETVIEWPORTEXT
:
2893 pDC
->SetViewportExt((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2895 case META_SETVIEWPORTORG
:
2896 pDC
->SetViewportOrg((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2898 case META_SCALEWINDOWEXT
:
2899 pDC
->ScaleWindowExt((int)(short)pMetaRec
->rdParm
[3], (int)(short)pMetaRec
->rdParm
[2],
2900 (int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2902 case META_SCALEVIEWPORTEXT
:
2903 pDC
->ScaleViewportExt((int)(short)pMetaRec
->rdParm
[3], (int)(short)pMetaRec
->rdParm
[2],
2904 (int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2906 case META_OFFSETVIEWPORTORG
:
2907 pDC
->OffsetViewportOrg((int)(short)pMetaRec
->rdParm
[1], (int)(short)pMetaRec
->rdParm
[0]);
2912 case META_RESTOREDC
:
2913 pDC
->RestoreDC((int)(short)pMetaRec
->rdParm
[0]);
2915 case META_SETBKCOLOR
:
2916 pDC
->SetBkColor(*(UNALIGNED COLORREF
*)&pMetaRec
->rdParm
[0]);
2918 case META_SETTEXTCOLOR
:
2919 pDC
->SetTextColor(*(UNALIGNED COLORREF
*)&pMetaRec
->rdParm
[0]);
2922 // need to watch out for SelectObject(HFONT), for custom font mapping
2923 case META_SELECTOBJECT
:
2925 HGDIOBJ hObject
= pHandleTable
->objectHandle
[pMetaRec
->rdParm
[0]];
2926 UINT nObjType
= ::GetObjectType(hObject
);
2929 // object type is unknown, determine if it is a font
2930 HFONT hStockFont
= (HFONT
)::GetStockObject(SYSTEM_FONT
);
2931 HFONT hFontOld
= (HFONT
)::SelectObject(pDC
->m_hDC
, hStockFont
);
2932 HGDIOBJ hObjOld
= ::SelectObject(pDC
->m_hDC
, hObject
);
2933 if(hObjOld
== hStockFont
)
2935 // got the stock object back, so must be selecting a font
2936 pDC
->SelectFont((HFONT
)hObject
);
2937 break; // don't play the default record
2941 // didn't get the stock object back, so restore everything
2942 ::SelectObject(pDC
->m_hDC
, hFontOld
);
2943 ::SelectObject(pDC
->m_hDC
, hObjOld
);
2945 // and fall through to PlayMetaFileRecord...
2947 else if(nObjType
== OBJ_FONT
)
2949 // play back as CDCHandle::SelectFont(HFONT)
2950 pDC
->SelectFont((HFONT
)hObject
);
2951 break; // don't play the default record
2957 ::PlayMetaFileRecord(hDC
, pHandleTable
, pMetaRec
, nHandles
);
2963 #endif // !_WIN32_WCE
2969 ATLASSERT(m_hDC
!= NULL
);
2970 return ::AbortPath(m_hDC
);
2975 ATLASSERT(m_hDC
!= NULL
);
2976 return ::BeginPath(m_hDC
);
2981 ATLASSERT(m_hDC
!= NULL
);
2982 return ::CloseFigure(m_hDC
);
2987 ATLASSERT(m_hDC
!= NULL
);
2988 return ::EndPath(m_hDC
);
2993 ATLASSERT(m_hDC
!= NULL
);
2994 return ::FillPath(m_hDC
);
2999 ATLASSERT(m_hDC
!= NULL
);
3000 return ::FlattenPath(m_hDC
);
3003 BOOL
StrokeAndFillPath()
3005 ATLASSERT(m_hDC
!= NULL
);
3006 return ::StrokeAndFillPath(m_hDC
);
3011 ATLASSERT(m_hDC
!= NULL
);
3012 return ::StrokePath(m_hDC
);
3017 ATLASSERT(m_hDC
!= NULL
);
3018 return ::WidenPath(m_hDC
);
3021 BOOL
GetMiterLimit(PFLOAT pfMiterLimit
) const
3023 ATLASSERT(m_hDC
!= NULL
);
3024 return ::GetMiterLimit(m_hDC
, pfMiterLimit
);
3027 BOOL
SetMiterLimit(float fMiterLimit
)
3029 ATLASSERT(m_hDC
!= NULL
);
3030 return ::SetMiterLimit(m_hDC
, fMiterLimit
, NULL
);
3033 int GetPath(LPPOINT lpPoints
, LPBYTE lpTypes
, int nCount
) const
3035 ATLASSERT(m_hDC
!= NULL
);
3036 return ::GetPath(m_hDC
, lpPoints
, lpTypes
, nCount
);
3039 BOOL
SelectClipPath(int nMode
)
3041 ATLASSERT(m_hDC
!= NULL
);
3042 return ::SelectClipPath(m_hDC
, nMode
);
3044 #endif // !_WIN32_WCE
3046 // Misc Helper Functions
3047 static CBrushHandle PASCAL
GetHalftoneBrush()
3049 HBRUSH halftoneBrush
= NULL
;
3050 WORD grayPattern
[8] = { 0 };
3051 for(int i
= 0; i
< 8; i
++)
3052 grayPattern
[i
] = (WORD
)(0x5555 << (i
& 1));
3053 HBITMAP grayBitmap
= CreateBitmap(8, 8, 1, 1, &grayPattern
);
3054 if(grayBitmap
!= NULL
)
3056 halftoneBrush
= ::CreatePatternBrush(grayBitmap
);
3057 DeleteObject(grayBitmap
);
3059 return CBrushHandle(halftoneBrush
);
3062 void DrawDragRect(LPCRECT lpRect
, SIZE size
, LPCRECT lpRectLast
, SIZE sizeLast
, HBRUSH hBrush
= NULL
, HBRUSH hBrushLast
= NULL
)
3064 // first, determine the update region and select it
3066 rgnOutside
.CreateRectRgnIndirect(lpRect
);
3067 RECT rect
= *lpRect
;
3068 ::InflateRect(&rect
, -size
.cx
, -size
.cy
);
3069 ::IntersectRect(&rect
, &rect
, lpRect
);
3071 rgnInside
.CreateRectRgnIndirect(&rect
);
3073 rgnNew
.CreateRectRgn(0, 0, 0, 0);
3074 rgnNew
.CombineRgn(rgnOutside
, rgnInside
, RGN_XOR
);
3076 HBRUSH hBrushOld
= NULL
;
3077 CBrush brushHalftone
;
3079 brushHalftone
= hBrush
= CDCHandle::GetHalftoneBrush();
3080 if(hBrushLast
== NULL
)
3081 hBrushLast
= hBrush
;
3085 if(lpRectLast
!= NULL
)
3087 // find difference between new region and old region
3088 rgnLast
.CreateRectRgn(0, 0, 0, 0);
3089 rgnOutside
.SetRectRgn(lpRectLast
->left
, lpRectLast
->top
, lpRectLast
->right
, lpRectLast
->bottom
);
3091 ::InflateRect(&rect
, -sizeLast
.cx
, -sizeLast
.cy
);
3092 ::IntersectRect(&rect
, &rect
, lpRectLast
);
3093 rgnInside
.SetRectRgn(rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3094 rgnLast
.CombineRgn(rgnOutside
, rgnInside
, RGN_XOR
);
3096 // only diff them if brushes are the same
3097 if(hBrush
== hBrushLast
)
3099 rgnUpdate
.CreateRectRgn(0, 0, 0, 0);
3100 rgnUpdate
.CombineRgn(rgnLast
, rgnNew
, RGN_XOR
);
3103 if(hBrush
!= hBrushLast
&& lpRectLast
!= NULL
)
3105 // brushes are different -- erase old region first
3106 SelectClipRgn(rgnLast
);
3108 hBrushOld
= SelectBrush(hBrushLast
);
3109 PatBlt(rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, PATINVERT
);
3110 SelectBrush(hBrushOld
);
3114 // draw into the update/new region
3115 SelectClipRgn(rgnUpdate
.IsNull() ? rgnNew
: rgnUpdate
);
3117 hBrushOld
= SelectBrush(hBrush
);
3118 PatBlt(rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, PATINVERT
);
3121 if(hBrushOld
!= NULL
)
3122 SelectBrush(hBrushOld
);
3123 SelectClipRgn(NULL
);
3126 void FillSolidRect(LPCRECT lpRect
, COLORREF clr
)
3128 ATLASSERT(m_hDC
!= NULL
);
3130 COLORREF clrOld
= ::SetBkColor(m_hDC
, clr
);
3131 ATLASSERT(clrOld
!= CLR_INVALID
);
3132 if(clrOld
!= CLR_INVALID
)
3134 ::ExtTextOut(m_hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
3135 ::SetBkColor(m_hDC
, clrOld
);
3139 void FillSolidRect(int x
, int y
, int cx
, int cy
, COLORREF clr
)
3141 ATLASSERT(m_hDC
!= NULL
);
3143 RECT rect
= { x
, y
, x
+ cx
, y
+ cy
};
3144 FillSolidRect(&rect
, clr
);
3147 void Draw3dRect(LPCRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
3149 Draw3dRect(lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
3150 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
3153 void Draw3dRect(int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
3155 FillSolidRect(x
, y
, cx
- 1, 1, clrTopLeft
);
3156 FillSolidRect(x
, y
, 1, cy
- 1, clrTopLeft
);
3157 FillSolidRect(x
+ cx
, y
, -1, cy
, clrBottomRight
);
3158 FillSolidRect(x
, y
+ cy
, cx
, -1, clrBottomRight
);
3162 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
3163 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
)
3165 ATLASSERT(m_hDC
!= NULL
);
3166 return ::SetDIBitsToDevice(m_hDC
, x
, y
, dwWidth
, dwHeight
, xSrc
, ySrc
, uStartScan
, cScanLines
, lpvBits
, lpbmi
, uColorUse
);
3168 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
3170 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
3171 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
)
3173 ATLASSERT(m_hDC
!= NULL
);
3174 return ::StretchDIBits(m_hDC
, x
, y
, nWidth
, nHeight
, xSrc
, ySrc
, nSrcWidth
, nSrcHeight
, lpvBits
, lpbmi
, uColorUse
, dwRop
);
3177 UINT
GetDIBColorTable(UINT uStartIndex
, UINT cEntries
, RGBQUAD
* pColors
) const
3179 ATLASSERT(m_hDC
!= NULL
);
3180 return ::GetDIBColorTable(m_hDC
, uStartIndex
, cEntries
, pColors
);
3183 UINT
SetDIBColorTable(UINT uStartIndex
, UINT cEntries
, CONST RGBQUAD
* pColors
)
3185 ATLASSERT(m_hDC
!= NULL
);
3186 return ::SetDIBColorTable(m_hDC
, uStartIndex
, cEntries
, pColors
);
3188 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
3191 #if !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
3192 int ChoosePixelFormat(CONST PIXELFORMATDESCRIPTOR
* ppfd
)
3194 ATLASSERT(m_hDC
!= NULL
);
3195 return ::ChoosePixelFormat(m_hDC
, ppfd
);
3198 int DescribePixelFormat(int iPixelFormat
, UINT nBytes
, LPPIXELFORMATDESCRIPTOR ppfd
)
3200 ATLASSERT(m_hDC
!= NULL
);
3201 return ::DescribePixelFormat(m_hDC
, iPixelFormat
, nBytes
, ppfd
);
3204 int GetPixelFormat() const
3206 ATLASSERT(m_hDC
!= NULL
);
3207 return ::GetPixelFormat(m_hDC
);
3210 BOOL
SetPixelFormat(int iPixelFormat
, CONST PIXELFORMATDESCRIPTOR
* ppfd
)
3212 ATLASSERT(m_hDC
!= NULL
);
3213 return ::SetPixelFormat(m_hDC
, iPixelFormat
, ppfd
);
3218 ATLASSERT(m_hDC
!= NULL
);
3219 return ::SwapBuffers(m_hDC
);
3222 HGLRC
wglCreateContext()
3224 ATLASSERT(m_hDC
!= NULL
);
3225 return ::wglCreateContext(m_hDC
);
3228 HGLRC
wglCreateLayerContext(int iLayerPlane
)
3230 ATLASSERT(m_hDC
!= NULL
);
3231 return ::wglCreateLayerContext(m_hDC
, iLayerPlane
);
3234 BOOL
wglMakeCurrent(HGLRC hglrc
)
3236 ATLASSERT(m_hDC
!= NULL
);
3237 return ::wglMakeCurrent(m_hDC
, hglrc
);
3240 BOOL
wglUseFontBitmaps(DWORD dwFirst
, DWORD dwCount
, DWORD listBase
)
3242 ATLASSERT(m_hDC
!= NULL
);
3243 return ::wglUseFontBitmaps(m_hDC
, dwFirst
, dwCount
, listBase
);
3246 BOOL
wglUseFontOutlines(DWORD dwFirst
, DWORD dwCount
, DWORD listBase
, FLOAT deviation
, FLOAT extrusion
, int format
, LPGLYPHMETRICSFLOAT lpgmf
)
3248 ATLASSERT(m_hDC
!= NULL
);
3249 return ::wglUseFontOutlines(m_hDC
, dwFirst
, dwCount
, listBase
, deviation
, extrusion
, format
, lpgmf
);
3252 BOOL
wglDescribeLayerPlane(int iPixelFormat
, int iLayerPlane
, UINT nBytes
, LPLAYERPLANEDESCRIPTOR plpd
)
3254 ATLASSERT(m_hDC
!= NULL
);
3255 return ::wglDescribeLayerPlane(m_hDC
, iPixelFormat
, iLayerPlane
, nBytes
, plpd
);
3258 int wglSetLayerPaletteEntries(int iLayerPlane
, int iStart
, int cEntries
, CONST COLORREF
* pclr
)
3260 ATLASSERT(m_hDC
!= NULL
);
3261 return ::wglSetLayerPaletteEntries(m_hDC
, iLayerPlane
, iStart
, cEntries
, pclr
);
3264 int wglGetLayerPaletteEntries(int iLayerPlane
, int iStart
, int cEntries
, COLORREF
* pclr
)
3266 ATLASSERT(m_hDC
!= NULL
);
3267 return ::wglGetLayerPaletteEntries(m_hDC
, iLayerPlane
, iStart
, cEntries
, pclr
);
3270 BOOL
wglRealizeLayerPalette(int iLayerPlane
, BOOL bRealize
)
3272 ATLASSERT(m_hDC
!= NULL
);
3273 return ::wglRealizeLayerPalette(m_hDC
, iLayerPlane
, bRealize
);
3276 BOOL
wglSwapLayerBuffers(UINT uPlanes
)
3278 ATLASSERT(m_hDC
!= NULL
);
3279 return ::wglSwapLayerBuffers(m_hDC
, uPlanes
);
3281 #endif // !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
3283 // New for Windows 2000 only
3284 #if (_WIN32_WINNT >= 0x0500)
3285 COLORREF
GetDCPenColor() const
3287 ATLASSERT(m_hDC
!= NULL
);
3288 return ::GetDCPenColor(m_hDC
);
3291 COLORREF
SetDCPenColor(COLORREF clr
)
3293 ATLASSERT(m_hDC
!= NULL
);
3294 return ::SetDCPenColor(m_hDC
, clr
);
3297 COLORREF
GetDCBrushColor() const
3299 ATLASSERT(m_hDC
!= NULL
);
3300 return ::GetDCBrushColor(m_hDC
);
3303 COLORREF
SetDCBrushColor(COLORREF clr
)
3305 ATLASSERT(m_hDC
!= NULL
);
3306 return ::SetDCBrushColor(m_hDC
, clr
);
3310 DWORD
GetFontUnicodeRanges(LPGLYPHSET lpgs
) const
3312 ATLASSERT(m_hDC
!= NULL
);
3313 return ::GetFontUnicodeRanges(m_hDC
, lpgs
);
3315 #endif // !_WIN32_WCE
3317 DWORD
GetGlyphIndices(LPCTSTR lpstr
, int cch
, LPWORD pgi
, DWORD dwFlags
) const
3319 ATLASSERT(m_hDC
!= NULL
);
3320 return ::GetGlyphIndices(m_hDC
, lpstr
, cch
, pgi
, dwFlags
);
3323 BOOL
GetTextExtentPointI(LPWORD pgiIn
, int cgi
, LPSIZE lpSize
) const
3325 ATLASSERT(m_hDC
!= NULL
);
3326 return ::GetTextExtentPointI(m_hDC
, pgiIn
, cgi
, lpSize
);
3329 BOOL
GetTextExtentExPointI(LPWORD pgiIn
, int cgi
, int nMaxExtent
, LPINT lpnFit
, LPINT alpDx
, LPSIZE lpSize
) const
3331 ATLASSERT(m_hDC
!= NULL
);
3332 return ::GetTextExtentExPointI(m_hDC
, pgiIn
, cgi
, nMaxExtent
, lpnFit
, alpDx
, lpSize
);
3335 BOOL
GetCharWidthI(UINT giFirst
, UINT cgi
, LPWORD pgi
, LPINT lpBuffer
) const
3337 ATLASSERT(m_hDC
!= NULL
);
3338 return ::GetCharWidthI(m_hDC
, giFirst
, cgi
, pgi
, lpBuffer
);
3341 BOOL
GetCharABCWidthsI(UINT giFirst
, UINT cgi
, LPWORD pgi
, LPABC lpabc
) const
3343 ATLASSERT(m_hDC
!= NULL
);
3344 return ::GetCharABCWidthsI(m_hDC
, giFirst
, cgi
, pgi
, lpabc
);
3346 #endif // (_WIN32_WINNT >= 0x0500)
3348 // New for Windows 2000 and Windows 98
3349 #if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
3350 BOOL
ColorCorrectPalette(HPALETTE hPalette
, DWORD dwFirstEntry
, DWORD dwNumOfEntries
)
3352 ATLASSERT(m_hDC
!= NULL
);
3353 return ::ColorCorrectPalette(m_hDC
, hPalette
, dwFirstEntry
, dwNumOfEntries
);
3355 #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
3358 typedef CDCT
<false> CDCHandle
;
3359 typedef CDCT
<true> CDC
;
3362 ///////////////////////////////////////////////////////////////////////////////
3365 class CPaintDC
: public CDC
3372 // Constructor/destructor
3375 ATLASSERT(::IsWindow(hWnd
));
3377 m_hDC
= ::BeginPaint(hWnd
, &m_ps
);
3382 ATLASSERT(m_hDC
!= NULL
);
3383 ATLASSERT(::IsWindow(m_hWnd
));
3384 ::EndPaint(m_hWnd
, &m_ps
);
3389 class CClientDC
: public CDC
3395 // Constructor/destructor
3396 CClientDC(HWND hWnd
)
3398 ATLASSERT(hWnd
== NULL
|| ::IsWindow(hWnd
));
3400 m_hDC
= ::GetDC(hWnd
);
3405 ATLASSERT(m_hDC
!= NULL
);
3406 ::ReleaseDC(m_hWnd
, Detach());
3410 class CWindowDC
: public CDC
3416 // Constructor/destructor
3417 CWindowDC(HWND hWnd
)
3419 ATLASSERT(hWnd
== NULL
|| ::IsWindow(hWnd
));
3421 m_hDC
= ::GetWindowDC(hWnd
);
3426 ATLASSERT(m_hDC
!= NULL
);
3427 ::ReleaseDC(m_hWnd
, Detach());
3431 class CMemoryDC
: public CDC
3440 // Constructor/destructor
3441 CMemoryDC(HDC hDC
, const RECT
& rcPaint
) : m_hDCOriginal(hDC
), m_hBmpOld(NULL
)
3443 m_rcPaint
= rcPaint
;
3444 CreateCompatibleDC(m_hDCOriginal
);
3445 ATLASSERT(m_hDC
!= NULL
);
3446 m_bmp
.CreateCompatibleBitmap(m_hDCOriginal
, m_rcPaint
.right
- m_rcPaint
.left
, m_rcPaint
.bottom
- m_rcPaint
.top
);
3447 ATLASSERT(m_bmp
.m_hBitmap
!= NULL
);
3448 m_hBmpOld
= SelectBitmap(m_bmp
);
3449 SetViewportOrg(-m_rcPaint
.left
, -m_rcPaint
.top
);
3454 ::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
);
3455 SelectBitmap(m_hBmpOld
);
3460 ///////////////////////////////////////////////////////////////////////////////
3461 // Enhanced metafile support
3465 class CEnhMetaFileInfo
3469 HENHMETAFILE m_hEMF
;
3472 ENHMETAHEADER m_header
;
3473 PIXELFORMATDESCRIPTOR m_pfd
;
3475 // Constructor/destructor
3476 CEnhMetaFileInfo(HENHMETAFILE hEMF
) : m_pBits(NULL
), m_pDesc(NULL
), m_hEMF(hEMF
)
3486 BYTE
* GetEnhMetaFileBits()
3488 ATLASSERT(m_hEMF
!= NULL
);
3489 UINT nBytes
= ::GetEnhMetaFileBits(m_hEMF
, 0, NULL
);
3492 ATLTRY(m_pBits
= new BYTE
[nBytes
]);
3493 if (m_pBits
!= NULL
)
3494 ::GetEnhMetaFileBits(m_hEMF
, nBytes
, m_pBits
);
3498 LPTSTR
GetEnhMetaFileDescription()
3500 ATLASSERT(m_hEMF
!= NULL
);
3501 UINT nLen
= ::GetEnhMetaFileDescription(m_hEMF
, 0, NULL
);
3504 ATLTRY(m_pDesc
= new TCHAR
[nLen
]);
3505 if (m_pDesc
!= NULL
)
3506 nLen
= ::GetEnhMetaFileDescription(m_hEMF
, nLen
, m_pDesc
);
3510 ENHMETAHEADER
* GetEnhMetaFileHeader()
3512 ATLASSERT(m_hEMF
!= NULL
);
3513 memset(&m_header
, 0, sizeof(m_header
));
3514 m_header
.iType
= EMR_HEADER
;
3515 m_header
.nSize
= sizeof(ENHMETAHEADER
);
3516 UINT n
= ::GetEnhMetaFileHeader(m_hEMF
, sizeof(ENHMETAHEADER
), &m_header
);
3517 return (n
!= 0) ? &m_header
: NULL
;
3520 PIXELFORMATDESCRIPTOR
* GetEnhMetaFilePixelFormat()
3522 ATLASSERT(m_hEMF
!= NULL
);
3523 memset(&m_pfd
, 0, sizeof(m_pfd
));
3524 UINT n
= ::GetEnhMetaFilePixelFormat(m_hEMF
, sizeof(m_pfd
), &m_pfd
);
3525 return (n
!= 0) ? &m_pfd
: NULL
;
3530 template <bool t_bManaged
>
3535 HENHMETAFILE m_hEMF
;
3537 // Constructor/destructor
3538 CEnhMetaFileT(HENHMETAFILE hEMF
= NULL
) : m_hEMF(hEMF
)
3544 if(t_bManaged
&& m_hEMF
!= NULL
)
3549 CEnhMetaFileT
<t_bManaged
>& operator =(HENHMETAFILE hEMF
)
3555 void Attach(HENHMETAFILE hEMF
)
3557 if(t_bManaged
&& m_hEMF
!= NULL
&& m_hEMF
!= hEMF
)
3562 HENHMETAFILE
Detach()
3564 HENHMETAFILE hEMF
= m_hEMF
;
3569 operator HENHMETAFILE() const { return m_hEMF
; }
3571 bool IsNull() const { return (m_hEMF
== NULL
); }
3575 ATLASSERT(m_hEMF
!= NULL
);
3576 BOOL bRet
= ::DeleteEnhMetaFile(m_hEMF
);
3581 UINT
GetEnhMetaFileBits(UINT cbBuffer
, LPBYTE lpbBuffer
) const
3583 ATLASSERT(m_hEMF
!= NULL
);
3584 return ::GetEnhMetaFileBits(m_hEMF
, cbBuffer
, lpbBuffer
);
3587 UINT
GetEnhMetaFileDescription(UINT cchBuffer
, LPTSTR lpszDescription
) const
3589 ATLASSERT(m_hEMF
!= NULL
);
3590 return ::GetEnhMetaFileDescription(m_hEMF
, cchBuffer
, lpszDescription
);
3593 UINT
GetEnhMetaFileHeader(LPENHMETAHEADER lpemh
) const
3595 ATLASSERT(m_hEMF
!= NULL
);
3596 lpemh
->iType
= EMR_HEADER
;
3597 lpemh
->nSize
= sizeof(ENHMETAHEADER
);
3598 return ::GetEnhMetaFileHeader(m_hEMF
, sizeof(ENHMETAHEADER
), lpemh
);
3601 UINT
GetEnhMetaFilePaletteEntries(UINT cEntries
, LPPALETTEENTRY lppe
) const
3603 ATLASSERT(m_hEMF
!= NULL
);
3604 return ::GetEnhMetaFilePaletteEntries(m_hEMF
, cEntries
, lppe
);
3607 UINT
GetEnhMetaFilePixelFormat(DWORD cbBuffer
, PIXELFORMATDESCRIPTOR
* ppfd
) const
3609 ATLASSERT(m_hEMF
!= NULL
);
3610 return ::GetEnhMetaFilePixelFormat(m_hEMF
, cbBuffer
, ppfd
);
3614 typedef CEnhMetaFileT
<false> CEnhMetaFileHandle
;
3615 typedef CEnhMetaFileT
<true> CEnhMetaFile
;
3618 class CEnhMetaFileDC
: public CDC
3621 // Constructor/destructor
3626 CEnhMetaFileDC(HDC hdc
, LPCRECT lpRect
)
3628 Create(hdc
, NULL
, lpRect
, NULL
);
3629 ATLASSERT(m_hDC
!= NULL
);
3632 CEnhMetaFileDC(HDC hdcRef
, LPCTSTR lpFilename
, LPCRECT lpRect
, LPCTSTR lpDescription
)
3634 Create(hdcRef
, lpFilename
, lpRect
, lpDescription
);
3635 ATLASSERT(m_hDC
!= NULL
);
3640 HENHMETAFILE hEMF
= Close();
3642 ::DeleteEnhMetaFile(hEMF
);
3646 void Create(HDC hdcRef
, LPCTSTR lpFilename
, LPCRECT lpRect
, LPCTSTR lpDescription
)
3648 ATLASSERT(m_hDC
== NULL
);
3649 m_hDC
= ::CreateEnhMetaFile(hdcRef
, lpFilename
, lpRect
, lpDescription
);
3652 HENHMETAFILE
Close()
3654 HENHMETAFILE hEMF
= NULL
;
3657 hEMF
= ::CloseEnhMetaFile(m_hDC
);
3664 #endif // !_WIN32_WCE
3667 ///////////////////////////////////////////////////////////////////////////////
3668 // WinCE compatible clipboard CF_DIB format support functions
3670 #ifndef _WTL_NO_DIB16
3672 #define DIBINFO16_BITFIELDS { 31744, 992, 31 }
3674 // DIBINFO16 - To avoid color table problems in WinCE we only create this type of Dib
3675 struct DIBINFO16
// a BITMAPINFO with 2 additional color bitfields
3677 BITMAPINFOHEADER bmiHeader
;
3678 RGBQUAD bmiColors
[3];
3680 DIBINFO16(SIZE size
)
3682 BITMAPINFOHEADER bmih
= { sizeof(BITMAPINFOHEADER
), size
.cx
, size
.cy
,
3683 1, 16, BI_BITFIELDS
, 2 * size
.cx
* size
.cy
, 0, 0, 3 };
3684 DWORD dw
[3] = DIBINFO16_BITFIELDS
;
3687 SecureHelper::memcpy_x(bmiColors
, sizeof(bmiColors
), dw
, 3 * sizeof(DWORD
));
3692 // AtlxxxDibxxx minimal packed DIB implementation and helpers to copy and paste CF_DIB
3694 inline bool AtlIsDib16(LPBITMAPINFOHEADER pbmih
)
3696 return (pbmih
->biBitCount
== 16) && (pbmih
->biCompression
== BI_BITFIELDS
);
3699 inline int AtlGetDibColorTableSize(LPBITMAPINFOHEADER pbmih
)
3701 switch (pbmih
->biBitCount
)
3706 return pbmih
->biClrUsed
? pbmih
->biClrUsed
: 1 << pbmih
->biBitCount
;
3711 return pbmih
->biCompression
== BI_BITFIELDS
? 3 : 0;
3713 ATLASSERT(FALSE
); // should never come here
3719 inline int AtlGetDibNumColors(LPBITMAPINFOHEADER pbmih
)
3721 switch (pbmih
->biBitCount
)
3726 if (pbmih
->biClrUsed
)
3727 return pbmih
->biClrUsed
;
3731 if (pbmih
->biCompression
== BI_BITFIELDS
)
3738 if (pbmih
->biCompression
== BI_BITFIELDS
)
3746 return 1 << pbmih
->biBitCount
;
3749 inline HBITMAP
AtlGetDibBitmap(LPBITMAPINFO pbmi
)
3754 LPBYTE pDibBits
= (LPBYTE
)pbmi
+ sizeof(BITMAPINFOHEADER
) + AtlGetDibColorTableSize(&pbmi
->bmiHeader
) * sizeof(RGBQUAD
);
3755 HBITMAP hbm
= CreateDIBSection(dc
, pbmi
, DIB_RGB_COLORS
, &pBits
, NULL
, NULL
);
3758 int cbBits
= pbmi
->bmiHeader
.biWidth
* pbmi
->bmiHeader
.biHeight
* pbmi
->bmiHeader
.biBitCount
/ 8;
3759 SecureHelper::memcpy_x(pBits
, cbBits
, pDibBits
, pbmi
->bmiHeader
.biSizeImage
);
3765 inline HBITMAP
AtlCopyBitmap(HBITMAP hbm
, SIZE sizeDst
, bool bAsBitmap
= false)
3767 CDC hdcSrc
= CreateCompatibleDC(NULL
);
3768 CDC hdcDst
= CreateCompatibleDC(NULL
);
3770 CBitmapHandle hbmOld
= NULL
, hbmOld2
= NULL
, bmSrc
= hbm
;
3772 CBitmap bmNew
= NULL
;
3774 SIZE sizeSrc
= { 0 };
3775 bmSrc
.GetSize(sizeSrc
);
3777 hbmOld
= hdcSrc
.SelectBitmap(bmSrc
);
3781 bmNew
.CreateCompatibleBitmap(hdcSrc
, sizeDst
.cx
, sizeDst
.cy
);
3785 DIBINFO16
dib16(sizeDst
);
3786 LPVOID pBits
= NULL
;
3787 bmNew
= CreateDIBSection(hdcDst
, (const BITMAPINFO
*)&dib16
, DIB_RGB_COLORS
, &pBits
, NULL
, NULL
);
3790 ATLASSERT(!bmNew
.IsNull());
3792 hbmOld2
= hdcDst
.SelectBitmap(bmNew
);
3795 if ((sizeDst
.cx
== sizeSrc
.cx
) && (sizeDst
.cy
== sizeSrc
.cy
))
3796 bOK
= hdcDst
.BitBlt(0, 0, sizeDst
.cx
, sizeDst
.cy
, hdcSrc
, 0, 0, SRCCOPY
);
3798 bOK
= hdcDst
.StretchBlt(0, 0, sizeDst
.cx
, sizeDst
.cy
, hdcSrc
, 0, 0, sizeSrc
.cx
, sizeSrc
.cy
, SRCCOPY
);
3800 hdcSrc
.SelectBitmap(hbmOld
);
3801 hdcDst
.SelectBitmap(hbmOld2
);
3804 bmNew
.DeleteObject();
3806 return bmNew
.Detach();
3809 inline HLOCAL
AtlCreatePackedDib16(HBITMAP hbm
, SIZE size
)
3811 DIBSECTION ds
= { 0 };
3813 bool bCopied
= false;
3815 bool bOK
= GetObject(hbm
, sizeof(ds
), &ds
) == sizeof(ds
);
3816 if ((bOK
== FALSE
) || (ds
.dsBm
.bmBits
== NULL
) || (AtlIsDib16(&ds
.dsBmih
) == FALSE
) ||
3817 (ds
.dsBmih
.biWidth
!= size
.cx
) || (ds
.dsBmih
.biHeight
!= size
.cy
))
3819 if ((hbm
= AtlCopyBitmap(hbm
, size
)) != NULL
)
3822 bOK
= GetObject(hbm
, sizeof(ds
), &ds
) == sizeof(ds
);
3830 if((bOK
!= FALSE
) && (AtlIsDib16(&ds
.dsBmih
) != FALSE
) && (ds
.dsBm
.bmBits
!= NULL
))
3832 pDib
= (LPBYTE
)LocalAlloc(LMEM_ZEROINIT
, sizeof(DIBINFO16
) + ds
.dsBmih
.biSizeImage
);
3835 SecureHelper::memcpy_x(pDib
, sizeof(DIBINFO16
) + ds
.dsBmih
.biSizeImage
, &ds
.dsBmih
, sizeof(DIBINFO16
));
3836 SecureHelper::memcpy_x(pDib
+ sizeof(DIBINFO16
), ds
.dsBmih
.biSizeImage
, ds
.dsBm
.bmBits
, ds
.dsBmih
.biSizeImage
);
3840 if (bCopied
== true)
3843 return (HLOCAL
)pDib
;
3846 inline bool AtlSetClipboardDib16(HBITMAP hbm
, SIZE size
, HWND hWnd
)
3848 ATLASSERT(::IsWindow(hWnd
));
3849 BOOL bOK
= OpenClipboard(hWnd
);
3852 bOK
= EmptyClipboard();
3855 HLOCAL hDib
= AtlCreatePackedDib16(hbm
, size
);
3858 bOK
= SetClipboardData(CF_DIB
, hDib
) != NULL
;
3870 return (bOK
!= FALSE
);
3873 inline HBITMAP
AtlGetClipboardDib(HWND hWnd
)
3875 ATLASSERT(::IsWindow(hWnd
) != FALSE
);
3877 if (OpenClipboard(hWnd
) != FALSE
)
3879 LPBITMAPINFO pbmi
= (LPBITMAPINFO
)GetClipboardData(CF_DIB
);
3881 hbm
= AtlGetDibBitmap(pbmi
);
3888 #endif // _WTL_NO_DIB16
3892 #endif // __ATLGDI_H__