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