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