yum-archive/TaSTT-Whisper
High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model
git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper
8c4603c
master
1// Windows Template Library - WTL version 10.0 2// Copyright (C) Microsoft Corporation, WTL Team. 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 Public License (http://opensource.org/licenses/MS-PL) 7// which can be found in the file MS-PL.txt at the root folder. 8 9#ifndef __ATLGDI_H__ 10#define __ATLGDI_H__ 11 12#pragma once 13 14#ifndef __ATLAPP_H__ 15#error atlgdi.h requires atlapp.h to be included first 16#endif 17 18 19// protect template members from windowsx.h macros 20#ifdef _INC_WINDOWSX 21#undef CopyRgn 22#undef CreateBrush 23#undef CreatePen 24#undef SelectBrush 25#undef SelectPen 26#undef SelectFont 27#undef SelectBitmap 28#endif // _INC_WINDOWSX 29 30// required libraries 31#pragma comment(lib, "msimg32.lib") 32#if !defined(_ATL_NO_OPENGL ) 33#pragma comment(lib, "opengl32.lib") 34#endif 35 36 37/////////////////////////////////////////////////////////////////////////////// 38// Classes in this file: 39// 40// CPenT<t_bManaged> 41// CBrushT<t_bManaged> 42// CLogFont 43// CFontT<t_bManaged> 44// CBitmapT<t_bManaged> 45// CPaletteT<t_bManaged> 46// CRgnT<t_bManaged> 47// CDCT<t_bManaged> 48// CPaintDC 49// CClientDC 50// CWindowDC 51// CMemoryDC 52// CEnhMetaFileInfo 53// CEnhMetaFileT<t_bManaged> 54// CEnhMetaFileDC 55 56 57namespace WTL 58{ 59 60/////////////////////////////////////////////////////////////////////////////// 61// Bitmap resource helpers to extract bitmap information for a bitmap resource 62 63inline LPBITMAPINFOHEADER AtlGetBitmapResourceInfo (HMODULE hModule ,ATL ::_U_STRINGorID image ) 64{ 65HRSRC hResource = ::FindResource (hModule ,image .m_lpstr ,RT_BITMAP ); 66ATLASSERT (hResource != NULL ); 67HGLOBAL hGlobal = ::LoadResource (hModule ,hResource ); 68ATLASSERT (hGlobal != NULL ); 69LPBITMAPINFOHEADER pBitmapInfoHeader = (LPBITMAPINFOHEADER )::LockResource (hGlobal ); 70ATLASSERT (pBitmapInfoHeader != NULL ); 71return pBitmapInfoHeader ; 72} 73 74inline WORD AtlGetBitmapResourceBitsPerPixel (HMODULE hModule ,ATL ::_U_STRINGorID image ) 75{ 76LPBITMAPINFOHEADER pBitmapInfoHeader = AtlGetBitmapResourceInfo (hModule ,image ); 77ATLASSERT (pBitmapInfoHeader != NULL ); 78return pBitmapInfoHeader -> biBitCount ; 79} 80 81inline WORD AtlGetBitmapResourceBitsPerPixel (ATL ::_U_STRINGorID image ) 82{ 83return AtlGetBitmapResourceBitsPerPixel (ModuleHelper ::GetResourceInstance (),image ); 84} 85 86/////////////////////////////////////////////////////////////////////////////// 87// 32-bit (alpha channel) bitmap resource helper 88 89// Note: 32-bit (alpha channel) images work only on Windows XP with Common Controls version 6. 90// If you want your app to work on older version of Windows, load non-alpha images if Common 91// Controls version is less than 6. 92 93inline bool AtlIsAlphaBitmapResource (ATL ::_U_STRINGorID image ) 94{ 95return (AtlGetBitmapResourceBitsPerPixel (image )== 32 ); 96} 97 98 99/////////////////////////////////////////////////////////////////////////////// 100// CPen 101 102template < bool t_bManaged > 103class CPenT 104{ 105public : 106// Data members 107HPEN m_hPen ; 108 109// Constructor/destructor/operators 110CPenT (HPEN hPen = NULL ) :m_hPen (hPen ) 111 { } 112 113 ~CPenT () 114 { 115if (t_bManaged && (m_hPen != NULL )) 116DeleteObject (); 117 } 118 119CPenT < t_bManaged >& operator = (HPEN hPen ) 120 { 121Attach (hPen ); 122return * this ; 123 } 124 125void Attach (HPEN hPen ) 126 { 127if (t_bManaged && (m_hPen != NULL )&& (m_hPen != hPen )) 128 ::DeleteObject (m_hPen ); 129m_hPen = hPen ; 130 } 131 132HPEN Detach () 133 { 134HPEN hPen = m_hPen ; 135m_hPen = NULL ; 136return hPen ; 137 } 138 139operator HPEN ()const {return m_hPen ; } 140 141bool IsNull ()const {return (m_hPen == NULL ); } 142 143// Create methods 144HPEN CreatePen (int nPenStyle ,int nWidth ,COLORREF crColor ) 145 { 146ATLASSERT (m_hPen == NULL ); 147m_hPen = ::CreatePen (nPenStyle ,nWidth ,crColor ); 148return m_hPen ; 149 } 150 151HPEN CreatePen (int nPenStyle ,int nWidth ,const LOGBRUSH * pLogBrush ,int nStyleCount = 0 ,const DWORD * lpStyle = NULL ) 152 { 153ATLASSERT (m_hPen == NULL ); 154m_hPen = ::ExtCreatePen (nPenStyle ,nWidth ,pLogBrush ,nStyleCount ,lpStyle ); 155return m_hPen ; 156 } 157 158HPEN CreatePenIndirect (LPLOGPEN lpLogPen ) 159 { 160ATLASSERT (m_hPen == NULL ); 161m_hPen = ::CreatePenIndirect (lpLogPen ); 162return m_hPen ; 163 } 164 165BOOL DeleteObject () 166 { 167ATLASSERT (m_hPen != NULL ); 168BOOL bRet = ::DeleteObject (m_hPen ); 169if (bRet ) 170m_hPen = NULL ; 171return bRet ; 172 } 173 174// Attributes 175int GetLogPen (LOGPEN * pLogPen )const 176 { 177ATLASSERT (m_hPen != NULL ); 178return ::GetObject (m_hPen ,sizeof (LOGPEN ),pLogPen ); 179 } 180 181bool GetLogPen (LOGPEN & LogPen )const 182 { 183ATLASSERT (m_hPen != NULL ); 184return (::GetObject (m_hPen ,sizeof (LOGPEN ),& LogPen )== sizeof (LOGPEN )); 185 } 186 187int GetExtLogPen (EXTLOGPEN * pLogPen ,int nSize = sizeof (EXTLOGPEN ))const 188 { 189ATLASSERT (m_hPen != NULL ); 190return ::GetObject (m_hPen ,nSize ,pLogPen ); 191 } 192 193bool GetExtLogPen (EXTLOGPEN & ExtLogPen ,int nSize = sizeof (EXTLOGPEN ))const 194 { 195ATLASSERT (m_hPen != NULL ); 196int nRet = ::GetObject (m_hPen ,nSize ,& ExtLogPen ); 197return ((nRet > 0 )&& (nRet <=nSize )); 198 } 199}; 200 201typedef CPenT < false> CPenHandle ; 202typedef CPenT < true> CPen ; 203 204 205/////////////////////////////////////////////////////////////////////////////// 206// CBrush 207 208template < bool t_bManaged > 209class CBrushT 210{ 211public : 212// Data members 213HBRUSH m_hBrush ; 214 215// Constructor/destructor/operators 216CBrushT (HBRUSH hBrush = NULL ) :m_hBrush (hBrush ) 217 { } 218 219 ~CBrushT () 220 { 221if (t_bManaged && (m_hBrush != NULL )) 222DeleteObject (); 223 } 224 225CBrushT < t_bManaged >& operator = (HBRUSH hBrush ) 226 { 227Attach (hBrush ); 228return * this ; 229 } 230 231void Attach (HBRUSH hBrush ) 232 { 233if (t_bManaged && (m_hBrush != NULL )&& (m_hBrush != hBrush )) 234 ::DeleteObject (m_hBrush ); 235m_hBrush = hBrush ; 236 } 237 238HBRUSH Detach () 239 { 240HBRUSH hBrush = m_hBrush ; 241m_hBrush = NULL ; 242return hBrush ; 243 } 244 245operator HBRUSH ()const {return m_hBrush ; } 246 247bool IsNull ()const {return (m_hBrush == NULL ); } 248 249// Create methods 250HBRUSH CreateSolidBrush (COLORREF crColor ) 251 { 252ATLASSERT (m_hBrush == NULL ); 253m_hBrush = ::CreateSolidBrush (crColor ); 254return m_hBrush ; 255 } 256 257HBRUSH CreateHatchBrush (int nIndex ,COLORREF crColor ) 258 { 259ATLASSERT (m_hBrush == NULL ); 260m_hBrush = ::CreateHatchBrush (nIndex ,crColor ); 261return m_hBrush ; 262 } 263 264HBRUSH CreateBrushIndirect (const LOGBRUSH * lpLogBrush ) 265 { 266ATLASSERT (m_hBrush == NULL ); 267m_hBrush = ::CreateBrushIndirect (lpLogBrush ); 268return m_hBrush ; 269 } 270 271HBRUSH CreatePatternBrush (HBITMAP hBitmap ) 272 { 273ATLASSERT (m_hBrush == NULL ); 274m_hBrush = ::CreatePatternBrush (hBitmap ); 275return m_hBrush ; 276 } 277 278HBRUSH CreateDIBPatternBrush (HGLOBAL hPackedDIB ,UINT nUsage ) 279 { 280ATLASSERT (hPackedDIB != NULL ); 281const void * lpPackedDIB = GlobalLock (hPackedDIB ); 282ATLASSERT (lpPackedDIB != NULL ); 283m_hBrush = ::CreateDIBPatternBrushPt (lpPackedDIB ,nUsage ); 284GlobalUnlock (hPackedDIB ); 285return m_hBrush ; 286 } 287 288HBRUSH CreateDIBPatternBrush (const void * lpPackedDIB ,UINT nUsage ) 289 { 290ATLASSERT (m_hBrush == NULL ); 291m_hBrush = ::CreateDIBPatternBrushPt (lpPackedDIB ,nUsage ); 292return m_hBrush ; 293 } 294 295HBRUSH CreateSysColorBrush (int nIndex ) 296 { 297ATLASSERT (m_hBrush == NULL ); 298m_hBrush = ::GetSysColorBrush (nIndex ); 299return m_hBrush ; 300 } 301 302BOOL DeleteObject () 303 { 304ATLASSERT (m_hBrush != NULL ); 305BOOL bRet = ::DeleteObject (m_hBrush ); 306if (bRet ) 307m_hBrush = NULL ; 308return bRet ; 309 } 310 311// Attributes 312int GetLogBrush (LOGBRUSH * pLogBrush )const 313 { 314ATLASSERT (m_hBrush != NULL ); 315return ::GetObject (m_hBrush ,sizeof (LOGBRUSH ),pLogBrush ); 316 } 317 318bool GetLogBrush (LOGBRUSH & LogBrush )const 319 { 320ATLASSERT (m_hBrush != NULL ); 321return (::GetObject (m_hBrush ,sizeof (LOGBRUSH ),& LogBrush )== sizeof (LOGBRUSH )); 322 } 323}; 324 325typedef CBrushT < false> CBrushHandle ; 326typedef CBrushT < true> CBrush ; 327 328 329/////////////////////////////////////////////////////////////////////////////// 330// CFont 331 332class CLogFont :public LOGFONT 333{ 334public : 335CLogFont () 336 { 337memset (this ,0 ,sizeof (LOGFONT )); 338 } 339 340CLogFont (const LOGFONT & lf ) 341 { 342Copy (& lf ); 343 } 344 345CLogFont (HFONT hFont ) 346 { 347ATLASSERT (::GetObjectType (hFont )== OBJ_FONT ); 348 ::GetObject (hFont ,sizeof (LOGFONT ), (LOGFONT * )this ); 349 } 350 351HFONT CreateFontIndirect () 352 { 353return ::CreateFontIndirect (this ); 354 } 355 356void SetBold () 357 { 358lfWeight = FW_BOLD ; 359 } 360 361bool IsBold ()const 362 { 363return (lfWeight >=FW_BOLD ); 364 } 365 366void MakeBolder (int iScale = 1 ) 367 { 368lfWeight += FW_BOLD * iScale ; 369 } 370 371void MakeLarger (int iScale ) 372 { 373if (lfHeight > 0 ) 374lfHeight += iScale ; 375else 376lfHeight -= iScale ; 377 } 378 379void SetHeight (LONG nPointSize ,HDC hDC = NULL ) 380 { 381HDC hDC1 = (hDC != NULL ) ?hDC : ::GetDC (NULL ); 382// For MM_TEXT mapping mode 383lfHeight = - ::MulDiv (nPointSize , ::GetDeviceCaps (hDC1 ,LOGPIXELSY ),72 ); 384if (hDC == NULL ) 385 ::ReleaseDC (NULL ,hDC1 ); 386 } 387 388LONG GetHeight (HDC hDC = NULL )const 389 { 390HDC hDC1 = (hDC != NULL ) ?hDC : ::GetDC (NULL ); 391// For MM_TEXT mapping mode 392LONG nPointSize = ::MulDiv (- lfHeight ,72 , ::GetDeviceCaps (hDC1 ,LOGPIXELSY )); 393if (hDC == NULL ) 394 ::ReleaseDC (NULL ,hDC1 ); 395 396return nPointSize ; 397 } 398 399LONG GetDeciPointHeight (HDC hDC = NULL )const 400 { 401HDC hDC1 = (hDC != NULL ) ?hDC : ::GetDC (NULL ); 402POINT ptOrg = {0 ,0 }; 403 ::DPtoLP (hDC1 ,& ptOrg ,1 ); 404POINT pt = {0 ,0 }; 405pt .y = abs (lfHeight )+ ptOrg .y ; 406 ::LPtoDP (hDC1 ,& pt ,1 ); 407LONG nDeciPoint = ::MulDiv (pt .y ,720 , ::GetDeviceCaps (hDC1 ,LOGPIXELSY ));// 72 points/inch, 10 decipoints/point 408if (hDC == NULL ) 409 ::ReleaseDC (NULL ,hDC1 ); 410 411return nDeciPoint ; 412 } 413 414void SetHeightFromDeciPoint (LONG nDeciPtHeight ,HDC hDC = NULL ) 415 { 416HDC hDC1 = (hDC != NULL ) ?hDC : ::GetDC (NULL ); 417POINT pt = {0 ,0 }; 418pt .y = ::MulDiv (::GetDeviceCaps (hDC1 ,LOGPIXELSY ),nDeciPtHeight ,720 );// 72 points/inch, 10 decipoints/point 419 ::DPtoLP (hDC1 ,& pt ,1 ); 420POINT ptOrg = {0 ,0 }; 421 ::DPtoLP (hDC1 ,& ptOrg ,1 ); 422lfHeight = - abs (pt .y - ptOrg .y ); 423if (hDC == NULL ) 424 ::ReleaseDC (NULL ,hDC1 ); 425 } 426 427void SetCaptionFont () 428 { 429NONCLIENTMETRICS ncm = {RunTimeHelper ::SizeOf_NONCLIENTMETRICS () }; 430ATLVERIFY (::SystemParametersInfo (SPI_GETNONCLIENTMETRICS ,sizeof (ncm ),& ncm ,0 )); 431Copy (& ncm .lfCaptionFont ); 432 } 433 434void SetMenuFont () 435 { 436NONCLIENTMETRICS ncm = {RunTimeHelper ::SizeOf_NONCLIENTMETRICS () }; 437ATLVERIFY (::SystemParametersInfo (SPI_GETNONCLIENTMETRICS ,sizeof (ncm ),& ncm ,0 )); 438Copy (& ncm .lfMenuFont ); 439 } 440 441void SetStatusFont () 442 { 443NONCLIENTMETRICS ncm = {RunTimeHelper ::SizeOf_NONCLIENTMETRICS () }; 444ATLVERIFY (::SystemParametersInfo (SPI_GETNONCLIENTMETRICS ,sizeof (ncm ),& ncm ,0 )); 445Copy (& ncm .lfStatusFont ); 446 } 447 448void SetMessageBoxFont () 449 { 450NONCLIENTMETRICS ncm = {RunTimeHelper ::SizeOf_NONCLIENTMETRICS () }; 451ATLVERIFY (::SystemParametersInfo (SPI_GETNONCLIENTMETRICS ,sizeof (ncm ),& ncm ,0 )); 452Copy (& ncm .lfMessageFont ); 453 } 454 455void Copy (const LOGFONT * pLogFont ) 456 { 457ATLASSERT (pLogFont != NULL ); 458* (LOGFONT * )this = * pLogFont ; 459 } 460 461CLogFont & operator = (const CLogFont & src ) 462 { 463Copy (& src ); 464return * this ; 465 } 466 467CLogFont & operator = (const LOGFONT & src ) 468 { 469Copy (& src ); 470return * this ; 471 } 472 473CLogFont & operator = (HFONT hFont ) 474 { 475ATLASSERT (::GetObjectType (hFont )== OBJ_FONT ); 476 ::GetObject (hFont ,sizeof (LOGFONT ), (LOGFONT * )this ); 477return * this ; 478 } 479 480bool operator == (const LOGFONT & logfont )const 481 { 482return ((logfont .lfHeight == lfHeight )&& 483 (logfont .lfWidth == lfWidth )&& 484 (logfont .lfEscapement == lfEscapement )&& 485 (logfont .lfOrientation == lfOrientation )&& 486 (logfont .lfWeight == lfWeight )&& 487 (logfont .lfItalic == lfItalic )&& 488 (logfont .lfUnderline == lfUnderline )&& 489 (logfont .lfStrikeOut == lfStrikeOut )&& 490 (logfont .lfCharSet == lfCharSet )&& 491 (logfont .lfOutPrecision == lfOutPrecision )&& 492 (logfont .lfClipPrecision == lfClipPrecision )&& 493 (logfont .lfQuality == lfQuality )&& 494 (logfont .lfPitchAndFamily == lfPitchAndFamily )&& 495 (lstrcmp (logfont .lfFaceName ,lfFaceName )== 0 )); 496 } 497}; 498 499 500template < bool t_bManaged > 501class CFontT 502{ 503public : 504// Data members 505HFONT m_hFont ; 506 507// Constructor/destructor/operators 508CFontT (HFONT hFont = NULL ) :m_hFont (hFont ) 509 { } 510 511 ~CFontT () 512 { 513if (t_bManaged && (m_hFont != NULL )) 514DeleteObject (); 515 } 516 517CFontT < t_bManaged >& operator = (HFONT hFont ) 518 { 519Attach (hFont ); 520return * this ; 521 } 522 523void Attach (HFONT hFont ) 524 { 525if (t_bManaged && (m_hFont != NULL )&& (m_hFont != hFont )) 526 ::DeleteObject (m_hFont ); 527m_hFont = hFont ; 528 } 529 530HFONT Detach () 531 { 532HFONT hFont = m_hFont ; 533m_hFont = NULL ; 534return hFont ; 535 } 536 537operator HFONT ()const {return m_hFont ; } 538 539bool IsNull ()const {return (m_hFont == NULL ); } 540 541// Create methods 542HFONT CreateFontIndirect (const LOGFONT * lpLogFont ) 543 { 544ATLASSERT (m_hFont == NULL ); 545m_hFont = ::CreateFontIndirect (lpLogFont ); 546return m_hFont ; 547 } 548 549HFONT CreateFontIndirectEx (CONST ENUMLOGFONTEXDV * penumlfex ) 550 { 551ATLASSERT (m_hFont == NULL ); 552m_hFont = ::CreateFontIndirectEx (penumlfex ); 553return m_hFont ; 554 } 555 556HFONT CreateFont (int nHeight ,int nWidth ,int nEscapement , 557int nOrientation ,int nWeight ,BYTE bItalic ,BYTE bUnderline , 558BYTE cStrikeOut ,BYTE nCharSet ,BYTE nOutPrecision , 559BYTE nClipPrecision ,BYTE nQuality ,BYTE nPitchAndFamily , 560LPCTSTR lpszFacename ) 561 { 562ATLASSERT (m_hFont == NULL ); 563m_hFont = ::CreateFont (nHeight ,nWidth ,nEscapement , 564nOrientation ,nWeight ,bItalic ,bUnderline ,cStrikeOut , 565nCharSet ,nOutPrecision ,nClipPrecision ,nQuality , 566nPitchAndFamily ,lpszFacename ); 567return m_hFont ; 568 } 569 570HFONT CreatePointFont (int nPointSize ,LPCTSTR lpszFaceName ,HDC hDC = NULL ,bool bBold = false,bool bItalic = false) 571 { 572LOGFONT logFont = {}; 573logFont .lfCharSet = DEFAULT_CHARSET ; 574logFont .lfHeight = nPointSize ; 575ATL ::Checked ::tcsncpy_s (logFont .lfFaceName ,_countof (logFont .lfFaceName ),lpszFaceName ,_TRUNCATE ); 576 577if (bBold ) 578logFont .lfWeight = FW_BOLD ; 579if (bItalic ) 580logFont .lfItalic = (BYTE )TRUE; 581 582return CreatePointFontIndirect (& logFont ,hDC ); 583 } 584 585HFONT CreatePointFontIndirect (const LOGFONT * lpLogFont ,HDC hDC = NULL ) 586 { 587HDC hDC1 = (hDC != NULL ) ?hDC : ::GetDC (NULL ); 588 589// convert nPointSize to logical units based on hDC 590LOGFONT logFont = * lpLogFont ; 591POINT pt = {0 ,0 }; 592pt .y = ::MulDiv (::GetDeviceCaps (hDC1 ,LOGPIXELSY ),logFont .lfHeight ,720 );// 72 points/inch, 10 decipoints/point 593 ::DPtoLP (hDC1 ,& pt ,1 ); 594POINT ptOrg = {0 ,0 }; 595 ::DPtoLP (hDC1 ,& ptOrg ,1 ); 596logFont .lfHeight = - abs (pt .y - ptOrg .y ); 597 598if (hDC == NULL ) 599 ::ReleaseDC (NULL ,hDC1 ); 600 601return CreateFontIndirect (& logFont ); 602 } 603 604BOOL DeleteObject () 605 { 606ATLASSERT (m_hFont != NULL ); 607BOOL bRet = ::DeleteObject (m_hFont ); 608if (bRet ) 609m_hFont = NULL ; 610return bRet ; 611 } 612 613// Attributes 614int GetLogFont (LOGFONT * pLogFont )const 615 { 616ATLASSERT (m_hFont != NULL ); 617return ::GetObject (m_hFont ,sizeof (LOGFONT ),pLogFont ); 618 } 619 620bool GetLogFont (LOGFONT & LogFont )const 621 { 622ATLASSERT (m_hFont != NULL ); 623return (::GetObject (m_hFont ,sizeof (LOGFONT ),& LogFont )== sizeof (LOGFONT )); 624 } 625}; 626 627typedef CFontT < false> CFontHandle ; 628typedef CFontT < true> CFont ; 629 630 631/////////////////////////////////////////////////////////////////////////////// 632// CBitmap 633 634template < bool t_bManaged > 635class CBitmapT 636{ 637public : 638// Data members 639HBITMAP m_hBitmap ; 640 641// Constructor/destructor/operators 642CBitmapT (HBITMAP hBitmap = NULL ) :m_hBitmap (hBitmap ) 643 { } 644 645 ~CBitmapT () 646 { 647if (t_bManaged && (m_hBitmap != NULL )) 648DeleteObject (); 649 } 650 651CBitmapT < t_bManaged >& operator = (HBITMAP hBitmap ) 652 { 653Attach (hBitmap ); 654return * this ; 655 } 656 657void Attach (HBITMAP hBitmap ) 658 { 659if (t_bManaged && (m_hBitmap != NULL )&& (m_hBitmap != hBitmap )) 660 ::DeleteObject (m_hBitmap ); 661m_hBitmap = hBitmap ; 662 } 663 664HBITMAP Detach () 665 { 666HBITMAP hBitmap = m_hBitmap ; 667m_hBitmap = NULL ; 668return hBitmap ; 669 } 670 671operator HBITMAP ()const {return m_hBitmap ; } 672 673bool IsNull ()const {return (m_hBitmap == NULL ); } 674 675// Create and load methods 676HBITMAP LoadBitmap (ATL ::_U_STRINGorID bitmap ) 677 { 678ATLASSERT (m_hBitmap == NULL ); 679m_hBitmap = ::LoadBitmap (ModuleHelper ::GetResourceInstance (),bitmap .m_lpstr ); 680return m_hBitmap ; 681 } 682 683HBITMAP LoadOEMBitmap (UINT nIDBitmap )// for OBM_/OCR_/OIC_ 684 { 685ATLASSERT (m_hBitmap == NULL ); 686m_hBitmap = ::LoadBitmap (NULL ,MAKEINTRESOURCE (nIDBitmap )); 687return m_hBitmap ; 688 } 689 690HBITMAP LoadMappedBitmap (UINT nIDBitmap ,UINT nFlags = 0 ,LPCOLORMAP lpColorMap = NULL ,int nMapSize = 0 ) 691 { 692ATLASSERT (m_hBitmap == NULL ); 693m_hBitmap = ::CreateMappedBitmap (ModuleHelper ::GetResourceInstance (),nIDBitmap , (WORD )nFlags ,lpColorMap ,nMapSize ); 694return m_hBitmap ; 695 } 696 697HBITMAP CreateBitmap (int nWidth ,int nHeight ,UINT nPlanes ,UINT nBitsPerPixel ,const void * lpBits ) 698 { 699ATLASSERT (m_hBitmap == NULL ); 700m_hBitmap = ::CreateBitmap (nWidth ,nHeight ,nPlanes ,nBitsPerPixel ,lpBits ); 701return m_hBitmap ; 702 } 703 704HBITMAP CreateBitmapIndirect (LPBITMAP lpBitmap ) 705 { 706ATLASSERT (m_hBitmap == NULL ); 707m_hBitmap = ::CreateBitmapIndirect (lpBitmap ); 708return m_hBitmap ; 709 } 710 711HBITMAP CreateCompatibleBitmap (HDC hDC ,int nWidth ,int nHeight ) 712 { 713ATLASSERT (m_hBitmap == NULL ); 714m_hBitmap = ::CreateCompatibleBitmap (hDC ,nWidth ,nHeight ); 715return m_hBitmap ; 716 } 717 718HBITMAP CreateDiscardableBitmap (HDC hDC ,int nWidth ,int nHeight ) 719 { 720ATLASSERT (m_hBitmap == NULL ); 721m_hBitmap = ::CreateDiscardableBitmap (hDC ,nWidth ,nHeight ); 722return m_hBitmap ; 723 } 724 725BOOL DeleteObject () 726 { 727ATLASSERT (m_hBitmap != NULL ); 728BOOL bRet = ::DeleteObject (m_hBitmap ); 729if (bRet ) 730m_hBitmap = NULL ; 731return bRet ; 732 } 733 734// Attributes 735int GetBitmap (BITMAP * pBitMap )const 736 { 737ATLASSERT (m_hBitmap != NULL ); 738return ::GetObject (m_hBitmap ,sizeof (BITMAP ),pBitMap ); 739 } 740 741bool GetBitmap (BITMAP & bm )const 742 { 743ATLASSERT (m_hBitmap != NULL ); 744return (::GetObject (m_hBitmap ,sizeof (BITMAP ),& bm )== sizeof (BITMAP )); 745 } 746 747bool GetSize (SIZE & size )const 748 { 749ATLASSERT (m_hBitmap != NULL ); 750BITMAP bm = {}; 751if (!GetBitmap (& bm )) 752return false; 753size .cx = bm .bmWidth ; 754size .cy = bm .bmHeight ; 755return true; 756 } 757 758DWORD GetBitmapBits (DWORD dwCount ,LPVOID lpBits )const 759 { 760ATLASSERT (m_hBitmap != NULL ); 761return ::GetBitmapBits (m_hBitmap ,dwCount ,lpBits ); 762 } 763 764DWORD SetBitmapBits (DWORD dwCount ,const void * lpBits ) 765 { 766ATLASSERT (m_hBitmap != NULL ); 767return ::SetBitmapBits (m_hBitmap ,dwCount ,lpBits ); 768 } 769 770BOOL GetBitmapDimension (LPSIZE lpSize )const 771 { 772ATLASSERT (m_hBitmap != NULL ); 773return ::GetBitmapDimensionEx (m_hBitmap ,lpSize ); 774 } 775 776BOOL SetBitmapDimension (int nWidth ,int nHeight ,LPSIZE lpSize = NULL ) 777 { 778ATLASSERT (m_hBitmap != NULL ); 779return ::SetBitmapDimensionEx (m_hBitmap ,nWidth ,nHeight ,lpSize ); 780 } 781 782// DIB support 783HBITMAP CreateDIBitmap (HDC hDC ,CONST BITMAPINFOHEADER * lpbmih ,DWORD dwInit ,CONST VOID * lpbInit ,CONST BITMAPINFO * lpbmi ,UINT uColorUse ) 784 { 785ATLASSERT (m_hBitmap == NULL ); 786m_hBitmap = ::CreateDIBitmap (hDC ,lpbmih ,dwInit ,lpbInit ,lpbmi ,uColorUse ); 787return m_hBitmap ; 788 } 789 790HBITMAP CreateDIBSection (HDC hDC ,CONST BITMAPINFO * lpbmi ,UINT uColorUse ,VOID ** ppvBits ,HANDLE hSection ,DWORD dwOffset ) 791 { 792ATLASSERT (m_hBitmap == NULL ); 793m_hBitmap = ::CreateDIBSection (hDC ,lpbmi ,uColorUse ,ppvBits ,hSection ,dwOffset ); 794return m_hBitmap ; 795 } 796 797int GetDIBits (HDC hDC ,UINT uStartScan ,UINT cScanLines ,LPVOID lpvBits ,LPBITMAPINFO lpbmi ,UINT uColorUse )const 798 { 799ATLASSERT (m_hBitmap != NULL ); 800return ::GetDIBits (hDC ,m_hBitmap ,uStartScan ,cScanLines ,lpvBits ,lpbmi ,uColorUse ); 801 } 802 803int SetDIBits (HDC hDC ,UINT uStartScan ,UINT cScanLines ,CONST VOID * lpvBits ,CONST BITMAPINFO * lpbmi ,UINT uColorUse ) 804 { 805ATLASSERT (m_hBitmap != NULL ); 806return ::SetDIBits (hDC ,m_hBitmap ,uStartScan ,cScanLines ,lpvBits ,lpbmi ,uColorUse ); 807 } 808}; 809 810typedef CBitmapT < false> CBitmapHandle ; 811typedef CBitmapT < true> CBitmap ; 812 813 814/////////////////////////////////////////////////////////////////////////////// 815// CPalette 816 817template < bool t_bManaged > 818class CPaletteT 819{ 820public : 821// Data members 822HPALETTE m_hPalette ; 823 824// Constructor/destructor/operators 825CPaletteT (HPALETTE hPalette = NULL ) :m_hPalette (hPalette ) 826 { } 827 828 ~CPaletteT () 829 { 830if (t_bManaged && (m_hPalette != NULL )) 831DeleteObject (); 832 } 833 834CPaletteT < t_bManaged >& operator = (HPALETTE hPalette ) 835 { 836Attach (hPalette ); 837return * this ; 838 } 839 840void Attach (HPALETTE hPalette ) 841 { 842if (t_bManaged && (m_hPalette != NULL )&& (m_hPalette != hPalette )) 843 ::DeleteObject (m_hPalette ); 844m_hPalette = hPalette ; 845 } 846 847HPALETTE Detach () 848 { 849HPALETTE hPalette = m_hPalette ; 850m_hPalette = NULL ; 851return hPalette ; 852 } 853 854operator HPALETTE ()const {return m_hPalette ; } 855 856bool IsNull ()const {return (m_hPalette == NULL ); } 857 858// Create methods 859HPALETTE CreatePalette (LPLOGPALETTE lpLogPalette ) 860 { 861ATLASSERT (m_hPalette == NULL ); 862m_hPalette = ::CreatePalette (lpLogPalette ); 863return m_hPalette ; 864 } 865 866HPALETTE CreateHalftonePalette (HDC hDC ) 867 { 868ATLASSERT (m_hPalette == NULL ); 869ATLASSERT (hDC != NULL ); 870m_hPalette = ::CreateHalftonePalette (hDC ); 871return m_hPalette ; 872 } 873 874BOOL DeleteObject () 875 { 876ATLASSERT (m_hPalette != NULL ); 877BOOL bRet = ::DeleteObject (m_hPalette ); 878if (bRet ) 879m_hPalette = NULL ; 880return bRet ; 881 } 882 883// Attributes 884int GetEntryCount ()const 885 { 886ATLASSERT (m_hPalette != NULL ); 887WORD nEntries = 0 ; 888 ::GetObject (m_hPalette ,sizeof (WORD ),& nEntries ); 889return (int )nEntries ; 890 } 891 892UINT GetPaletteEntries (UINT nStartIndex ,UINT nNumEntries ,LPPALETTEENTRY lpPaletteColors )const 893 { 894ATLASSERT (m_hPalette != NULL ); 895return ::GetPaletteEntries (m_hPalette ,nStartIndex ,nNumEntries ,lpPaletteColors ); 896 } 897 898UINT SetPaletteEntries (UINT nStartIndex ,UINT nNumEntries ,LPPALETTEENTRY lpPaletteColors ) 899 { 900ATLASSERT (m_hPalette != NULL ); 901return ::SetPaletteEntries (m_hPalette ,nStartIndex ,nNumEntries ,lpPaletteColors ); 902 } 903 904// Operations 905void AnimatePalette (UINT nStartIndex ,UINT nNumEntries ,LPPALETTEENTRY lpPaletteColors ) 906 { 907ATLASSERT (m_hPalette != NULL ); 908 ::AnimatePalette (m_hPalette ,nStartIndex ,nNumEntries ,lpPaletteColors ); 909 } 910 911BOOL ResizePalette (UINT nNumEntries ) 912 { 913ATLASSERT (m_hPalette != NULL ); 914return ::ResizePalette (m_hPalette ,nNumEntries ); 915 } 916 917UINT GetNearestPaletteIndex (COLORREF crColor )const 918 { 919ATLASSERT (m_hPalette != NULL ); 920return ::GetNearestPaletteIndex (m_hPalette ,crColor ); 921 } 922}; 923 924typedef CPaletteT < false> CPaletteHandle ; 925typedef CPaletteT < true> CPalette ; 926 927 928/////////////////////////////////////////////////////////////////////////////// 929// CRgn 930 931template < bool t_bManaged > 932class CRgnT 933{ 934public : 935// Data members 936HRGN m_hRgn ; 937 938// Constructor/destructor/operators 939CRgnT (HRGN hRgn = NULL ) :m_hRgn (hRgn ) 940 { } 941 942 ~CRgnT () 943 { 944if (t_bManaged && (m_hRgn != NULL )) 945DeleteObject (); 946 } 947 948CRgnT < t_bManaged >& operator = (HRGN hRgn ) 949 { 950Attach (hRgn ); 951return * this ; 952 } 953 954void Attach (HRGN hRgn ) 955 { 956if (t_bManaged && (m_hRgn != NULL )&& (m_hRgn != hRgn )) 957 ::DeleteObject (m_hRgn ); 958m_hRgn = hRgn ; 959 } 960 961HRGN Detach () 962 { 963HRGN hRgn = m_hRgn ; 964m_hRgn = NULL ; 965return hRgn ; 966 } 967 968operator HRGN ()const {return m_hRgn ; } 969 970bool IsNull ()const {return (m_hRgn == NULL ); } 971 972// Create methods 973HRGN CreateRectRgn (int x1 ,int y1 ,int x2 ,int y2 ) 974 { 975ATLASSERT (m_hRgn == NULL ); 976m_hRgn = ::CreateRectRgn (x1 ,y1 ,x2 ,y2 ); 977return m_hRgn ; 978 } 979 980HRGN CreateRectRgnIndirect (LPCRECT lpRect ) 981 { 982ATLASSERT (m_hRgn == NULL ); 983m_hRgn = ::CreateRectRgnIndirect (lpRect ); 984return m_hRgn ; 985 } 986 987HRGN CreateEllipticRgn (int x1 ,int y1 ,int x2 ,int y2 ) 988 { 989ATLASSERT (m_hRgn == NULL ); 990m_hRgn = ::CreateEllipticRgn (x1 ,y1 ,x2 ,y2 ); 991return m_hRgn ; 992 } 993 994HRGN CreateEllipticRgnIndirect (LPCRECT lpRect ) 995 { 996ATLASSERT (m_hRgn == NULL ); 997m_hRgn = ::CreateEllipticRgnIndirect (lpRect ); 998return m_hRgn ; 999 } 1000 1001HRGN CreatePolygonRgn (const POINT * lpPoints ,int nCount ,int nMode ) 1002 { 1003ATLASSERT (m_hRgn == NULL ); 1004m_hRgn = ::CreatePolygonRgn (lpPoints ,nCount ,nMode ); 1005return m_hRgn ; 1006 } 1007 1008HRGN CreatePolyPolygonRgn (const POINT * lpPoints ,const INT * lpPolyCounts ,int nCount ,int nPolyFillMode ) 1009 { 1010ATLASSERT (m_hRgn == NULL ); 1011m_hRgn = ::CreatePolyPolygonRgn (lpPoints ,lpPolyCounts ,nCount ,nPolyFillMode ); 1012return m_hRgn ; 1013 } 1014 1015HRGN CreateRoundRectRgn (int x1 ,int y1 ,int x2 ,int y2 ,int x3 ,int y3 ) 1016 { 1017ATLASSERT (m_hRgn == NULL ); 1018m_hRgn = ::CreateRoundRectRgn (x1 ,y1 ,x2 ,y2 ,x3 ,y3 ); 1019return m_hRgn ; 1020 } 1021 1022HRGN CreateFromPath (HDC hDC ) 1023 { 1024ATLASSERT (m_hRgn == NULL ); 1025ATLASSERT (hDC != NULL ); 1026m_hRgn = ::PathToRegion (hDC ); 1027return m_hRgn ; 1028 } 1029 1030HRGN CreateFromData (const XFORM * lpXForm ,int nCount ,const RGNDATA * pRgnData ) 1031 { 1032ATLASSERT (m_hRgn == NULL ); 1033m_hRgn = ::ExtCreateRegion (lpXForm ,nCount ,pRgnData ); 1034return m_hRgn ; 1035 } 1036 1037BOOL DeleteObject () 1038 { 1039ATLASSERT (m_hRgn != NULL ); 1040BOOL bRet = ::DeleteObject (m_hRgn ); 1041if (bRet ) 1042m_hRgn = NULL ; 1043return bRet ; 1044 } 1045 1046// Operations 1047void SetRectRgn (int x1 ,int y1 ,int x2 ,int y2 ) 1048 { 1049ATLASSERT (m_hRgn != NULL ); 1050 ::SetRectRgn (m_hRgn ,x1 ,y1 ,x2 ,y2 ); 1051 } 1052 1053void SetRectRgn (LPCRECT lpRect ) 1054 { 1055ATLASSERT (m_hRgn != NULL ); 1056 ::SetRectRgn (m_hRgn ,lpRect -> left ,lpRect -> top ,lpRect -> right ,lpRect -> bottom ); 1057 } 1058 1059int CombineRgn (HRGN hRgnSrc1 ,HRGN hRgnSrc2 ,int nCombineMode ) 1060 { 1061ATLASSERT (m_hRgn != NULL ); 1062return ::CombineRgn (m_hRgn ,hRgnSrc1 ,hRgnSrc2 ,nCombineMode ); 1063 } 1064 1065int CombineRgn (HRGN hRgnSrc ,int nCombineMode ) 1066 { 1067ATLASSERT (m_hRgn != NULL ); 1068return ::CombineRgn (m_hRgn ,m_hRgn ,hRgnSrc ,nCombineMode ); 1069 } 1070 1071int CopyRgn (HRGN hRgnSrc ) 1072 { 1073ATLASSERT (m_hRgn != NULL ); 1074return ::CombineRgn (m_hRgn ,hRgnSrc ,NULL ,RGN_COPY ); 1075 } 1076 1077BOOL EqualRgn (HRGN hRgn )const 1078 { 1079ATLASSERT (m_hRgn != NULL ); 1080return ::EqualRgn (m_hRgn ,hRgn ); 1081 } 1082 1083int OffsetRgn (int x ,int y ) 1084 { 1085ATLASSERT (m_hRgn != NULL ); 1086return ::OffsetRgn (m_hRgn ,x ,y ); 1087 } 1088 1089int OffsetRgn (POINT point ) 1090 { 1091ATLASSERT (m_hRgn != NULL ); 1092return ::OffsetRgn (m_hRgn ,point .x ,point .y ); 1093 } 1094 1095int GetRgnBox (LPRECT lpRect )const 1096 { 1097ATLASSERT (m_hRgn != NULL ); 1098return ::GetRgnBox (m_hRgn ,lpRect ); 1099 } 1100 1101BOOL PtInRegion (int x ,int y )const 1102 { 1103ATLASSERT (m_hRgn != NULL ); 1104return ::PtInRegion (m_hRgn ,x ,y ); 1105 } 1106 1107BOOL PtInRegion (POINT point )const 1108 { 1109ATLASSERT (m_hRgn != NULL ); 1110return ::PtInRegion (m_hRgn ,point .x ,point .y ); 1111 } 1112 1113BOOL RectInRegion (LPCRECT lpRect )const 1114 { 1115ATLASSERT (m_hRgn != NULL ); 1116return ::RectInRegion (m_hRgn ,lpRect ); 1117 } 1118 1119int GetRegionData (LPRGNDATA lpRgnData ,int nDataSize )const 1120 { 1121ATLASSERT (m_hRgn != NULL ); 1122return (int )::GetRegionData (m_hRgn ,nDataSize ,lpRgnData ); 1123 } 1124}; 1125 1126typedef CRgnT < false> CRgnHandle ; 1127typedef CRgnT < true> CRgn ; 1128 1129 1130/////////////////////////////////////////////////////////////////////////////// 1131// CDC - The device context class 1132 1133template < bool t_bManaged > 1134class CDCT ; 1135typedef CDCT < false> CDCHandle ; 1136typedef CDCT < true> CDC ; 1137 1138template < bool t_bManaged > 1139class CDCT 1140{ 1141public : 1142// Data members 1143HDC m_hDC ; 1144 1145// Constructor/destructor/operators 1146CDCT (HDC hDC = NULL ) :m_hDC (hDC ) 1147 { 1148 } 1149 1150 ~CDCT () 1151 { 1152if (t_bManaged && (m_hDC != NULL )) 1153 ::DeleteDC (Detach ()); 1154 } 1155 1156CDCT < t_bManaged >& operator = (HDC hDC ) 1157 { 1158Attach (hDC ); 1159return * this ; 1160 } 1161 1162void Attach (HDC hDC ) 1163 { 1164if (t_bManaged && (m_hDC != NULL )&& (m_hDC != hDC )) 1165 ::DeleteDC (m_hDC ); 1166m_hDC = hDC ; 1167 } 1168 1169HDC Detach () 1170 { 1171HDC hDC = m_hDC ; 1172m_hDC = NULL ; 1173return hDC ; 1174 } 1175 1176operator HDC ()const {return m_hDC ; } 1177 1178bool IsNull ()const {return (m_hDC == NULL ); } 1179 1180// Operations 1181HWND WindowFromDC ()const 1182 { 1183ATLASSERT (m_hDC != NULL ); 1184return ::WindowFromDC (m_hDC ); 1185 } 1186 1187CPenHandle GetCurrentPen ()const 1188 { 1189ATLASSERT (m_hDC != NULL ); 1190return CPenHandle ((HPEN )::GetCurrentObject (m_hDC ,OBJ_PEN )); 1191 } 1192 1193CBrushHandle GetCurrentBrush ()const 1194 { 1195ATLASSERT (m_hDC != NULL ); 1196return CBrushHandle ((HBRUSH )::GetCurrentObject (m_hDC ,OBJ_BRUSH )); 1197 } 1198 1199CPaletteHandle GetCurrentPalette ()const 1200 { 1201ATLASSERT (m_hDC != NULL ); 1202return CPaletteHandle ((HPALETTE )::GetCurrentObject (m_hDC ,OBJ_PAL )); 1203 } 1204 1205CFontHandle GetCurrentFont ()const 1206 { 1207ATLASSERT (m_hDC != NULL ); 1208return CFontHandle ((HFONT )::GetCurrentObject (m_hDC ,OBJ_FONT )); 1209 } 1210 1211CBitmapHandle GetCurrentBitmap ()const 1212 { 1213ATLASSERT (m_hDC != NULL ); 1214return CBitmapHandle ((HBITMAP )::GetCurrentObject (m_hDC ,OBJ_BITMAP )); 1215 } 1216 1217HDC CreateDC (LPCTSTR lpszDriverName ,LPCTSTR lpszDeviceName ,LPCTSTR lpszOutput ,const DEVMODE * lpInitData ) 1218 { 1219ATLASSERT (m_hDC == NULL ); 1220m_hDC = ::CreateDC (lpszDriverName ,lpszDeviceName ,lpszOutput ,lpInitData ); 1221return m_hDC ; 1222 } 1223 1224HDC CreateCompatibleDC (HDC hDC = NULL ) 1225 { 1226ATLASSERT (m_hDC == NULL ); 1227m_hDC = ::CreateCompatibleDC (hDC ); 1228return m_hDC ; 1229 } 1230 1231BOOL DeleteDC () 1232 { 1233if (m_hDC == NULL ) 1234return FALSE; 1235BOOL bRet = ::DeleteDC (m_hDC ); 1236if (bRet ) 1237m_hDC = NULL ; 1238return bRet ; 1239 } 1240 1241// Device-Context Functions 1242int SaveDC () 1243 { 1244ATLASSERT (m_hDC != NULL ); 1245return ::SaveDC (m_hDC ); 1246 } 1247 1248BOOL RestoreDC (int nSavedDC ) 1249 { 1250ATLASSERT (m_hDC != NULL ); 1251return ::RestoreDC (m_hDC ,nSavedDC ); 1252 } 1253 1254int GetDeviceCaps (int nIndex )const 1255 { 1256ATLASSERT (m_hDC != NULL ); 1257return ::GetDeviceCaps (m_hDC ,nIndex ); 1258 } 1259 1260UINT SetBoundsRect (LPCRECT lpRectBounds ,UINT flags ) 1261 { 1262ATLASSERT (m_hDC != NULL ); 1263return ::SetBoundsRect (m_hDC ,lpRectBounds ,flags ); 1264 } 1265 1266UINT GetBoundsRect (LPRECT lpRectBounds ,UINT flags )const 1267 { 1268ATLASSERT (m_hDC != NULL ); 1269return ::GetBoundsRect (m_hDC ,lpRectBounds ,flags ); 1270 } 1271 1272BOOL ResetDC (const DEVMODE * lpDevMode ) 1273 { 1274ATLASSERT (m_hDC != NULL ); 1275return ::ResetDC (m_hDC ,lpDevMode )!= NULL ; 1276 } 1277 1278// Drawing-Tool Functions 1279BOOL GetBrushOrg (LPPOINT lpPoint )const 1280 { 1281ATLASSERT (m_hDC != NULL ); 1282return ::GetBrushOrgEx (m_hDC ,lpPoint ); 1283 } 1284 1285BOOL SetBrushOrg (int x ,int y ,LPPOINT lpPoint = NULL ) 1286 { 1287ATLASSERT (m_hDC != NULL ); 1288return ::SetBrushOrgEx (m_hDC ,x ,y ,lpPoint ); 1289 } 1290 1291BOOL SetBrushOrg (POINT point ,LPPOINT lpPointRet = NULL ) 1292 { 1293ATLASSERT (m_hDC != NULL ); 1294return ::SetBrushOrgEx (m_hDC ,point .x ,point .y ,lpPointRet ); 1295 } 1296 1297int EnumObjects (int nObjectType ,int (CALLBACK * lpfn )(LPVOID ,LPARAM ),LPARAM lpData ) 1298 { 1299ATLASSERT (m_hDC != NULL ); 1300#ifdef STRICT 1301return ::EnumObjects (m_hDC ,nObjectType , (GOBJENUMPROC )lpfn ,lpData ); 1302#else 1303return ::EnumObjects (m_hDC ,nObjectType , (GOBJENUMPROC )lpfn , (LPVOID )lpData ); 1304#endif 1305 } 1306 1307// Type-safe selection helpers 1308HPEN SelectPen (HPEN hPen ) 1309 { 1310ATLASSERT (m_hDC != NULL ); 1311ATLASSERT ((hPen == NULL )|| (::GetObjectType (hPen )== OBJ_PEN )|| (::GetObjectType (hPen )== OBJ_EXTPEN )); 1312return (HPEN )::SelectObject (m_hDC ,hPen ); 1313 } 1314 1315HBRUSH SelectBrush (HBRUSH hBrush ) 1316 { 1317ATLASSERT (m_hDC != NULL ); 1318ATLASSERT ((hBrush == NULL )|| (::GetObjectType (hBrush )== OBJ_BRUSH )); 1319return (HBRUSH )::SelectObject (m_hDC ,hBrush ); 1320 } 1321 1322HFONT SelectFont (HFONT hFont ) 1323 { 1324ATLASSERT (m_hDC != NULL ); 1325ATLASSERT ((hFont == NULL )|| (::GetObjectType (hFont )== OBJ_FONT )); 1326return (HFONT )::SelectObject (m_hDC ,hFont ); 1327 } 1328 1329HBITMAP SelectBitmap (HBITMAP hBitmap ) 1330 { 1331ATLASSERT (m_hDC != NULL ); 1332ATLASSERT ((hBitmap == NULL )|| (::GetObjectType (hBitmap )== OBJ_BITMAP )); 1333return (HBITMAP )::SelectObject (m_hDC ,hBitmap ); 1334 } 1335 1336int SelectRgn (HRGN hRgn )// special return for regions 1337 { 1338ATLASSERT (m_hDC != NULL ); 1339ATLASSERT ((hRgn == NULL )|| (::GetObjectType (hRgn )== OBJ_REGION )); 1340return PtrToInt (::SelectObject (m_hDC ,hRgn )); 1341 } 1342 1343// Type-safe selection helpers for stock objects 1344HPEN SelectStockPen (int nPen ) 1345 { 1346ATLASSERT (m_hDC != NULL ); 1347ATLASSERT ((nPen == WHITE_PEN )|| (nPen == BLACK_PEN )|| (nPen == NULL_PEN )|| (nPen == DC_PEN )); 1348return SelectPen ((HPEN )::GetStockObject (nPen )); 1349 } 1350 1351HBRUSH SelectStockBrush (int nBrush ) 1352 { 1353ATLASSERT (((nBrush >=WHITE_BRUSH )&& (nBrush <=HOLLOW_BRUSH ))|| (nBrush == DC_BRUSH )); 1354return SelectBrush ((HBRUSH )::GetStockObject (nBrush )); 1355 } 1356 1357HFONT SelectStockFont (int nFont ) 1358 { 1359ATLASSERT (((nFont >=OEM_FIXED_FONT )&& (nFont <=SYSTEM_FIXED_FONT ))|| (nFont == DEFAULT_GUI_FONT )); 1360return SelectFont ((HFONT )::GetStockObject (nFont )); 1361 } 1362 1363HPALETTE SelectStockPalette (int nPalette ,BOOL bForceBackground ) 1364 { 1365ATLASSERT (nPalette == DEFAULT_PALETTE );// the only one supported 1366return SelectPalette ((HPALETTE )::GetStockObject (nPalette ),bForceBackground ); 1367 } 1368 1369// Color and Color Palette Functions 1370COLORREF GetNearestColor (COLORREF crColor )const 1371 { 1372ATLASSERT (m_hDC != NULL ); 1373return ::GetNearestColor (m_hDC ,crColor ); 1374 } 1375 1376HPALETTE SelectPalette (HPALETTE hPalette ,BOOL bForceBackground ) 1377 { 1378ATLASSERT (m_hDC != NULL ); 1379 1380return ::SelectPalette (m_hDC ,hPalette ,bForceBackground ); 1381 } 1382 1383UINT RealizePalette () 1384 { 1385ATLASSERT (m_hDC != NULL ); 1386return ::RealizePalette (m_hDC ); 1387 } 1388 1389void UpdateColors () 1390 { 1391ATLASSERT (m_hDC != NULL ); 1392 ::UpdateColors (m_hDC ); 1393 } 1394 1395// Drawing-Attribute Functions 1396COLORREF GetBkColor ()const 1397 { 1398ATLASSERT (m_hDC != NULL ); 1399return ::GetBkColor (m_hDC ); 1400 } 1401 1402int GetBkMode ()const 1403 { 1404ATLASSERT (m_hDC != NULL ); 1405return ::GetBkMode (m_hDC ); 1406 } 1407 1408int GetPolyFillMode ()const 1409 { 1410ATLASSERT (m_hDC != NULL ); 1411return ::GetPolyFillMode (m_hDC ); 1412 } 1413 1414int GetROP2 ()const 1415 { 1416ATLASSERT (m_hDC != NULL ); 1417return ::GetROP2 (m_hDC ); 1418 } 1419 1420int GetStretchBltMode ()const 1421 { 1422ATLASSERT (m_hDC != NULL ); 1423return ::GetStretchBltMode (m_hDC ); 1424 } 1425 1426COLORREF GetTextColor ()const 1427 { 1428ATLASSERT (m_hDC != NULL ); 1429return ::GetTextColor (m_hDC ); 1430 } 1431 1432COLORREF SetBkColor (COLORREF crColor ) 1433 { 1434ATLASSERT (m_hDC != NULL ); 1435return ::SetBkColor (m_hDC ,crColor ); 1436 } 1437 1438int SetBkMode (int nBkMode ) 1439 { 1440ATLASSERT (m_hDC != NULL ); 1441return ::SetBkMode (m_hDC ,nBkMode ); 1442 } 1443 1444int SetPolyFillMode (int nPolyFillMode ) 1445 { 1446ATLASSERT (m_hDC != NULL ); 1447return ::SetPolyFillMode (m_hDC ,nPolyFillMode ); 1448 } 1449 1450int SetROP2 (int nDrawMode ) 1451 { 1452ATLASSERT (m_hDC != NULL ); 1453return ::SetROP2 (m_hDC ,nDrawMode ); 1454 } 1455 1456int SetStretchBltMode (int nStretchMode ) 1457 { 1458ATLASSERT (m_hDC != NULL ); 1459return ::SetStretchBltMode (m_hDC ,nStretchMode ); 1460 } 1461 1462COLORREF SetTextColor (COLORREF crColor ) 1463 { 1464ATLASSERT (m_hDC != NULL ); 1465return ::SetTextColor (m_hDC ,crColor ); 1466 } 1467 1468BOOL GetColorAdjustment (LPCOLORADJUSTMENT lpColorAdjust )const 1469 { 1470ATLASSERT (m_hDC != NULL ); 1471return ::GetColorAdjustment (m_hDC ,lpColorAdjust ); 1472 } 1473 1474BOOL SetColorAdjustment (const COLORADJUSTMENT * lpColorAdjust ) 1475 { 1476ATLASSERT (m_hDC != NULL ); 1477return ::SetColorAdjustment (m_hDC ,lpColorAdjust ); 1478 } 1479 1480// Mapping Functions 1481int GetMapMode ()const 1482 { 1483ATLASSERT (m_hDC != NULL ); 1484return ::GetMapMode (m_hDC ); 1485 } 1486 1487BOOL GetViewportOrg (LPPOINT lpPoint )const 1488 { 1489ATLASSERT (m_hDC != NULL ); 1490return ::GetViewportOrgEx (m_hDC ,lpPoint ); 1491 } 1492 1493int SetMapMode (int nMapMode ) 1494 { 1495ATLASSERT (m_hDC != NULL ); 1496return ::SetMapMode (m_hDC ,nMapMode ); 1497 } 1498 1499// Viewport Origin 1500BOOL SetViewportOrg (int x ,int y ,LPPOINT lpPoint = NULL ) 1501 { 1502ATLASSERT (m_hDC != NULL ); 1503return ::SetViewportOrgEx (m_hDC ,x ,y ,lpPoint ); 1504 } 1505 1506BOOL SetViewportOrg (POINT point ,LPPOINT lpPointRet = NULL ) 1507 { 1508ATLASSERT (m_hDC != NULL ); 1509return SetViewportOrg (point .x ,point .y ,lpPointRet ); 1510 } 1511 1512BOOL OffsetViewportOrg (int nWidth ,int nHeight ,LPPOINT lpPoint = NULL ) 1513 { 1514ATLASSERT (m_hDC != NULL ); 1515return ::OffsetViewportOrgEx (m_hDC ,nWidth ,nHeight ,lpPoint ); 1516 } 1517 1518// Viewport Extent 1519BOOL GetViewportExt (LPSIZE lpSize )const 1520 { 1521ATLASSERT (m_hDC != NULL ); 1522return ::GetViewportExtEx (m_hDC ,lpSize ); 1523 } 1524 1525BOOL SetViewportExt (int x ,int y ,LPSIZE lpSize = NULL ) 1526 { 1527ATLASSERT (m_hDC != NULL ); 1528return ::SetViewportExtEx (m_hDC ,x ,y ,lpSize ); 1529 } 1530 1531BOOL SetViewportExt (SIZE size ,LPSIZE lpSizeRet = NULL ) 1532 { 1533ATLASSERT (m_hDC != NULL ); 1534return SetViewportExt (size .cx ,size .cy ,lpSizeRet ); 1535 } 1536 1537BOOL ScaleViewportExt (int xNum ,int xDenom ,int yNum ,int yDenom ,LPSIZE lpSize = NULL ) 1538 { 1539ATLASSERT (m_hDC != NULL ); 1540return ::ScaleViewportExtEx (m_hDC ,xNum ,xDenom ,yNum ,yDenom ,lpSize ); 1541 } 1542 1543// Window Origin 1544BOOL GetWindowOrg (LPPOINT lpPoint )const 1545 { 1546ATLASSERT (m_hDC != NULL ); 1547return ::GetWindowOrgEx (m_hDC ,lpPoint ); 1548 } 1549 1550BOOL SetWindowOrg (int x ,int y ,LPPOINT lpPoint = NULL ) 1551 { 1552ATLASSERT (m_hDC != NULL ); 1553return ::SetWindowOrgEx (m_hDC ,x ,y ,lpPoint ); 1554 } 1555 1556BOOL SetWindowOrg (POINT point ,LPPOINT lpPointRet = NULL ) 1557 { 1558ATLASSERT (m_hDC != NULL ); 1559return SetWindowOrg (point .x ,point .y ,lpPointRet ); 1560 } 1561 1562BOOL OffsetWindowOrg (int nWidth ,int nHeight ,LPPOINT lpPoint = NULL ) 1563 { 1564ATLASSERT (m_hDC != NULL ); 1565return ::OffsetWindowOrgEx (m_hDC ,nWidth ,nHeight ,lpPoint ); 1566 } 1567 1568// Window extent 1569BOOL GetWindowExt (LPSIZE lpSize )const 1570 { 1571ATLASSERT (m_hDC != NULL ); 1572return ::GetWindowExtEx (m_hDC ,lpSize ); 1573 } 1574 1575BOOL SetWindowExt (int x ,int y ,LPSIZE lpSize = NULL ) 1576 { 1577ATLASSERT (m_hDC != NULL ); 1578return ::SetWindowExtEx (m_hDC ,x ,y ,lpSize ); 1579 } 1580 1581BOOL SetWindowExt (SIZE size ,LPSIZE lpSizeRet = NULL ) 1582 { 1583ATLASSERT (m_hDC != NULL ); 1584return SetWindowExt (size .cx ,size .cy ,lpSizeRet ); 1585 } 1586 1587BOOL ScaleWindowExt (int xNum ,int xDenom ,int yNum ,int yDenom ,LPSIZE lpSize = NULL ) 1588 { 1589ATLASSERT (m_hDC != NULL ); 1590return ::ScaleWindowExtEx (m_hDC ,xNum ,xDenom ,yNum ,yDenom ,lpSize ); 1591 } 1592 1593// Coordinate Functions 1594BOOL DPtoLP (LPPOINT lpPoints ,int nCount = 1 )const 1595 { 1596ATLASSERT (m_hDC != NULL ); 1597return ::DPtoLP (m_hDC ,lpPoints ,nCount ); 1598 } 1599 1600BOOL DPtoLP (LPRECT lpRect )const 1601 { 1602ATLASSERT (m_hDC != NULL ); 1603return ::DPtoLP (m_hDC , (LPPOINT )lpRect ,2 ); 1604 } 1605 1606BOOL DPtoLP (LPSIZE lpSize )const 1607 { 1608SIZE sizeWinExt = {}; 1609if (!GetWindowExt (& sizeWinExt )) 1610return FALSE; 1611SIZE sizeVpExt = {}; 1612if (!GetViewportExt (& sizeVpExt )) 1613return FALSE; 1614lpSize -> cx = ::MulDiv (lpSize -> cx ,abs (sizeWinExt .cx ),abs (sizeVpExt .cx )); 1615lpSize -> cy = ::MulDiv (lpSize -> cy ,abs (sizeWinExt .cy ),abs (sizeVpExt .cy )); 1616return TRUE; 1617 } 1618 1619BOOL LPtoDP (LPPOINT lpPoints ,int nCount = 1 )const 1620 { 1621ATLASSERT (m_hDC != NULL ); 1622return ::LPtoDP (m_hDC ,lpPoints ,nCount ); 1623 } 1624 1625BOOL LPtoDP (LPRECT lpRect )const 1626 { 1627ATLASSERT (m_hDC != NULL ); 1628return ::LPtoDP (m_hDC , (LPPOINT )lpRect ,2 ); 1629 } 1630 1631BOOL LPtoDP (LPSIZE lpSize )const 1632 { 1633SIZE sizeWinExt = {}; 1634if (!GetWindowExt (& sizeWinExt )) 1635return FALSE; 1636SIZE sizeVpExt = {}; 1637if (!GetViewportExt (& sizeVpExt )) 1638return FALSE; 1639lpSize -> cx = ::MulDiv (lpSize -> cx ,abs (sizeVpExt .cx ),abs (sizeWinExt .cx )); 1640lpSize -> cy = ::MulDiv (lpSize -> cy ,abs (sizeVpExt .cy ),abs (sizeWinExt .cy )); 1641return TRUE; 1642 } 1643 1644// Special Coordinate Functions (useful for dealing with metafiles and OLE) 1645#define HIMETRIC_INCH 2540 // HIMETRIC units per inch 1646 1647void DPtoHIMETRIC (LPSIZE lpSize ) 1648 { 1649ATLASSERT (m_hDC != NULL ); 1650int nMapMode = GetMapMode (); 1651if ((nMapMode < MM_ISOTROPIC )&& (nMapMode != MM_TEXT )) 1652 { 1653// when using a constrained map mode, map against physical inch 1654SetMapMode (MM_HIMETRIC ); 1655DPtoLP (lpSize ); 1656SetMapMode (nMapMode ); 1657 } 1658else 1659 { 1660// map against logical inch for non-constrained mapping modes 1661int cxPerInch = GetDeviceCaps (LOGPIXELSX ); 1662int cyPerInch = GetDeviceCaps (LOGPIXELSY ); 1663ATLASSERT ((cxPerInch != 0 )&& (cyPerInch != 0 )); 1664lpSize -> cx = ::MulDiv (lpSize -> cx ,HIMETRIC_INCH ,cxPerInch ); 1665lpSize -> cy = ::MulDiv (lpSize -> cy ,HIMETRIC_INCH ,cyPerInch ); 1666 } 1667 } 1668 1669void HIMETRICtoDP (LPSIZE lpSize ) 1670 { 1671ATLASSERT (m_hDC != NULL ); 1672int nMapMode = GetMapMode (); 1673if ((nMapMode < MM_ISOTROPIC )&& (nMapMode != MM_TEXT )) 1674 { 1675// when using a constrained map mode, map against physical inch 1676SetMapMode (MM_HIMETRIC ); 1677LPtoDP (lpSize ); 1678SetMapMode (nMapMode ); 1679 } 1680else 1681 { 1682// map against logical inch for non-constrained mapping modes 1683int cxPerInch = GetDeviceCaps (LOGPIXELSX ); 1684int cyPerInch = GetDeviceCaps (LOGPIXELSY ); 1685ATLASSERT ((cxPerInch != 0 )&& (cyPerInch != 0 )); 1686lpSize -> cx = ::MulDiv (lpSize -> cx ,cxPerInch ,HIMETRIC_INCH ); 1687lpSize -> cy = ::MulDiv (lpSize -> cy ,cyPerInch ,HIMETRIC_INCH ); 1688 } 1689 } 1690 1691void LPtoHIMETRIC (LPSIZE lpSize ) 1692 { 1693LPtoDP (lpSize ); 1694DPtoHIMETRIC (lpSize ); 1695 } 1696 1697void HIMETRICtoLP (LPSIZE lpSize ) 1698 { 1699HIMETRICtoDP (lpSize ); 1700DPtoLP (lpSize ); 1701 } 1702 1703// Region Functions 1704BOOL FillRgn (HRGN hRgn ,HBRUSH hBrush ) 1705 { 1706ATLASSERT (m_hDC != NULL ); 1707return ::FillRgn (m_hDC ,hRgn ,hBrush ); 1708 } 1709 1710BOOL FrameRgn (HRGN hRgn ,HBRUSH hBrush ,int nWidth ,int nHeight ) 1711 { 1712ATLASSERT (m_hDC != NULL ); 1713return ::FrameRgn (m_hDC ,hRgn ,hBrush ,nWidth ,nHeight ); 1714 } 1715 1716BOOL InvertRgn (HRGN hRgn ) 1717 { 1718ATLASSERT (m_hDC != NULL ); 1719return ::InvertRgn (m_hDC ,hRgn ); 1720 } 1721 1722BOOL PaintRgn (HRGN hRgn ) 1723 { 1724ATLASSERT (m_hDC != NULL ); 1725return ::PaintRgn (m_hDC ,hRgn ); 1726 } 1727 1728// Clipping Functions 1729int GetClipBox (LPRECT lpRect )const 1730 { 1731ATLASSERT (m_hDC != NULL ); 1732return ::GetClipBox (m_hDC ,lpRect ); 1733 } 1734 1735int GetClipRgn (CRgn & region )const 1736 { 1737ATLASSERT (m_hDC != NULL ); 1738if (region .IsNull ()) 1739region .CreateRectRgn (0 ,0 ,0 ,0 ); 1740 1741int nRet = ::GetClipRgn (m_hDC ,region ); 1742if (nRet != 1 ) 1743region .DeleteObject (); 1744 1745return nRet ; 1746 } 1747 1748BOOL PtVisible (int x ,int y )const 1749 { 1750ATLASSERT (m_hDC != NULL ); 1751return ::PtVisible (m_hDC ,x ,y ); 1752 } 1753 1754BOOL PtVisible (POINT point )const 1755 { 1756ATLASSERT (m_hDC != NULL ); 1757return ::PtVisible (m_hDC ,point .x ,point .y ); 1758 } 1759 1760BOOL RectVisible (LPCRECT lpRect )const 1761 { 1762ATLASSERT (m_hDC != NULL ); 1763return ::RectVisible (m_hDC ,lpRect ); 1764 } 1765 1766int SelectClipRgn (HRGN hRgn ) 1767 { 1768ATLASSERT (m_hDC != NULL ); 1769return ::SelectClipRgn (m_hDC , (HRGN )hRgn ); 1770 } 1771 1772int ExcludeClipRect (int x1 ,int y1 ,int x2 ,int y2 ) 1773 { 1774ATLASSERT (m_hDC != NULL ); 1775return ::ExcludeClipRect (m_hDC ,x1 ,y1 ,x2 ,y2 ); 1776 } 1777 1778int ExcludeClipRect (LPCRECT lpRect ) 1779 { 1780ATLASSERT (m_hDC != NULL ); 1781return ::ExcludeClipRect (m_hDC ,lpRect -> left ,lpRect -> top ,lpRect -> right ,lpRect -> bottom ); 1782 } 1783 1784int ExcludeUpdateRgn (HWND hWnd ) 1785 { 1786ATLASSERT (m_hDC != NULL ); 1787return ::ExcludeUpdateRgn (m_hDC ,hWnd ); 1788 } 1789 1790int IntersectClipRect (int x1 ,int y1 ,int x2 ,int y2 ) 1791 { 1792ATLASSERT (m_hDC != NULL ); 1793return ::IntersectClipRect (m_hDC ,x1 ,y1 ,x2 ,y2 ); 1794 } 1795 1796int IntersectClipRect (LPCRECT lpRect ) 1797 { 1798ATLASSERT (m_hDC != NULL ); 1799return ::IntersectClipRect (m_hDC ,lpRect -> left ,lpRect -> top ,lpRect -> right ,lpRect -> bottom ); 1800 } 1801 1802int OffsetClipRgn (int x ,int y ) 1803 { 1804ATLASSERT (m_hDC != NULL ); 1805return ::OffsetClipRgn (m_hDC ,x ,y ); 1806 } 1807 1808int OffsetClipRgn (SIZE size ) 1809 { 1810ATLASSERT (m_hDC != NULL ); 1811return ::OffsetClipRgn (m_hDC ,size .cx ,size .cy ); 1812 } 1813 1814int SelectClipRgn (HRGN hRgn ,int nMode ) 1815 { 1816ATLASSERT (m_hDC != NULL ); 1817return ::ExtSelectClipRgn (m_hDC ,hRgn ,nMode ); 1818 } 1819 1820// Line-Output Functions 1821BOOL GetCurrentPosition (LPPOINT lpPoint )const 1822 { 1823ATLASSERT (m_hDC != NULL ); 1824return ::GetCurrentPositionEx (m_hDC ,lpPoint ); 1825 } 1826 1827BOOL MoveTo (int x ,int y ,LPPOINT lpPoint = NULL ) 1828 { 1829ATLASSERT (m_hDC != NULL ); 1830return ::MoveToEx (m_hDC ,x ,y ,lpPoint ); 1831 } 1832 1833BOOL MoveTo (POINT point ,LPPOINT lpPointRet = NULL ) 1834 { 1835ATLASSERT (m_hDC != NULL ); 1836return MoveTo (point .x ,point .y ,lpPointRet ); 1837 } 1838 1839BOOL LineTo (int x ,int y ) 1840 { 1841ATLASSERT (m_hDC != NULL ); 1842return ::LineTo (m_hDC ,x ,y ); 1843 } 1844 1845BOOL LineTo (POINT point ) 1846 { 1847ATLASSERT (m_hDC != NULL ); 1848return LineTo (point .x ,point .y ); 1849 } 1850 1851BOOL Arc (int x1 ,int y1 ,int x2 ,int y2 ,int x3 ,int y3 ,int x4 ,int y4 ) 1852 { 1853ATLASSERT (m_hDC != NULL ); 1854return ::Arc (m_hDC ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 ,x4 ,y4 ); 1855 } 1856 1857BOOL Arc (LPCRECT lpRect ,POINT ptStart ,POINT ptEnd ) 1858 { 1859ATLASSERT (m_hDC != NULL ); 1860return ::Arc (m_hDC ,lpRect -> left ,lpRect -> top , 1861lpRect -> right ,lpRect -> bottom ,ptStart .x ,ptStart .y , 1862ptEnd .x ,ptEnd .y ); 1863 } 1864 1865BOOL Polyline (const POINT * lpPoints ,int nCount ) 1866 { 1867ATLASSERT (m_hDC != NULL ); 1868return ::Polyline (m_hDC ,lpPoints ,nCount ); 1869 } 1870 1871BOOL AngleArc (int x ,int y ,int nRadius ,float fStartAngle ,float fSweepAngle ) 1872 { 1873ATLASSERT (m_hDC != NULL ); 1874return ::AngleArc (m_hDC ,x ,y ,nRadius ,fStartAngle ,fSweepAngle ); 1875 } 1876 1877BOOL ArcTo (int x1 ,int y1 ,int x2 ,int y2 ,int x3 ,int y3 ,int x4 ,int y4 ) 1878 { 1879ATLASSERT (m_hDC != NULL ); 1880return ::ArcTo (m_hDC ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 ,x4 ,y4 ); 1881 } 1882 1883BOOL ArcTo (LPCRECT lpRect ,POINT ptStart ,POINT ptEnd ) 1884 { 1885ATLASSERT (m_hDC != NULL ); 1886return ArcTo (lpRect -> left ,lpRect -> top ,lpRect -> right , 1887lpRect -> bottom ,ptStart .x ,ptStart .y ,ptEnd .x ,ptEnd .y ); 1888 } 1889 1890int GetArcDirection ()const 1891 { 1892ATLASSERT (m_hDC != NULL ); 1893return ::GetArcDirection (m_hDC ); 1894 } 1895 1896int SetArcDirection (int nArcDirection ) 1897 { 1898ATLASSERT (m_hDC != NULL ); 1899return ::SetArcDirection (m_hDC ,nArcDirection ); 1900 } 1901 1902BOOL PolyDraw (const POINT * lpPoints ,const BYTE * lpTypes ,int nCount ) 1903 { 1904ATLASSERT (m_hDC != NULL ); 1905return ::PolyDraw (m_hDC ,lpPoints ,lpTypes ,nCount ); 1906 } 1907 1908BOOL PolylineTo (const POINT * lpPoints ,int nCount ) 1909 { 1910ATLASSERT (m_hDC != NULL ); 1911return ::PolylineTo (m_hDC ,lpPoints ,nCount ); 1912 } 1913 1914BOOL PolyPolyline (const POINT * lpPoints , 1915const DWORD * lpPolyPoints ,int nCount ) 1916 { 1917ATLASSERT (m_hDC != NULL ); 1918return ::PolyPolyline (m_hDC ,lpPoints ,lpPolyPoints ,nCount ); 1919 } 1920 1921BOOL PolyBezier (const POINT * lpPoints ,int nCount ) 1922 { 1923ATLASSERT (m_hDC != NULL ); 1924return ::PolyBezier (m_hDC ,lpPoints ,nCount ); 1925 } 1926 1927BOOL PolyBezierTo (const POINT * lpPoints ,int nCount ) 1928 { 1929ATLASSERT (m_hDC != NULL ); 1930return ::PolyBezierTo (m_hDC ,lpPoints ,nCount ); 1931 } 1932 1933// Simple Drawing Functions 1934BOOL FillRect (LPCRECT lpRect ,HBRUSH hBrush ) 1935 { 1936ATLASSERT (m_hDC != NULL ); 1937return ::FillRect (m_hDC ,lpRect ,hBrush ); 1938 } 1939 1940BOOL FillRect (LPCRECT lpRect ,int nColorIndex ) 1941 { 1942ATLASSERT (m_hDC != NULL ); 1943return ::FillRect (m_hDC ,lpRect , (HBRUSH )LongToPtr (nColorIndex + 1 )); 1944 } 1945 1946BOOL FrameRect (LPCRECT lpRect ,HBRUSH hBrush ) 1947 { 1948ATLASSERT (m_hDC != NULL ); 1949return ::FrameRect (m_hDC ,lpRect ,hBrush ); 1950 } 1951 1952BOOL InvertRect (LPCRECT lpRect ) 1953 { 1954ATLASSERT (m_hDC != NULL ); 1955return ::InvertRect (m_hDC ,lpRect ); 1956 } 1957 1958BOOL DrawIcon (int x ,int y ,HICON hIcon ) 1959 { 1960ATLASSERT (m_hDC != NULL ); 1961return ::DrawIcon (m_hDC ,x ,y ,hIcon ); 1962 } 1963 1964BOOL DrawIcon (POINT point ,HICON hIcon ) 1965 { 1966ATLASSERT (m_hDC != NULL ); 1967return ::DrawIcon (m_hDC ,point .x ,point .y ,hIcon ); 1968 } 1969 1970BOOL DrawIconEx (int x ,int y ,HICON hIcon ,int cxWidth ,int cyWidth ,UINT uStepIfAniCur = 0 ,HBRUSH hbrFlickerFreeDraw = NULL ,UINT uFlags = DI_NORMAL ) 1971 { 1972ATLASSERT (m_hDC != NULL ); 1973return ::DrawIconEx (m_hDC ,x ,y ,hIcon ,cxWidth ,cyWidth ,uStepIfAniCur ,hbrFlickerFreeDraw ,uFlags ); 1974 } 1975 1976BOOL DrawIconEx (POINT point ,HICON hIcon ,SIZE size ,UINT uStepIfAniCur = 0 ,HBRUSH hbrFlickerFreeDraw = NULL ,UINT uFlags = DI_NORMAL ) 1977 { 1978ATLASSERT (m_hDC != NULL ); 1979return ::DrawIconEx (m_hDC ,point .x ,point .y ,hIcon ,size .cx ,size .cy ,uStepIfAniCur ,hbrFlickerFreeDraw ,uFlags ); 1980 } 1981 1982BOOL DrawState (POINT pt ,SIZE size ,HBITMAP hBitmap ,UINT nFlags ,HBRUSH hBrush = NULL ) 1983 { 1984ATLASSERT (m_hDC != NULL ); 1985return ::DrawState (m_hDC ,hBrush ,NULL , (LPARAM )hBitmap ,0 ,pt .x ,pt .y ,size .cx ,size .cy ,nFlags |DST_BITMAP ); 1986 } 1987 1988BOOL DrawState (POINT pt ,SIZE size ,HICON hIcon ,UINT nFlags ,HBRUSH hBrush = NULL ) 1989 { 1990ATLASSERT (m_hDC != NULL ); 1991return ::DrawState (m_hDC ,hBrush ,NULL , (LPARAM )hIcon ,0 ,pt .x ,pt .y ,size .cx ,size .cy ,nFlags |DST_ICON ); 1992 } 1993 1994BOOL DrawState (POINT pt ,SIZE size ,LPCTSTR lpszText ,UINT nFlags ,BOOL bPrefixText = TRUE,int nTextLen = 0 ,HBRUSH hBrush = NULL ) 1995 { 1996ATLASSERT (m_hDC != NULL ); 1997return ::DrawState (m_hDC ,hBrush ,NULL , (LPARAM )lpszText , (WPARAM )nTextLen ,pt .x ,pt .y ,size .cx ,size .cy ,nFlags | (bPrefixText ?DST_PREFIXTEXT :DST_TEXT )); 1998 } 1999 2000BOOL DrawState (POINT pt ,SIZE size ,DRAWSTATEPROC lpDrawProc ,LPARAM lData ,UINT nFlags ,HBRUSH hBrush = NULL ) 2001 { 2002ATLASSERT (m_hDC != NULL ); 2003return ::DrawState (m_hDC ,hBrush ,lpDrawProc ,lData ,0 ,pt .x ,pt .y ,size .cx ,size .cy ,nFlags |DST_COMPLEX ); 2004 } 2005 2006// Ellipse and Polygon Functions 2007BOOL Chord (int x1 ,int y1 ,int x2 ,int y2 ,int x3 ,int y3 ,int x4 ,int y4 ) 2008 { 2009ATLASSERT (m_hDC != NULL ); 2010return ::Chord (m_hDC ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 ,x4 ,y4 ); 2011 } 2012 2013BOOL Chord (LPCRECT lpRect ,POINT ptStart ,POINT ptEnd ) 2014 { 2015ATLASSERT (m_hDC != NULL ); 2016return ::Chord (m_hDC ,lpRect -> left ,lpRect -> top ,lpRect -> right ,lpRect -> bottom ,ptStart .x ,ptStart .y ,ptEnd .x ,ptEnd .y ); 2017 } 2018 2019void DrawFocusRect (LPCRECT lpRect ) 2020 { 2021ATLASSERT (m_hDC != NULL ); 2022 ::DrawFocusRect (m_hDC ,lpRect ); 2023 } 2024 2025BOOL Ellipse (int x1 ,int y1 ,int x2 ,int y2 ) 2026 { 2027ATLASSERT (m_hDC != NULL ); 2028return ::Ellipse (m_hDC ,x1 ,y1 ,x2 ,y2 ); 2029 } 2030 2031BOOL Ellipse (LPCRECT lpRect ) 2032 { 2033ATLASSERT (m_hDC != NULL ); 2034return ::Ellipse (m_hDC ,lpRect -> left ,lpRect -> top ,lpRect -> right ,lpRect -> bottom ); 2035 } 2036 2037BOOL Pie (int x1 ,int y1 ,int x2 ,int y2 ,int x3 ,int y3 ,int x4 ,int y4 ) 2038 { 2039ATLASSERT (m_hDC != NULL ); 2040return ::Pie (m_hDC ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 ,x4 ,y4 ); 2041 } 2042 2043BOOL Pie (LPCRECT lpRect ,POINT ptStart ,POINT ptEnd ) 2044 { 2045ATLASSERT (m_hDC != NULL ); 2046return ::Pie (m_hDC ,lpRect -> left ,lpRect -> top ,lpRect -> right ,lpRect -> bottom ,ptStart .x ,ptStart .y ,ptEnd .x ,ptEnd .y ); 2047 } 2048 2049BOOL Polygon (const POINT * lpPoints ,int nCount ) 2050 { 2051ATLASSERT (m_hDC != NULL ); 2052return ::Polygon (m_hDC ,lpPoints ,nCount ); 2053 } 2054 2055BOOL PolyPolygon (const POINT * lpPoints ,const INT * lpPolyCounts ,int nCount ) 2056 { 2057ATLASSERT (m_hDC != NULL ); 2058return ::PolyPolygon (m_hDC ,lpPoints ,lpPolyCounts ,nCount ); 2059 } 2060 2061BOOL Rectangle (int x1 ,int y1 ,int x2 ,int y2 ) 2062 { 2063ATLASSERT (m_hDC != NULL ); 2064return ::Rectangle (m_hDC ,x1 ,y1 ,x2 ,y2 ); 2065 } 2066 2067BOOL Rectangle (LPCRECT lpRect ) 2068 { 2069ATLASSERT (m_hDC != NULL ); 2070return ::Rectangle (m_hDC ,lpRect -> left ,lpRect -> top ,lpRect -> right ,lpRect -> bottom ); 2071 } 2072 2073BOOL RoundRect (int x1 ,int y1 ,int x2 ,int y2 ,int x3 ,int y3 ) 2074 { 2075ATLASSERT (m_hDC != NULL ); 2076return ::RoundRect (m_hDC ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 ); 2077 } 2078 2079BOOL RoundRect (LPCRECT lpRect ,POINT point ) 2080 { 2081ATLASSERT (m_hDC != NULL ); 2082return ::RoundRect (m_hDC ,lpRect -> left ,lpRect -> top ,lpRect -> right ,lpRect -> bottom ,point .x ,point .y ); 2083 } 2084 2085// Bitmap Functions 2086BOOL PatBlt (int x ,int y ,int nWidth ,int nHeight ,DWORD dwRop ) 2087 { 2088ATLASSERT (m_hDC != NULL ); 2089return ::PatBlt (m_hDC ,x ,y ,nWidth ,nHeight ,dwRop ); 2090 } 2091 2092BOOL BitBlt (int x ,int y ,int nWidth ,int nHeight ,HDC hSrcDC , 2093int xSrc ,int ySrc ,DWORD dwRop ) 2094 { 2095ATLASSERT (m_hDC != NULL ); 2096return ::BitBlt (m_hDC ,x ,y ,nWidth ,nHeight ,hSrcDC ,xSrc ,ySrc ,dwRop ); 2097 } 2098 2099BOOL StretchBlt (int x ,int y ,int nWidth ,int nHeight ,HDC hSrcDC ,int xSrc ,int ySrc ,int nSrcWidth ,int nSrcHeight ,DWORD dwRop ) 2100 { 2101ATLASSERT (m_hDC != NULL ); 2102return ::StretchBlt (m_hDC ,x ,y ,nWidth ,nHeight ,hSrcDC ,xSrc ,ySrc ,nSrcWidth ,nSrcHeight ,dwRop ); 2103 } 2104 2105COLORREF GetPixel (int x ,int y )const 2106 { 2107ATLASSERT (m_hDC != NULL ); 2108return ::GetPixel (m_hDC ,x ,y ); 2109 } 2110 2111COLORREF GetPixel (POINT point )const 2112 { 2113ATLASSERT (m_hDC != NULL ); 2114return ::GetPixel (m_hDC ,point .x ,point .y ); 2115 } 2116 2117COLORREF SetPixel (int x ,int y ,COLORREF crColor ) 2118 { 2119ATLASSERT (m_hDC != NULL ); 2120return ::SetPixel (m_hDC ,x ,y ,crColor ); 2121 } 2122 2123COLORREF SetPixel (POINT point ,COLORREF crColor ) 2124 { 2125ATLASSERT (m_hDC != NULL ); 2126return ::SetPixel (m_hDC ,point .x ,point .y ,crColor ); 2127 } 2128 2129BOOL FloodFill (int x ,int y ,COLORREF crColor ) 2130 { 2131ATLASSERT (m_hDC != NULL ); 2132return ::FloodFill (m_hDC ,x ,y ,crColor ); 2133 } 2134 2135BOOL ExtFloodFill (int x ,int y ,COLORREF crColor ,UINT nFillType ) 2136 { 2137ATLASSERT (m_hDC != NULL ); 2138return ::ExtFloodFill (m_hDC ,x ,y ,crColor ,nFillType ); 2139 } 2140 2141BOOL MaskBlt (int x ,int y ,int nWidth ,int nHeight ,HDC hSrcDC ,int xSrc ,int ySrc ,HBITMAP hMaskBitmap ,int xMask ,int yMask ,DWORD dwRop ) 2142 { 2143ATLASSERT (m_hDC != NULL ); 2144return ::MaskBlt (m_hDC ,x ,y ,nWidth ,nHeight ,hSrcDC ,xSrc ,ySrc ,hMaskBitmap ,xMask ,yMask ,dwRop ); 2145 } 2146 2147BOOL PlgBlt (LPPOINT lpPoint ,HDC hSrcDC ,int xSrc ,int ySrc ,int nWidth ,int nHeight ,HBITMAP hMaskBitmap ,int xMask ,int yMask ) 2148 { 2149ATLASSERT (m_hDC != NULL ); 2150return ::PlgBlt (m_hDC ,lpPoint ,hSrcDC ,xSrc ,ySrc ,nWidth ,nHeight ,hMaskBitmap ,xMask ,yMask ); 2151 } 2152 2153BOOL SetPixelV (int x ,int y ,COLORREF crColor ) 2154 { 2155ATLASSERT (m_hDC != NULL ); 2156return ::SetPixelV (m_hDC ,x ,y ,crColor ); 2157 } 2158 2159BOOL SetPixelV (POINT point ,COLORREF crColor ) 2160 { 2161ATLASSERT (m_hDC != NULL ); 2162return ::SetPixelV (m_hDC ,point .x ,point .y ,crColor ); 2163 } 2164 2165BOOL TransparentBlt (int x ,int y ,int nWidth ,int nHeight ,HDC hSrcDC ,int xSrc ,int ySrc ,int nSrcWidth ,int nSrcHeight ,UINT crTransparent ) 2166 { 2167ATLASSERT (m_hDC != NULL ); 2168return ::TransparentBlt (m_hDC ,x ,y ,nWidth ,nHeight ,hSrcDC ,xSrc ,ySrc ,nSrcWidth ,nSrcHeight ,crTransparent ); 2169 } 2170 2171BOOL GradientFill (const PTRIVERTEX pVertices ,DWORD nVertices ,void * pMeshElements ,DWORD nMeshElements ,DWORD dwMode ) 2172 { 2173ATLASSERT (m_hDC != NULL ); 2174return ::GradientFill (m_hDC ,pVertices ,nVertices ,pMeshElements ,nMeshElements ,dwMode ); 2175 } 2176 2177BOOL GradientFillRect (RECT & rect ,COLORREF clr1 ,COLORREF clr2 ,bool bHorizontal ) 2178 { 2179ATLASSERT (m_hDC != NULL ); 2180 2181TRIVERTEX arrTvx [2 ]= { {0 }, {0 } }; 2182 2183arrTvx [0 ].x = rect .left ; 2184arrTvx [0 ].y = rect .top ; 2185arrTvx [0 ].Red = MAKEWORD (0 ,GetRValue (clr1 )); 2186arrTvx [0 ].Green = MAKEWORD (0 ,GetGValue (clr1 )); 2187arrTvx [0 ].Blue = MAKEWORD (0 ,GetBValue (clr1 )); 2188arrTvx [0 ].Alpha = 0 ; 2189 2190arrTvx [1 ].x = rect .right ; 2191arrTvx [1 ].y = rect .bottom ; 2192arrTvx [1 ].Red = MAKEWORD (0 ,GetRValue (clr2 )); 2193arrTvx [1 ].Green = MAKEWORD (0 ,GetGValue (clr2 )); 2194arrTvx [1 ].Blue = MAKEWORD (0 ,GetBValue (clr2 )); 2195arrTvx [1 ].Alpha = 0 ; 2196 2197GRADIENT_RECT gr = {0 ,1 }; 2198 2199return ::GradientFill (m_hDC ,arrTvx ,2 ,& gr ,1 ,bHorizontal ?GRADIENT_FILL_RECT_H :GRADIENT_FILL_RECT_V ); 2200 } 2201 2202BOOL AlphaBlend (int x ,int y ,int nWidth ,int nHeight ,HDC hSrcDC ,int xSrc ,int ySrc ,int nSrcWidth ,int nSrcHeight ,BLENDFUNCTION bf ) 2203 { 2204ATLASSERT (m_hDC != NULL ); 2205return ::AlphaBlend (m_hDC ,x ,y ,nWidth ,nHeight ,hSrcDC ,xSrc ,ySrc ,nSrcWidth ,nSrcHeight ,bf ); 2206 } 2207 2208// Extra bitmap functions 2209// Helper function for painting a disabled toolbar or menu bitmap 2210// This function can take either an HBITMAP (for SS) or a DC with 2211// the bitmap already painted (for cmdbar) 2212BOOL DitherBlt (int x ,int y ,int nWidth ,int nHeight ,HDC hSrcDC ,HBITMAP hBitmap ,int xSrc ,int ySrc , 2213HBRUSH hBrushBackground = ::GetSysColorBrush (COLOR_3DFACE ), 2214HBRUSH hBrush3DEffect = ::GetSysColorBrush (COLOR_3DHILIGHT ), 2215HBRUSH hBrushDisabledImage = ::GetSysColorBrush (COLOR_3DSHADOW )) 2216 { 2217ATLASSERT ((m_hDC != NULL )|| (hBitmap != NULL )); 2218ATLASSERT ((nWidth > 0 )&& (nHeight > 0 )); 2219 2220// Create a generic DC for all BitBlts 2221CDCT < false> dc = (hSrcDC != NULL ) ?hSrcDC : ::CreateCompatibleDC (m_hDC ); 2222ATLASSERT (dc .m_hDC != NULL ); 2223if (dc .m_hDC == NULL ) 2224return FALSE; 2225 2226// Create a DC for the monochrome DIB section 2227CDCT < true> dcBW = ::CreateCompatibleDC (m_hDC ); 2228ATLASSERT (dcBW .m_hDC != NULL ); 2229if (dcBW .m_hDC == NULL ) 2230 { 2231if (hSrcDC == NULL ) 2232dc .DeleteDC (); 2233return FALSE; 2234 } 2235 2236// Create the monochrome DIB section with a black and white palette 2237struct RGBBWBITMAPINFO 2238 { 2239BITMAPINFOHEADER bmiHeader ; 2240RGBQUAD bmiColors [2 ]; 2241 }; 2242 2243RGBBWBITMAPINFO rgbBWBitmapInfo = 2244 { 2245 {sizeof (BITMAPINFOHEADER ),nWidth ,nHeight ,1 ,1 ,BI_RGB ,0 ,0 ,0 ,0 ,0 }, 2246 { {0x00 ,0x00 ,0x00 ,0x00 }, {0xFF ,0xFF ,0xFF ,0x00 } } 2247 }; 2248 2249VOID * pbitsBW ; 2250CBitmap bmpBW = ::CreateDIBSection (dcBW , (LPBITMAPINFO )& rgbBWBitmapInfo ,DIB_RGB_COLORS ,& pbitsBW ,NULL ,0 ); 2251ATLASSERT (bmpBW .m_hBitmap != NULL ); 2252if (bmpBW .m_hBitmap == NULL ) 2253 { 2254if (hSrcDC == NULL ) 2255dc .DeleteDC (); 2256return FALSE; 2257 } 2258 2259// Attach the monochrome DIB section and the bitmap to the DCs 2260HBITMAP hbmOldBW = dcBW .SelectBitmap (bmpBW ); 2261HBITMAP hbmOldDC = NULL ; 2262if (hBitmap != NULL ) 2263hbmOldDC = dc .SelectBitmap (hBitmap ); 2264 2265// Block: Dark gray removal: we want (128, 128, 128) pixels to become black and not white 2266 { 2267CDCT < true> dcTemp1 = ::CreateCompatibleDC (m_hDC ); 2268CDCT < true> dcTemp2 = ::CreateCompatibleDC (m_hDC ); 2269CBitmap bmpTemp1 ; 2270bmpTemp1 .CreateCompatibleBitmap (dc ,nWidth ,nHeight ); 2271CBitmap bmpTemp2 ; 2272bmpTemp2 .CreateBitmap (nWidth ,nHeight ,1 ,1 ,NULL ); 2273HBITMAP hOldBmp1 = dcTemp1 .SelectBitmap (bmpTemp1 ); 2274HBITMAP hOldBmp2 = dcTemp2 .SelectBitmap (bmpTemp2 ); 2275// Let's copy our image, it will be altered 2276dcTemp1 .BitBlt (0 ,0 ,nWidth ,nHeight ,dc ,xSrc ,ySrc ,SRCCOPY ); 2277 2278// All dark gray pixels will become white, the others black 2279dcTemp1 .SetBkColor (RGB (128 ,128 ,128 )); 2280dcTemp2 .BitBlt (0 ,0 ,nWidth ,nHeight ,dcTemp1 ,0 ,0 ,SRCCOPY ); 2281// Do an XOR to set to black these white pixels 2282dcTemp1 .BitBlt (0 ,0 ,nWidth ,nHeight ,dcTemp2 ,0 ,0 ,SRCINVERT ); 2283 2284// BitBlt the bitmap into the monochrome DIB section 2285// The DIB section will do a true monochrome conversion 2286// The magenta background being closer to white will become white 2287dcBW .BitBlt (0 ,0 ,nWidth ,nHeight ,dcTemp1 ,0 ,0 ,SRCCOPY ); 2288 2289// Cleanup 2290dcTemp1 .SelectBitmap (hOldBmp1 ); 2291dcTemp2 .SelectBitmap (hOldBmp2 ); 2292 } 2293 2294// Paint the destination rectangle using hBrushBackground 2295if (hBrushBackground != NULL ) 2296 { 2297RECT rc = {x ,y ,x + nWidth ,y + nHeight }; 2298FillRect (& rc ,hBrushBackground ); 2299 } 2300 2301// BitBlt the black bits in the monochrome bitmap into hBrush3DEffect color in the destination DC 2302// The magic ROP comes from the Charles Petzold's book 2303HBRUSH hOldBrush = SelectBrush (hBrush3DEffect ); 2304BitBlt (x + 1 ,y + 1 ,nWidth ,nHeight ,dcBW ,0 ,0 ,0xB8074A ); 2305 2306// BitBlt the black bits in the monochrome bitmap into hBrushDisabledImage color in the destination DC 2307SelectBrush (hBrushDisabledImage ); 2308BitBlt (x ,y ,nWidth ,nHeight ,dcBW ,0 ,0 ,0xB8074A ); 2309 2310SelectBrush (hOldBrush ); 2311dcBW .SelectBitmap (hbmOldBW ); 2312dc .SelectBitmap (hbmOldDC ); 2313 2314if (hSrcDC == NULL ) 2315dc .DeleteDC (); 2316 2317return TRUE; 2318 } 2319 2320// Text Functions 2321BOOL TextOut (int x ,int y ,LPCTSTR lpszString ,int nCount = -1 ) 2322 { 2323ATLASSERT (m_hDC != NULL ); 2324if (nCount == -1 ) 2325nCount = lstrlen (lpszString ); 2326return ::TextOut (m_hDC ,x ,y ,lpszString ,nCount ); 2327 } 2328 2329BOOL ExtTextOut (int x ,int y ,UINT nOptions ,LPCRECT lpRect ,LPCTSTR lpszString ,int nCount = -1 ,LPINT lpDxWidths = NULL ) 2330 { 2331ATLASSERT (m_hDC != NULL ); 2332if (nCount == -1 ) 2333nCount = lstrlen (lpszString ); 2334ATLASSERT ((nCount >=0 )&& (nCount <=8192 )); 2335return ::ExtTextOut (m_hDC ,x ,y ,nOptions ,lpRect ,lpszString , (UINT )nCount ,lpDxWidths ); 2336 } 2337 2338SIZE TabbedTextOut (int x ,int y ,LPCTSTR lpszString ,int nCount = -1 ,int nTabPositions = 0 ,LPINT lpnTabStopPositions = NULL ,int nTabOrigin = 0 ) 2339 { 2340ATLASSERT (m_hDC != NULL ); 2341if (nCount == -1 ) 2342nCount = lstrlen (lpszString ); 2343LONG lRes = ::TabbedTextOut (m_hDC ,x ,y ,lpszString ,nCount ,nTabPositions ,lpnTabStopPositions ,nTabOrigin ); 2344SIZE size = {GET_X_LPARAM (lRes ),GET_Y_LPARAM (lRes ) }; 2345return size ; 2346 } 2347 2348int DrawText (LPCTSTR lpstrText ,int cchText ,LPRECT lpRect ,UINT uFormat ) 2349 { 2350ATLASSERT (m_hDC != NULL ); 2351ATLASSERT ((uFormat & DT_MODIFYSTRING )== 0 ); 2352return ::DrawText (m_hDC ,lpstrText ,cchText ,lpRect ,uFormat ); 2353 } 2354 2355int DrawText (LPTSTR lpstrText ,int cchText ,LPRECT lpRect ,UINT uFormat ) 2356 { 2357ATLASSERT (m_hDC != NULL ); 2358return ::DrawText (m_hDC ,lpstrText ,cchText ,lpRect ,uFormat ); 2359 } 2360 2361int DrawTextEx (LPTSTR lpstrText ,int cchText ,LPRECT lpRect ,UINT uFormat ,LPDRAWTEXTPARAMS lpDTParams = NULL ) 2362 { 2363ATLASSERT (m_hDC != NULL ); 2364return ::DrawTextEx (m_hDC ,lpstrText ,cchText ,lpRect ,uFormat ,lpDTParams ); 2365 } 2366 2367// Note - ::DrawShadowText() is present only if comctl32.dll version 6 is loaded 2368int DrawShadowText (LPCWSTR lpstrText ,int cchText ,LPRECT lpRect ,DWORD dwFlags ,COLORREF clrText ,COLORREF clrShadow ,int xOffset ,int yOffset ) 2369 { 2370ATLASSERT (m_hDC != NULL ); 2371ATLASSERT (lpRect != NULL ); 2372return ::DrawShadowText (m_hDC ,lpstrText ,cchText ,lpRect ,dwFlags ,clrText ,clrShadow ,xOffset ,yOffset ); 2373 } 2374 2375BOOL GetTextExtent (LPCTSTR lpszString ,int nCount ,LPSIZE lpSize )const 2376 { 2377ATLASSERT (m_hDC != NULL ); 2378if (nCount == -1 ) 2379nCount = lstrlen (lpszString ); 2380return ::GetTextExtentPoint32 (m_hDC ,lpszString ,nCount ,lpSize ); 2381 } 2382 2383BOOL GetTextExtentExPoint (LPCTSTR lpszString ,int cchString ,LPSIZE lpSize ,int nMaxExtent ,LPINT lpnFit = NULL ,LPINT alpDx = NULL ) 2384 { 2385ATLASSERT (m_hDC != NULL ); 2386return ::GetTextExtentExPoint (m_hDC ,lpszString ,cchString ,nMaxExtent ,lpnFit ,alpDx ,lpSize ); 2387 } 2388 2389DWORD GetTabbedTextExtent (LPCTSTR lpszString ,int nCount = -1 ,int nTabPositions = 0 ,LPINT lpnTabStopPositions = NULL )const 2390 { 2391ATLASSERT (m_hDC != NULL ); 2392if (nCount == -1 ) 2393nCount = lstrlen (lpszString ); 2394return ::GetTabbedTextExtent (m_hDC ,lpszString ,nCount ,nTabPositions ,lpnTabStopPositions ); 2395 } 2396 2397BOOL GrayString (HBRUSH hBrush ,BOOL (CALLBACK * lpfnOutput )(HDC ,LPARAM ,int ),LPARAM lpData ,int nCount ,int x ,int y ,int nWidth ,int nHeight ) 2398 { 2399ATLASSERT (m_hDC != NULL ); 2400return ::GrayString (m_hDC ,hBrush , (GRAYSTRINGPROC )lpfnOutput ,lpData ,nCount ,x ,y ,nWidth ,nHeight ); 2401 } 2402 2403UINT GetTextAlign ()const 2404 { 2405ATLASSERT (m_hDC != NULL ); 2406return ::GetTextAlign (m_hDC ); 2407 } 2408 2409UINT SetTextAlign (UINT nFlags ) 2410 { 2411ATLASSERT (m_hDC != NULL ); 2412return ::SetTextAlign (m_hDC ,nFlags ); 2413 } 2414 2415int GetTextFace (LPTSTR lpszFacename ,int nCount )const 2416 { 2417ATLASSERT (m_hDC != NULL ); 2418return ::GetTextFace (m_hDC ,nCount ,lpszFacename ); 2419 } 2420 2421int GetTextFaceLen ()const 2422 { 2423ATLASSERT (m_hDC != NULL ); 2424return ::GetTextFace (m_hDC ,0 ,NULL ); 2425 } 2426 2427#ifdef _OLEAUTO_H_ 2428BOOL GetTextFace (BSTR & bstrFace )const 2429 { 2430USES_CONVERSION ; 2431ATLASSERT (m_hDC != NULL ); 2432ATLASSERT (bstrFace == NULL ); 2433 2434int nLen = GetTextFaceLen (); 2435if (nLen == 0 ) 2436return FALSE; 2437 2438ATL ::CTempBuffer < TCHAR ,_WTL_STACK_ALLOC_THRESHOLD > buff ; 2439LPTSTR lpszText = buff .Allocate (nLen ); 2440if (lpszText == NULL ) 2441return FALSE; 2442 2443if (!GetTextFace (lpszText ,nLen )) 2444return FALSE; 2445 2446bstrFace = ::SysAllocString (T2OLE (lpszText )); 2447return (bstrFace != NULL ) ? TRUE : FALSE; 2448 } 2449#endif 2450 2451#ifdef __ATLSTR_H__ 2452int GetTextFace (ATL ::CString & strFace )const 2453 { 2454ATLASSERT (m_hDC != NULL ); 2455 2456int nLen = GetTextFaceLen (); 2457if (nLen == 0 ) 2458return 0 ; 2459 2460LPTSTR lpstr = strFace .GetBufferSetLength (nLen ); 2461if (lpstr == NULL ) 2462return 0 ; 2463int nRet = GetTextFace (lpstr ,nLen ); 2464strFace .ReleaseBuffer (); 2465return nRet ; 2466 } 2467#endif // __ATLSTR_H__ 2468 2469BOOL GetTextMetrics (LPTEXTMETRIC lpMetrics )const 2470 { 2471ATLASSERT (m_hDC != NULL ); 2472return ::GetTextMetrics (m_hDC ,lpMetrics ); 2473 } 2474 2475int SetTextJustification (int nBreakExtra ,int nBreakCount ) 2476 { 2477ATLASSERT (m_hDC != NULL ); 2478return ::SetTextJustification (m_hDC ,nBreakExtra ,nBreakCount ); 2479 } 2480 2481int GetTextCharacterExtra ()const 2482 { 2483ATLASSERT (m_hDC != NULL ); 2484return ::GetTextCharacterExtra (m_hDC ); 2485 } 2486 2487int SetTextCharacterExtra (int nCharExtra ) 2488 { 2489ATLASSERT (m_hDC != NULL ); 2490return ::SetTextCharacterExtra (m_hDC ,nCharExtra ); 2491 } 2492 2493// Advanced Drawing 2494BOOL DrawEdge (LPRECT lpRect ,UINT nEdge ,UINT nFlags ) 2495 { 2496ATLASSERT (m_hDC != NULL ); 2497return ::DrawEdge (m_hDC ,lpRect ,nEdge ,nFlags ); 2498 } 2499 2500BOOL DrawFrameControl (LPRECT lpRect ,UINT nType ,UINT nState ) 2501 { 2502ATLASSERT (m_hDC != NULL ); 2503return ::DrawFrameControl (m_hDC ,lpRect ,nType ,nState ); 2504 } 2505 2506// Scrolling Functions 2507BOOL ScrollDC (int dx ,int dy ,LPCRECT lpRectScroll ,LPCRECT lpRectClip ,HRGN hRgnUpdate ,LPRECT lpRectUpdate ) 2508 { 2509ATLASSERT (m_hDC != NULL ); 2510return ::ScrollDC (m_hDC ,dx ,dy ,lpRectScroll ,lpRectClip ,hRgnUpdate ,lpRectUpdate ); 2511 } 2512 2513// Font Functions 2514BOOL GetCharWidth (UINT nFirstChar ,UINT nLastChar ,LPINT lpBuffer )const 2515 { 2516ATLASSERT (m_hDC != NULL ); 2517return ::GetCharWidth (m_hDC ,nFirstChar ,nLastChar ,lpBuffer ); 2518 } 2519 2520// GetCharWidth32 is not supported under Win9x 2521BOOL GetCharWidth32 (UINT nFirstChar ,UINT nLastChar ,LPINT lpBuffer )const 2522 { 2523ATLASSERT (m_hDC != NULL ); 2524return ::GetCharWidth32 (m_hDC ,nFirstChar ,nLastChar ,lpBuffer ); 2525 } 2526 2527DWORD SetMapperFlags (DWORD dwFlag ) 2528 { 2529ATLASSERT (m_hDC != NULL ); 2530return ::SetMapperFlags (m_hDC ,dwFlag ); 2531 } 2532 2533BOOL GetAspectRatioFilter (LPSIZE lpSize )const 2534 { 2535ATLASSERT (m_hDC != NULL ); 2536return ::GetAspectRatioFilterEx (m_hDC ,lpSize ); 2537 } 2538 2539BOOL GetCharABCWidths (UINT nFirstChar ,UINT nLastChar ,LPABC lpabc )const 2540 { 2541ATLASSERT (m_hDC != NULL ); 2542return ::GetCharABCWidths (m_hDC ,nFirstChar ,nLastChar ,lpabc ); 2543 } 2544 2545DWORD GetFontData (DWORD dwTable ,DWORD dwOffset ,LPVOID lpData ,DWORD cbData )const 2546 { 2547ATLASSERT (m_hDC != NULL ); 2548return ::GetFontData (m_hDC ,dwTable ,dwOffset ,lpData ,cbData ); 2549 } 2550 2551int GetKerningPairs (int nPairs ,LPKERNINGPAIR lpkrnpair )const 2552 { 2553ATLASSERT (m_hDC != NULL ); 2554return ::GetKerningPairs (m_hDC ,nPairs ,lpkrnpair ); 2555 } 2556 2557UINT GetOutlineTextMetrics (UINT cbData ,LPOUTLINETEXTMETRIC lpotm )const 2558 { 2559ATLASSERT (m_hDC != NULL ); 2560return ::GetOutlineTextMetrics (m_hDC ,cbData ,lpotm ); 2561 } 2562 2563DWORD GetGlyphOutline (UINT nChar ,UINT nFormat ,LPGLYPHMETRICS lpgm ,DWORD cbBuffer ,LPVOID lpBuffer ,const MAT2 * lpmat2 )const 2564 { 2565ATLASSERT (m_hDC != NULL ); 2566return ::GetGlyphOutline (m_hDC ,nChar ,nFormat ,lpgm ,cbBuffer ,lpBuffer ,lpmat2 ); 2567 } 2568 2569BOOL GetCharABCWidths (UINT nFirstChar ,UINT nLastChar ,LPABCFLOAT lpABCF )const 2570 { 2571ATLASSERT (m_hDC != NULL ); 2572return ::GetCharABCWidthsFloat (m_hDC ,nFirstChar ,nLastChar ,lpABCF ); 2573 } 2574 2575BOOL GetCharWidth (UINT nFirstChar ,UINT nLastChar ,float * lpFloatBuffer )const 2576 { 2577ATLASSERT (m_hDC != NULL ); 2578return ::GetCharWidthFloat (m_hDC ,nFirstChar ,nLastChar ,lpFloatBuffer ); 2579 } 2580 2581// Printer/Device Escape Functions 2582int Escape (int nEscape ,int nCount ,LPCSTR lpszInData ,LPVOID lpOutData ) 2583 { 2584ATLASSERT (m_hDC != NULL ); 2585return ::Escape (m_hDC ,nEscape ,nCount ,lpszInData ,lpOutData ); 2586 } 2587 2588int Escape (int nEscape ,int nInputSize ,LPCSTR lpszInputData , 2589int nOutputSize ,LPSTR lpszOutputData ) 2590 { 2591ATLASSERT (m_hDC != NULL ); 2592return ::ExtEscape (m_hDC ,nEscape ,nInputSize ,lpszInputData ,nOutputSize ,lpszOutputData ); 2593 } 2594 2595int DrawEscape (int nEscape ,int nInputSize ,LPCSTR lpszInputData ) 2596 { 2597ATLASSERT (m_hDC != NULL ); 2598return ::DrawEscape (m_hDC ,nEscape ,nInputSize ,lpszInputData ); 2599 } 2600 2601// Escape helpers 2602int StartDoc (LPCTSTR lpszDocName )// old Win3.0 version 2603 { 2604DOCINFO di = {}; 2605di .cbSize = sizeof (DOCINFO ); 2606di .lpszDocName = lpszDocName ; 2607return StartDoc (& di ); 2608 } 2609 2610int StartDoc (LPDOCINFO lpDocInfo ) 2611 { 2612ATLASSERT (m_hDC != NULL ); 2613return ::StartDoc (m_hDC ,lpDocInfo ); 2614 } 2615 2616int StartPage () 2617 { 2618ATLASSERT (m_hDC != NULL ); 2619return ::StartPage (m_hDC ); 2620 } 2621 2622int EndPage () 2623 { 2624ATLASSERT (m_hDC != NULL ); 2625return ::EndPage (m_hDC ); 2626 } 2627 2628int SetAbortProc (BOOL (CALLBACK * lpfn )(HDC ,int )) 2629 { 2630ATLASSERT (m_hDC != NULL ); 2631return ::SetAbortProc (m_hDC , (ABORTPROC )lpfn ); 2632 } 2633 2634int AbortDoc () 2635 { 2636ATLASSERT (m_hDC != NULL ); 2637return ::AbortDoc (m_hDC ); 2638 } 2639 2640int EndDoc () 2641 { 2642ATLASSERT (m_hDC != NULL ); 2643return ::EndDoc (m_hDC ); 2644 } 2645 2646// MetaFile Functions 2647BOOL PlayMetaFile (HMETAFILE hMF ) 2648 { 2649ATLASSERT (m_hDC != NULL ); 2650if (::GetDeviceCaps (m_hDC ,TECHNOLOGY )== DT_METAFILE ) 2651 { 2652// playing metafile in metafile, just use core windows API 2653return ::PlayMetaFile (m_hDC ,hMF ); 2654 } 2655 2656// for special playback, lParam == pDC 2657return ::EnumMetaFile (m_hDC ,hMF ,EnumMetaFileProc , (LPARAM )this ); 2658 } 2659 2660BOOL PlayMetaFile (HENHMETAFILE hEnhMetaFile ,LPCRECT lpBounds ) 2661 { 2662ATLASSERT (m_hDC != NULL ); 2663return ::PlayEnhMetaFile (m_hDC ,hEnhMetaFile ,lpBounds ); 2664 } 2665 2666BOOL AddMetaFileComment (UINT nDataSize ,const BYTE * pCommentData )// can be used for enhanced metafiles only 2667 { 2668ATLASSERT (m_hDC != NULL ); 2669return ::GdiComment (m_hDC ,nDataSize ,pCommentData ); 2670 } 2671 2672// Special handling for metafile playback 2673static int CALLBACK EnumMetaFileProc (HDC hDC ,HANDLETABLE * pHandleTable ,METARECORD * pMetaRec ,int nHandles ,LPARAM lParam ) 2674 { 2675CDCT < false>* pDC = (CDCT < false>* )lParam ; 2676 2677switch (pMetaRec -> rdFunction ) 2678 { 2679case META_SETMAPMODE : 2680pDC -> SetMapMode ((int )(short )pMetaRec -> rdParm [0 ]); 2681break ; 2682case META_SETWINDOWEXT : 2683pDC -> SetWindowExt ((int )(short )pMetaRec -> rdParm [1 ], (int )(short )pMetaRec -> rdParm [0 ]); 2684break ; 2685case META_SETWINDOWORG : 2686pDC -> SetWindowOrg ((int )(short )pMetaRec -> rdParm [1 ], (int )(short )pMetaRec -> rdParm [0 ]); 2687break ; 2688case META_SETVIEWPORTEXT : 2689pDC -> SetViewportExt ((int )(short )pMetaRec -> rdParm [1 ], (int )(short )pMetaRec -> rdParm [0 ]); 2690break ; 2691case META_SETVIEWPORTORG : 2692pDC -> SetViewportOrg ((int )(short )pMetaRec -> rdParm [1 ], (int )(short )pMetaRec -> rdParm [0 ]); 2693break ; 2694case META_SCALEWINDOWEXT : 2695pDC -> ScaleWindowExt ((int )(short )pMetaRec -> rdParm [3 ], (int )(short )pMetaRec -> rdParm [2 ], 2696 (int )(short )pMetaRec -> rdParm [1 ], (int )(short )pMetaRec -> rdParm [0 ]); 2697break ; 2698case META_SCALEVIEWPORTEXT : 2699pDC -> ScaleViewportExt ((int )(short )pMetaRec -> rdParm [3 ], (int )(short )pMetaRec -> rdParm [2 ], 2700 (int )(short )pMetaRec -> rdParm [1 ], (int )(short )pMetaRec -> rdParm [0 ]); 2701break ; 2702case META_OFFSETVIEWPORTORG : 2703pDC -> OffsetViewportOrg ((int )(short )pMetaRec -> rdParm [1 ], (int )(short )pMetaRec -> rdParm [0 ]); 2704break ; 2705case META_SAVEDC : 2706pDC -> SaveDC (); 2707break ; 2708case META_RESTOREDC : 2709pDC -> RestoreDC ((int )(short )pMetaRec -> rdParm [0 ]); 2710break ; 2711case META_SETBKCOLOR : 2712pDC -> SetBkColor (* (UNALIGNED COLORREF * )& pMetaRec -> rdParm [0 ]); 2713break ; 2714case META_SETTEXTCOLOR : 2715pDC -> SetTextColor (* (UNALIGNED COLORREF * )& pMetaRec -> rdParm [0 ]); 2716break ; 2717 2718// need to watch out for SelectObject(HFONT), for custom font mapping 2719case META_SELECTOBJECT : 2720 { 2721HGDIOBJ hObject = pHandleTable -> objectHandle [pMetaRec -> rdParm [0 ]]; 2722UINT nObjType = ::GetObjectType (hObject ); 2723if (nObjType == 0 ) 2724 { 2725// object type is unknown, determine if it is a font 2726HFONT hStockFont = (HFONT )::GetStockObject (SYSTEM_FONT ); 2727HFONT hFontOld = (HFONT )::SelectObject (pDC -> m_hDC ,hStockFont ); 2728HGDIOBJ hObjOld = ::SelectObject (pDC -> m_hDC ,hObject ); 2729if (hObjOld == hStockFont ) 2730 { 2731// got the stock object back, so must be selecting a font 2732pDC -> SelectFont ((HFONT )hObject ); 2733break ;// don't play the default record 2734 } 2735else 2736 { 2737// didn't get the stock object back, so restore everything 2738 ::SelectObject (pDC -> m_hDC ,hFontOld ); 2739 ::SelectObject (pDC -> m_hDC ,hObjOld ); 2740 } 2741// and fall through to PlayMetaFileRecord... 2742 } 2743else if (nObjType == OBJ_FONT ) 2744 { 2745// play back as CDCHandle::SelectFont(HFONT) 2746pDC -> SelectFont ((HFONT )hObject ); 2747break ;// don't play the default record 2748 } 2749 } 2750// fall through... 2751 2752default : 2753 ::PlayMetaFileRecord (hDC ,pHandleTable ,pMetaRec ,nHandles ); 2754break ; 2755 } 2756 2757return 1 ; 2758 } 2759 2760// Path Functions 2761BOOL AbortPath () 2762 { 2763ATLASSERT (m_hDC != NULL ); 2764return ::AbortPath (m_hDC ); 2765 } 2766 2767BOOL BeginPath () 2768 { 2769ATLASSERT (m_hDC != NULL ); 2770return ::BeginPath (m_hDC ); 2771 } 2772 2773BOOL CloseFigure () 2774 { 2775ATLASSERT (m_hDC != NULL ); 2776return ::CloseFigure (m_hDC ); 2777 } 2778 2779BOOL EndPath () 2780 { 2781ATLASSERT (m_hDC != NULL ); 2782return ::EndPath (m_hDC ); 2783 } 2784 2785BOOL FillPath () 2786 { 2787ATLASSERT (m_hDC != NULL ); 2788return ::FillPath (m_hDC ); 2789 } 2790 2791BOOL FlattenPath () 2792 { 2793ATLASSERT (m_hDC != NULL ); 2794return ::FlattenPath (m_hDC ); 2795 } 2796 2797BOOL StrokeAndFillPath () 2798 { 2799ATLASSERT (m_hDC != NULL ); 2800return ::StrokeAndFillPath (m_hDC ); 2801 } 2802 2803BOOL StrokePath () 2804 { 2805ATLASSERT (m_hDC != NULL ); 2806return ::StrokePath (m_hDC ); 2807 } 2808 2809BOOL WidenPath () 2810 { 2811ATLASSERT (m_hDC != NULL ); 2812return ::WidenPath (m_hDC ); 2813 } 2814 2815BOOL GetMiterLimit (PFLOAT pfMiterLimit )const 2816 { 2817ATLASSERT (m_hDC != NULL ); 2818return ::GetMiterLimit (m_hDC ,pfMiterLimit ); 2819 } 2820 2821BOOL SetMiterLimit (float fMiterLimit ) 2822 { 2823ATLASSERT (m_hDC != NULL ); 2824return ::SetMiterLimit (m_hDC ,fMiterLimit ,NULL ); 2825 } 2826 2827int GetPath (LPPOINT lpPoints ,LPBYTE lpTypes ,int nCount )const 2828 { 2829ATLASSERT (m_hDC != NULL ); 2830return ::GetPath (m_hDC ,lpPoints ,lpTypes ,nCount ); 2831 } 2832 2833BOOL SelectClipPath (int nMode ) 2834 { 2835ATLASSERT (m_hDC != NULL ); 2836return ::SelectClipPath (m_hDC ,nMode ); 2837 } 2838 2839// Misc Helper Functions 2840static CBrushHandle PASCAL GetHalftoneBrush () 2841 { 2842HBRUSH halftoneBrush = NULL ; 2843WORD grayPattern [8 ]= {}; 2844for (int i = 0 ;i < 8 ;i ++ ) 2845grayPattern [i ]= (WORD )(0x5555 << (i & 1 )); 2846HBITMAP grayBitmap = CreateBitmap (8 ,8 ,1 ,1 ,& grayPattern ); 2847if (grayBitmap != NULL ) 2848 { 2849halftoneBrush = ::CreatePatternBrush (grayBitmap ); 2850DeleteObject (grayBitmap ); 2851 } 2852return CBrushHandle (halftoneBrush ); 2853 } 2854 2855void DrawDragRect (LPCRECT lpRect ,SIZE size ,LPCRECT lpRectLast ,SIZE sizeLast ,HBRUSH hBrush = NULL ,HBRUSH hBrushLast = NULL ) 2856 { 2857// first, determine the update region and select it 2858CRgn rgnOutside ; 2859rgnOutside .CreateRectRgnIndirect (lpRect ); 2860RECT rect = * lpRect ; 2861 ::InflateRect (& rect ,- size .cx ,- size .cy ); 2862 ::IntersectRect (& rect ,& rect ,lpRect ); 2863CRgn rgnInside ; 2864rgnInside .CreateRectRgnIndirect (& rect ); 2865CRgn rgnNew ; 2866rgnNew .CreateRectRgn (0 ,0 ,0 ,0 ); 2867rgnNew .CombineRgn (rgnOutside ,rgnInside ,RGN_XOR ); 2868 2869HBRUSH hBrushOld = NULL ; 2870CBrush brushHalftone ; 2871if (hBrush == NULL ) 2872brushHalftone = hBrush = CDCHandle ::GetHalftoneBrush (); 2873if (hBrushLast == NULL ) 2874hBrushLast = hBrush ; 2875 2876CRgn rgnLast ; 2877CRgn rgnUpdate ; 2878if (lpRectLast != NULL ) 2879 { 2880// find difference between new region and old region 2881rgnLast .CreateRectRgn (0 ,0 ,0 ,0 ); 2882rgnOutside .SetRectRgn (lpRectLast -> left ,lpRectLast -> top ,lpRectLast -> right ,lpRectLast -> bottom ); 2883rect = * lpRectLast ; 2884 ::InflateRect (& rect ,- sizeLast .cx ,- sizeLast .cy ); 2885 ::IntersectRect (& rect ,& rect ,lpRectLast ); 2886rgnInside .SetRectRgn (rect .left ,rect .top ,rect .right ,rect .bottom ); 2887rgnLast .CombineRgn (rgnOutside ,rgnInside ,RGN_XOR ); 2888 2889// only diff them if brushes are the same 2890if (hBrush == hBrushLast ) 2891 { 2892rgnUpdate .CreateRectRgn (0 ,0 ,0 ,0 ); 2893rgnUpdate .CombineRgn (rgnLast ,rgnNew ,RGN_XOR ); 2894 } 2895 } 2896if ((hBrush != hBrushLast )&& (lpRectLast != NULL )) 2897 { 2898// brushes are different -- erase old region first 2899SelectClipRgn (rgnLast ); 2900GetClipBox (& rect ); 2901hBrushOld = SelectBrush (hBrushLast ); 2902PatBlt (rect .left ,rect .top ,rect .right - rect .left ,rect .bottom - rect .top ,PATINVERT ); 2903SelectBrush (hBrushOld ); 2904hBrushOld = NULL ; 2905 } 2906 2907// draw into the update/new region 2908SelectClipRgn (rgnUpdate .IsNull () ?rgnNew :rgnUpdate ); 2909GetClipBox (& rect ); 2910hBrushOld = SelectBrush (hBrush ); 2911PatBlt (rect .left ,rect .top ,rect .right - rect .left ,rect .bottom - rect .top ,PATINVERT ); 2912 2913// cleanup DC 2914if (hBrushOld != NULL ) 2915SelectBrush (hBrushOld ); 2916SelectClipRgn (NULL ); 2917 } 2918 2919void FillSolidRect (LPCRECT lpRect ,COLORREF clr ) 2920 { 2921ATLASSERT (m_hDC != NULL ); 2922 2923COLORREF clrOld = ::SetBkColor (m_hDC ,clr ); 2924ATLASSERT (clrOld != CLR_INVALID ); 2925if (clrOld != CLR_INVALID ) 2926 { 2927 ::ExtTextOut (m_hDC ,0 ,0 ,ETO_OPAQUE ,lpRect ,NULL ,0 ,NULL ); 2928 ::SetBkColor (m_hDC ,clrOld ); 2929 } 2930 } 2931 2932void FillSolidRect (int x ,int y ,int cx ,int cy ,COLORREF clr ) 2933 { 2934ATLASSERT (m_hDC != NULL ); 2935 2936RECT rect = {x ,y ,x + cx ,y + cy }; 2937FillSolidRect (& rect ,clr ); 2938 } 2939 2940void Draw3dRect (LPCRECT lpRect ,COLORREF clrTopLeft ,COLORREF clrBottomRight ) 2941 { 2942Draw3dRect (lpRect -> left ,lpRect -> top ,lpRect -> right - lpRect -> left , 2943lpRect -> bottom - lpRect -> top ,clrTopLeft ,clrBottomRight ); 2944 } 2945 2946void Draw3dRect (int x ,int y ,int cx ,int cy ,COLORREF clrTopLeft ,COLORREF clrBottomRight ) 2947 { 2948FillSolidRect (x ,y ,cx - 1 ,1 ,clrTopLeft ); 2949FillSolidRect (x ,y ,1 ,cy - 1 ,clrTopLeft ); 2950FillSolidRect (x + cx ,y ,-1 ,cy ,clrBottomRight ); 2951FillSolidRect (x ,y + cy ,cx ,-1 ,clrBottomRight ); 2952 } 2953 2954// DIB support 2955int 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 ) 2956 { 2957ATLASSERT (m_hDC != NULL ); 2958return ::SetDIBitsToDevice (m_hDC ,x ,y ,dwWidth ,dwHeight ,xSrc ,ySrc ,uStartScan ,cScanLines ,lpvBits ,lpbmi ,uColorUse ); 2959 } 2960 2961int 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 ) 2962 { 2963ATLASSERT (m_hDC != NULL ); 2964return ::StretchDIBits (m_hDC ,x ,y ,nWidth ,nHeight ,xSrc ,ySrc ,nSrcWidth ,nSrcHeight ,lpvBits ,lpbmi ,uColorUse ,dwRop ); 2965 } 2966 2967UINT GetDIBColorTable (UINT uStartIndex ,UINT cEntries ,RGBQUAD * pColors )const 2968 { 2969ATLASSERT (m_hDC != NULL ); 2970return ::GetDIBColorTable (m_hDC ,uStartIndex ,cEntries ,pColors ); 2971 } 2972 2973UINT SetDIBColorTable (UINT uStartIndex ,UINT cEntries ,CONST RGBQUAD * pColors ) 2974 { 2975ATLASSERT (m_hDC != NULL ); 2976return ::SetDIBColorTable (m_hDC ,uStartIndex ,cEntries ,pColors ); 2977 } 2978 2979// OpenGL support 2980#if !defined(_ATL_NO_OPENGL ) 2981int ChoosePixelFormat (CONST PIXELFORMATDESCRIPTOR * ppfd ) 2982 { 2983ATLASSERT (m_hDC != NULL ); 2984return ::ChoosePixelFormat (m_hDC ,ppfd ); 2985 } 2986 2987int DescribePixelFormat (int iPixelFormat ,UINT nBytes ,LPPIXELFORMATDESCRIPTOR ppfd ) 2988 { 2989ATLASSERT (m_hDC != NULL ); 2990return ::DescribePixelFormat (m_hDC ,iPixelFormat ,nBytes ,ppfd ); 2991 } 2992 2993int GetPixelFormat ()const 2994 { 2995ATLASSERT (m_hDC != NULL ); 2996return ::GetPixelFormat (m_hDC ); 2997 } 2998 2999BOOL SetPixelFormat (int iPixelFormat ,CONST PIXELFORMATDESCRIPTOR * ppfd ) 3000 { 3001ATLASSERT (m_hDC != NULL ); 3002return ::SetPixelFormat (m_hDC ,iPixelFormat ,ppfd ); 3003 } 3004 3005BOOL SwapBuffers () 3006 { 3007ATLASSERT (m_hDC != NULL ); 3008return ::SwapBuffers (m_hDC ); 3009 } 3010 3011HGLRC wglCreateContext () 3012 { 3013ATLASSERT (m_hDC != NULL ); 3014return ::wglCreateContext (m_hDC ); 3015 } 3016 3017HGLRC wglCreateLayerContext (int iLayerPlane ) 3018 { 3019ATLASSERT (m_hDC != NULL ); 3020return ::wglCreateLayerContext (m_hDC ,iLayerPlane ); 3021 } 3022 3023BOOL wglMakeCurrent (HGLRC hglrc ) 3024 { 3025ATLASSERT (m_hDC != NULL ); 3026return ::wglMakeCurrent (m_hDC ,hglrc ); 3027 } 3028 3029BOOL wglUseFontBitmaps (DWORD dwFirst ,DWORD dwCount ,DWORD listBase ) 3030 { 3031ATLASSERT (m_hDC != NULL ); 3032return ::wglUseFontBitmaps (m_hDC ,dwFirst ,dwCount ,listBase ); 3033 } 3034 3035BOOL wglUseFontOutlines (DWORD dwFirst ,DWORD dwCount ,DWORD listBase ,FLOAT deviation ,FLOAT extrusion ,int format ,LPGLYPHMETRICSFLOAT lpgmf ) 3036 { 3037ATLASSERT (m_hDC != NULL ); 3038return ::wglUseFontOutlines (m_hDC ,dwFirst ,dwCount ,listBase ,deviation ,extrusion ,format ,lpgmf ); 3039 } 3040 3041BOOL wglDescribeLayerPlane (int iPixelFormat ,int iLayerPlane ,UINT nBytes ,LPLAYERPLANEDESCRIPTOR plpd ) 3042 { 3043ATLASSERT (m_hDC != NULL ); 3044return ::wglDescribeLayerPlane (m_hDC ,iPixelFormat ,iLayerPlane ,nBytes ,plpd ); 3045 } 3046 3047int wglSetLayerPaletteEntries (int iLayerPlane ,int iStart ,int cEntries ,CONST COLORREF * pclr ) 3048 { 3049ATLASSERT (m_hDC != NULL ); 3050return ::wglSetLayerPaletteEntries (m_hDC ,iLayerPlane ,iStart ,cEntries ,pclr ); 3051 } 3052 3053int wglGetLayerPaletteEntries (int iLayerPlane ,int iStart ,int cEntries ,COLORREF * pclr ) 3054 { 3055ATLASSERT (m_hDC != NULL ); 3056return ::wglGetLayerPaletteEntries (m_hDC ,iLayerPlane ,iStart ,cEntries ,pclr ); 3057 } 3058 3059BOOL wglRealizeLayerPalette (int iLayerPlane ,BOOL bRealize ) 3060 { 3061ATLASSERT (m_hDC != NULL ); 3062return ::wglRealizeLayerPalette (m_hDC ,iLayerPlane ,bRealize ); 3063 } 3064 3065BOOL wglSwapLayerBuffers (UINT uPlanes ) 3066 { 3067ATLASSERT (m_hDC != NULL ); 3068return ::wglSwapLayerBuffers (m_hDC ,uPlanes ); 3069 } 3070#endif // !defined(_ATL_NO_OPENGL) 3071 3072COLORREF GetDCPenColor ()const 3073 { 3074ATLASSERT (m_hDC != NULL ); 3075return ::GetDCPenColor (m_hDC ); 3076 } 3077 3078COLORREF SetDCPenColor (COLORREF clr ) 3079 { 3080ATLASSERT (m_hDC != NULL ); 3081return ::SetDCPenColor (m_hDC ,clr ); 3082 } 3083 3084COLORREF GetDCBrushColor ()const 3085 { 3086ATLASSERT (m_hDC != NULL ); 3087return ::GetDCBrushColor (m_hDC ); 3088 } 3089 3090COLORREF SetDCBrushColor (COLORREF clr ) 3091 { 3092ATLASSERT (m_hDC != NULL ); 3093return ::SetDCBrushColor (m_hDC ,clr ); 3094 } 3095 3096DWORD GetFontUnicodeRanges (LPGLYPHSET lpgs )const 3097 { 3098ATLASSERT (m_hDC != NULL ); 3099return ::GetFontUnicodeRanges (m_hDC ,lpgs ); 3100 } 3101 3102DWORD GetGlyphIndices (LPCTSTR lpstr ,int cch ,LPWORD pgi ,DWORD dwFlags )const 3103 { 3104ATLASSERT (m_hDC != NULL ); 3105return ::GetGlyphIndices (m_hDC ,lpstr ,cch ,pgi ,dwFlags ); 3106 } 3107 3108BOOL GetTextExtentPointI (LPWORD pgiIn ,int cgi ,LPSIZE lpSize )const 3109 { 3110ATLASSERT (m_hDC != NULL ); 3111return ::GetTextExtentPointI (m_hDC ,pgiIn ,cgi ,lpSize ); 3112 } 3113 3114BOOL GetTextExtentExPointI (LPWORD pgiIn ,int cgi ,int nMaxExtent ,LPINT lpnFit ,LPINT alpDx ,LPSIZE lpSize )const 3115 { 3116ATLASSERT (m_hDC != NULL ); 3117return ::GetTextExtentExPointI (m_hDC ,pgiIn ,cgi ,nMaxExtent ,lpnFit ,alpDx ,lpSize ); 3118 } 3119 3120BOOL GetCharWidthI (UINT giFirst ,UINT cgi ,LPWORD pgi ,LPINT lpBuffer )const 3121 { 3122ATLASSERT (m_hDC != NULL ); 3123return ::GetCharWidthI (m_hDC ,giFirst ,cgi ,pgi ,lpBuffer ); 3124 } 3125 3126BOOL GetCharABCWidthsI (UINT giFirst ,UINT cgi ,LPWORD pgi ,LPABC lpabc )const 3127 { 3128ATLASSERT (m_hDC != NULL ); 3129return ::GetCharABCWidthsI (m_hDC ,giFirst ,cgi ,pgi ,lpabc ); 3130 } 3131 3132BOOL ColorCorrectPalette (HPALETTE hPalette ,DWORD dwFirstEntry ,DWORD dwNumOfEntries ) 3133 { 3134ATLASSERT (m_hDC != NULL ); 3135return ::ColorCorrectPalette (m_hDC ,hPalette ,dwFirstEntry ,dwNumOfEntries ); 3136 } 3137}; 3138 3139 3140/////////////////////////////////////////////////////////////////////////////// 3141// CDC Helpers 3142 3143class CPaintDC :public CDC 3144{ 3145public : 3146// Data members 3147HWND m_hWnd ; 3148PAINTSTRUCT m_ps ; 3149 3150// Constructor/destructor 3151CPaintDC (HWND hWnd ) 3152 { 3153ATLASSERT (::IsWindow (hWnd )); 3154m_hWnd = hWnd ; 3155m_hDC = ::BeginPaint (hWnd ,& m_ps ); 3156 } 3157 3158 ~CPaintDC () 3159 { 3160ATLASSERT (m_hDC != NULL ); 3161ATLASSERT (::IsWindow (m_hWnd )); 3162 ::EndPaint (m_hWnd ,& m_ps ); 3163Detach (); 3164 } 3165}; 3166 3167class CClientDC :public CDC 3168{ 3169public : 3170// Data members 3171HWND m_hWnd ; 3172 3173// Constructor/destructor 3174CClientDC (HWND hWnd ) 3175 { 3176ATLASSERT ((hWnd == NULL )|| ::IsWindow (hWnd )); 3177m_hWnd = hWnd ; 3178m_hDC = ::GetDC (hWnd ); 3179 } 3180 3181 ~CClientDC () 3182 { 3183ATLASSERT (m_hDC != NULL ); 3184 ::ReleaseDC (m_hWnd ,Detach ()); 3185 } 3186}; 3187 3188class CWindowDC :public CDC 3189{ 3190public : 3191// Data members 3192HWND m_hWnd ; 3193 3194// Constructor/destructor 3195CWindowDC (HWND hWnd ) 3196 { 3197ATLASSERT ((hWnd == NULL )|| ::IsWindow (hWnd )); 3198m_hWnd = hWnd ; 3199m_hDC = ::GetWindowDC (hWnd ); 3200 } 3201 3202 ~CWindowDC () 3203 { 3204ATLASSERT (m_hDC != NULL ); 3205 ::ReleaseDC (m_hWnd ,Detach ()); 3206 } 3207}; 3208 3209class CMemoryDC :public CDC 3210{ 3211public : 3212// Data members 3213HDC m_hDCOriginal ; 3214RECT m_rcPaint ; 3215CBitmap m_bmp ; 3216HBITMAP m_hBmpOld ; 3217 3218// Constructor/destructor 3219CMemoryDC (HDC hDC ,const RECT & rcPaint ) :m_hDCOriginal (hDC ),m_hBmpOld (NULL ) 3220 { 3221m_rcPaint = rcPaint ; 3222CreateCompatibleDC (m_hDCOriginal ); 3223ATLASSERT (m_hDC != NULL ); 3224m_bmp .CreateCompatibleBitmap (m_hDCOriginal ,m_rcPaint .right - m_rcPaint .left ,m_rcPaint .bottom - m_rcPaint .top ); 3225ATLASSERT (m_bmp .m_hBitmap != NULL ); 3226m_hBmpOld = SelectBitmap (m_bmp ); 3227SetViewportOrg (- m_rcPaint .left ,- m_rcPaint .top ); 3228 } 3229 3230 ~CMemoryDC () 3231 { 3232 ::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 ); 3233SelectBitmap (m_hBmpOld ); 3234 } 3235}; 3236 3237 3238/////////////////////////////////////////////////////////////////////////////// 3239// Enhanced metafile support 3240 3241class CEnhMetaFileInfo 3242{ 3243public : 3244// Data members 3245HENHMETAFILE m_hEMF ; 3246BYTE * m_pBits ; 3247TCHAR * m_pDesc ; 3248ENHMETAHEADER m_header ; 3249PIXELFORMATDESCRIPTOR m_pfd ; 3250 3251// Constructor/destructor 3252CEnhMetaFileInfo (HENHMETAFILE hEMF ) :m_hEMF (hEMF ),m_pBits (NULL ),m_pDesc (NULL ) 3253 { 3254memset (& m_header ,0 ,sizeof (m_header )); 3255memset (& m_pfd ,0 ,sizeof (m_pfd )); 3256 } 3257 3258 ~CEnhMetaFileInfo () 3259 { 3260delete []m_pBits ; 3261delete []m_pDesc ; 3262 } 3263 3264// Operations 3265BYTE * GetEnhMetaFileBits () 3266 { 3267ATLASSERT (m_hEMF != NULL ); 3268UINT nBytes = ::GetEnhMetaFileBits (m_hEMF ,0 ,NULL ); 3269delete []m_pBits ; 3270m_pBits = NULL ; 3271ATLTRY (m_pBits = new BYTE [nBytes ]); 3272if (m_pBits != NULL ) 3273 ::GetEnhMetaFileBits (m_hEMF ,nBytes ,m_pBits ); 3274return m_pBits ; 3275 } 3276 3277LPTSTR GetEnhMetaFileDescription () 3278 { 3279ATLASSERT (m_hEMF != NULL ); 3280UINT nLen = ::GetEnhMetaFileDescription (m_hEMF ,0 ,NULL ); 3281delete []m_pDesc ; 3282m_pDesc = NULL ; 3283ATLTRY (m_pDesc = new TCHAR [nLen ]); 3284if (m_pDesc != NULL ) 3285nLen = ::GetEnhMetaFileDescription (m_hEMF ,nLen ,m_pDesc ); 3286return m_pDesc ; 3287 } 3288 3289ENHMETAHEADER * GetEnhMetaFileHeader () 3290 { 3291ATLASSERT (m_hEMF != NULL ); 3292memset (& m_header ,0 ,sizeof (m_header )); 3293m_header .iType = EMR_HEADER ; 3294m_header .nSize = sizeof (ENHMETAHEADER ); 3295UINT n = ::GetEnhMetaFileHeader (m_hEMF ,sizeof (ENHMETAHEADER ),& m_header ); 3296return (n != 0 ) ?& m_header :NULL ; 3297 } 3298 3299PIXELFORMATDESCRIPTOR * GetEnhMetaFilePixelFormat () 3300 { 3301ATLASSERT (m_hEMF != NULL ); 3302memset (& m_pfd ,0 ,sizeof (m_pfd )); 3303UINT n = ::GetEnhMetaFilePixelFormat (m_hEMF ,sizeof (m_pfd ),& m_pfd ); 3304return (n != 0 ) ?& m_pfd :NULL ; 3305 } 3306}; 3307 3308 3309template < bool t_bManaged > 3310class CEnhMetaFileT 3311{ 3312public : 3313// Data members 3314HENHMETAFILE m_hEMF ; 3315 3316// Constructor/destructor 3317CEnhMetaFileT (HENHMETAFILE hEMF = NULL ) :m_hEMF (hEMF ) 3318 { 3319 } 3320 3321 ~CEnhMetaFileT () 3322 { 3323if (t_bManaged && (m_hEMF != NULL )) 3324DeleteObject (); 3325 } 3326 3327// Operations 3328CEnhMetaFileT < t_bManaged >& operator = (HENHMETAFILE hEMF ) 3329 { 3330Attach (hEMF ); 3331return * this ; 3332 } 3333 3334void Attach (HENHMETAFILE hEMF ) 3335 { 3336if (t_bManaged && (m_hEMF != NULL )&& (m_hEMF != hEMF )) 3337DeleteObject (); 3338m_hEMF = hEMF ; 3339 } 3340 3341HENHMETAFILE Detach () 3342 { 3343HENHMETAFILE hEMF = m_hEMF ; 3344m_hEMF = NULL ; 3345return hEMF ; 3346 } 3347 3348operator HENHMETAFILE ()const {return m_hEMF ; } 3349 3350bool IsNull ()const {return (m_hEMF == NULL ); } 3351 3352BOOL DeleteObject () 3353 { 3354ATLASSERT (m_hEMF != NULL ); 3355BOOL bRet = ::DeleteEnhMetaFile (m_hEMF ); 3356m_hEMF = NULL ; 3357return bRet ; 3358 } 3359 3360UINT GetEnhMetaFileBits (UINT cbBuffer ,LPBYTE lpbBuffer )const 3361 { 3362ATLASSERT (m_hEMF != NULL ); 3363return ::GetEnhMetaFileBits (m_hEMF ,cbBuffer ,lpbBuffer ); 3364 } 3365 3366UINT GetEnhMetaFileDescription (UINT cchBuffer ,LPTSTR lpszDescription )const 3367 { 3368ATLASSERT (m_hEMF != NULL ); 3369return ::GetEnhMetaFileDescription (m_hEMF ,cchBuffer ,lpszDescription ); 3370 } 3371 3372UINT GetEnhMetaFileHeader (LPENHMETAHEADER lpemh )const 3373 { 3374ATLASSERT (m_hEMF != NULL ); 3375lpemh -> iType = EMR_HEADER ; 3376lpemh -> nSize = sizeof (ENHMETAHEADER ); 3377return ::GetEnhMetaFileHeader (m_hEMF ,sizeof (ENHMETAHEADER ),lpemh ); 3378 } 3379 3380UINT GetEnhMetaFilePaletteEntries (UINT cEntries ,LPPALETTEENTRY lppe )const 3381 { 3382ATLASSERT (m_hEMF != NULL ); 3383return ::GetEnhMetaFilePaletteEntries (m_hEMF ,cEntries ,lppe ); 3384 } 3385 3386UINT GetEnhMetaFilePixelFormat (DWORD cbBuffer ,PIXELFORMATDESCRIPTOR * ppfd )const 3387 { 3388ATLASSERT (m_hEMF != NULL ); 3389return ::GetEnhMetaFilePixelFormat (m_hEMF ,cbBuffer ,ppfd ); 3390 } 3391}; 3392 3393typedef CEnhMetaFileT < false> CEnhMetaFileHandle ; 3394typedef CEnhMetaFileT < true> CEnhMetaFile ; 3395 3396 3397class CEnhMetaFileDC :public CDC 3398{ 3399public : 3400// Constructor/destructor 3401CEnhMetaFileDC () 3402 { 3403 } 3404 3405CEnhMetaFileDC (HDC hdc ,LPCRECT lpRect ) 3406 { 3407Create (hdc , NULL,lpRect , NULL); 3408ATLASSERT (m_hDC != NULL ); 3409 } 3410 3411CEnhMetaFileDC (HDC hdcRef ,LPCTSTR lpFilename ,LPCRECT lpRect ,LPCTSTR lpDescription ) 3412 { 3413Create (hdcRef ,lpFilename ,lpRect ,lpDescription ); 3414ATLASSERT (m_hDC != NULL ); 3415 } 3416 3417 ~CEnhMetaFileDC () 3418 { 3419HENHMETAFILE hEMF = Close (); 3420if (hEMF != NULL ) 3421 ::DeleteEnhMetaFile (hEMF ); 3422 } 3423 3424// Operations 3425void Create (HDC hdcRef ,LPCTSTR lpFilename ,LPCRECT lpRect ,LPCTSTR lpDescription ) 3426 { 3427ATLASSERT (m_hDC == NULL ); 3428m_hDC = ::CreateEnhMetaFile (hdcRef ,lpFilename ,lpRect ,lpDescription ); 3429 } 3430 3431HENHMETAFILE Close () 3432 { 3433HENHMETAFILE hEMF = NULL ; 3434if (m_hDC != NULL ) 3435 { 3436hEMF = ::CloseEnhMetaFile (m_hDC ); 3437m_hDC = NULL ; 3438 } 3439return hEMF ; 3440 } 3441}; 3442 3443}// namespace WTL 3444 3445#endif // __ATLGDI_H__