1 // Win32++ Version 7.3
\r
2 // Released: 30th November 2011
\r
6 // url: https://sourceforge.net/projects/win32-framework
\r
9 // Copyright (c) 2005-2011 David Nash
\r
11 // Permission is hereby granted, free of charge, to
\r
12 // any person obtaining a copy of this software and
\r
13 // associated documentation files (the "Software"),
\r
14 // to deal in the Software without restriction, including
\r
15 // without limitation the rights to use, copy, modify,
\r
16 // merge, publish, distribute, sublicense, and/or sell
\r
17 // copies of the Software, and to permit persons to whom
\r
18 // the Software is furnished to do so, subject to the
\r
19 // following conditions:
\r
21 // The above copyright notice and this permission notice
\r
22 // shall be included in all copies or substantial portions
\r
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
\r
26 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
\r
27 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
\r
28 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
\r
29 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
\r
30 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
31 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
32 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
\r
33 // OR OTHER DEALINGS IN THE SOFTWARE.
\r
35 ////////////////////////////////////////////////////////
\r
38 ////////////////////////////////////////////////////////
\r
40 // Declaration of the CDC class, and CBitmapInfoPtr class
\r
42 // The CDC class provides a device context, along with the various associated
\r
43 // objects such as Bitmaps, Brushes, Bitmaps, Fonts and Pens. This class
\r
44 // handles the creation, selection, de-selection and deletion of these objects
\r
45 // automatically. It also automatically deletes or releases the device context
\r
46 // itself as appropriate. Any failure to create the new GDI object throws an
\r
49 // The CDC class is sufficient for most GDI programming needs. Sometimes
\r
50 // however we need to have the GDI object seperated from the device context.
\r
51 // Wrapper classes for GDI objects are provided for this purpose. The classes
\r
52 // are CBitmap, CBrush, CFont, CPalette, CPen and CRgn. These classes
\r
53 // automatically delete the GDI resouce assigned to them when their destructor
\r
54 // is called. These wrapper class objects can be attached to the CDC as
\r
57 // Coding Exampe without CDC ...
\r
60 // HDC hdcClient = ::GetDC(m_hWnd);
\r
61 // HDC hdcMem = ::CreateCompatibleDC(hdcClient);
\r
62 // HBITMAP hBitmap = ::CreateCompatibleBitmap(hdcClient, cx, cy);
\r
63 // HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hdcMem, hBitmap);
\r
64 // HPEN hPen = ::CreatePen(PS_SOLID, 1, RGB(255,0,0);
\r
65 // HPEN hOldPen = (HPEN)::SelectObject(hdcMem, hPen);
\r
66 // ::MoveToEx(hdcMem, 0, 0, NULL);
\r
67 // ::LineTo(hdcMem, 50, 50);
\r
68 // ::BitBlt(hdcClient, 0, 0, cx, cy, hdcMem, 0, 0);
\r
69 // ::SelectObject(hdcMem, hOldPen);
\r
70 // ::DeleteObject(hPen);
\r
71 // ::SelectObject(hdcMem, hOldBitmap);
\r
72 // ::DeleteObject(hBitmap);
\r
73 // ::DeleteDC(hdcMem);
\r
74 // ::ReleaseDC(m_hWnd, hdcClient);
\r
77 // Coding Example with CDC classes ...
\r
80 // CClientDC dcClient(this)
\r
81 // CMemDC dcMem(&dcClient);
\r
82 // dcMem.CreateCompatibleBitmap(&dcClient, cx, cy);
\r
83 // CPen* pOldPen = CMemDC.CreatePen(PS_SOLID, 1, RGB(255,0,0);
\r
84 // CMemDC.MoveTo(0, 0);
\r
85 // CMemDC.LineTo(50, 50);
\r
86 // dcClient.BitBlt(0, 0, cx, cy, &CMemDC, 0, 0);
\r
89 // Coding Example with CDC classes and CPen ...
\r
92 // CClientDC dcClient(this)
\r
93 // CMemDC CMemDC(&dcClient);
\r
94 // dcMem.CreateCompatibleBitmap(&dcClient, cx, cy);
\r
95 // CPen MyPen(PS_SOLID, 1, RGB(255,0,0));
\r
96 // CPen* pOldPen = CMemDC.SelectObject(&MyPen);
\r
97 // CMemDC.MoveTo(0, 0);
\r
98 // CMemDC.LineTo(50, 50);
\r
99 // dcClient.BitBlt(0, 0, cx, cy, &CMemDC, 0, 0);
\r
103 // * When the CDC object drops out of scope, it's destructor is called, releasing
\r
104 // or deleting the device context as appropriate.
\r
105 // * When the destructor for CBitmap, CBrush, CPalette, CPen and CRgn are called,
\r
106 // the destructor is called deleting their GDI object.
\r
107 // * When the CDC object' destructor is called, any GDI objects created by one of
\r
108 // the CDC member functions (CDC::CreatePen for example) will be deleted.
\r
109 // * Bitmaps can only be selected into one device context at a time.
\r
110 // * Palettes use SelectPalatte to select them into device the context.
\r
111 // * Regions use SelectClipRgn to select them into the device context.
\r
112 // * The FromHandle function can be used to convert a GDI handle (HDC, HPEN,
\r
113 // HBITMAP etc) to a pointer of the appropriate GDI class (CDC, CPen CBitmap etc).
\r
114 // The FromHandle function creates a temporary object unless the HANDLE is already
\r
115 // assigned to a GDI class. Temporary objects don't delete their GDI object when
\r
116 // their destructor is called.
\r
117 // * All the GDI classes are reference counted. This allows functions to safely
\r
118 // pass these objects by value, as well as by pointer or by reference.
\r
120 // The CBitmapInfoPtr class is a convienient wrapper for the BITMAPINFO structure.
\r
121 // The size of the BITMAPINFO structure is dependant on the type of HBITMAP, and its
\r
122 // space needs to be allocated dynamically. CBitmapInfoPtr automatically allocates
\r
123 // and deallocates the memory for the structure. A CBitmapInfoPtr object can be
\r
124 // used anywhere in place of a LPBITMAPINFO. LPBITMAPINFO is used in functions like
\r
125 // GetDIBits and SetDIBits.
\r
127 // Coding example ...
\r
128 // CDC MemDC = CreateCompatibleDC(NULL);
\r
129 // CBitmapInfoPtr pbmi(hBitmap);
\r
130 // MemDC.GetDIBits(hBitmap, 0, pbmi->bmiHeader.biHeight, NULL, pbmi, DIB_RGB_COLORS);
\r
132 #ifndef _WIN32XX_GDI_H_
\r
133 #define _WIN32XX_GDI_H_
\r
135 #include "wincore.h"
\r
137 // Disable macros from Windowsx.h
\r
143 /////////////////////////////////////////////////////////////////
\r
144 // Declarations for some global functions in the Win32xx namespace
\r
147 void GrayScaleBitmap(CBitmap* pbmSource);
\r
148 void TintBitmap(CBitmap* pbmSource, int cRed, int cGreen, int cBlue);
\r
149 HIMAGELIST CreateDisabledImageList(HIMAGELIST himlNormal);
\r
152 ///////////////////////////////////////////////
\r
153 // Declarations for the CGDIObject class
\r
157 friend CBitmap* FromHandle(HBITMAP hBitmap);
\r
158 friend CBrush* FromHandle(HBRUSH hBrush);
\r
159 friend CDC* FromHandle(HDC hDC);
\r
160 friend CFont* FromHandle(HFONT hFont);
\r
161 friend CPalette* FromHandle(HPALETTE hPalette);
\r
162 friend CPen* FromHandle(HPEN hPen);
\r
163 friend CRgn* FromHandle(HRGN hRgn);
\r
166 struct DataMembers // A structure that contains the data members for CGDIObject
\r
168 HGDIOBJ hGDIObject;
\r
170 BOOL bRemoveObject;
\r
173 CGDIObject(const CGDIObject& rhs);
\r
174 virtual ~CGDIObject();
\r
175 CGDIObject& operator = ( const CGDIObject& rhs );
\r
176 void operator = (HGDIOBJ hObject);
\r
178 void Attach(HGDIOBJ hObject);
\r
179 void DeleteObject();
\r
181 HGDIOBJ GetHandle() const;
\r
182 int GetObject(int nCount, LPVOID pObject) const;
\r
185 DataMembers* m_pData;
\r
189 BOOL RemoveFromMap();
\r
194 ///////////////////////////////////////////////
\r
195 // Declarations for the CBitmap class
\r
197 class CBitmap : public CGDIObject
\r
201 CBitmap(HBITMAP hBitmap);
\r
202 CBitmap(LPCTSTR lpstr);
\r
204 operator HBITMAP() const;
\r
207 // Create and load methods
\r
208 BOOL LoadBitmap(LPCTSTR lpszName);
\r
209 BOOL LoadBitmap(int nID);
\r
210 BOOL LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad);
\r
211 BOOL LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad);
\r
212 BOOL LoadOEMBitmap(UINT nIDBitmap);
\r
213 HBITMAP CreateBitmap(int nWidth, int nHeight, UINT nPlanes, UINT nBitsPerPixel, LPCVOID lpBits);
\r
214 HBITMAP CreateCompatibleBitmap(CDC* pDC, int nWidth, int nHeight);
\r
215 HBITMAP CreateDIBSection(CDC* pDC, CONST BITMAPINFO* lpbmi, UINT uColorUse, LPVOID* ppvBits, HANDLE hSection, DWORD dwOffset);
\r
218 HBITMAP CreateDIBitmap(CDC* pDC, CONST BITMAPINFOHEADER* lpbmih, DWORD dwInit, LPCVOID lpbInit, CONST BITMAPINFO* lpbmi, UINT uColorUse);
\r
219 HBITMAP CreateMappedBitmap(UINT nIDBitmap, UINT nFlags = 0, LPCOLORMAP lpColorMap = NULL, int nMapSize = 0);
\r
220 HBITMAP CreateBitmapIndirect(LPBITMAP lpBitmap);
\r
221 int GetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT uColorUse) const;
\r
222 int SetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, CONST VOID* lpvBits, CONST BITMAPINFO* lpbmi, UINT uColorUse);
\r
223 CSize GetBitmapDimensionEx() const;
\r
224 CSize SetBitmapDimensionEx(int nWidth, int nHeight);
\r
225 #endif // !_WIN32_WCE
\r
228 BITMAP GetBitmapData() const;
\r
232 ///////////////////////////////////////////////
\r
233 // Declarations for the CBrush class
\r
235 class CBrush : public CGDIObject
\r
239 CBrush(HBRUSH hBrush);
\r
240 CBrush(COLORREF crColor);
\r
241 operator HBRUSH() const;
\r
244 HBRUSH CreateSolidBrush(COLORREF crColor);
\r
245 HBRUSH CreatePatternBrush(CBitmap* pBitmap);
\r
246 LOGBRUSH GetLogBrush() const;
\r
249 HBRUSH CreateHatchBrush(int nIndex, COLORREF crColor);
\r
250 HBRUSH CreateBrushIndirect(LPLOGBRUSH lpLogBrush);
\r
251 HBRUSH CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec);
\r
252 HBRUSH CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT nUsage);
\r
253 #endif // !defined(_WIN32_WCE)
\r
258 ///////////////////////////////////////////////
\r
259 // Declarations for the CFont class
\r
261 class CFont : public CGDIObject
\r
265 CFont(HFONT hFont);
\r
266 CFont(const LOGFONT* lpLogFont);
\r
267 operator HFONT() const;
\r
271 HFONT CreateFontIndirect(const LOGFONT* lpLogFont);
\r
272 HFONT CreatePointFont(int nPointSize, LPCTSTR lpszFaceName, CDC* pDC = NULL, BOOL bBold = FALSE, BOOL bItalic = FALSE);
\r
273 HFONT CreatePointFontIndirect(const LOGFONT* lpLogFont, CDC* pDC = NULL);
\r
276 HFONT CreateFont(int nHeight, int nWidth, int nEscapement,
\r
277 int nOrientation, int nWeight, DWORD dwItalic, DWORD dwUnderline,
\r
278 DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision,
\r
279 DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily,
\r
280 LPCTSTR lpszFacename);
\r
281 #endif // #ifndef _WIN32_WCE
\r
284 LOGFONT GetLogFont() const;
\r
288 ///////////////////////////////////////////////
\r
289 // Declarations for the CPalette class
\r
291 class CPalette : public CGDIObject
\r
295 CPalette(HPALETTE hPalette);
\r
296 operator HPALETTE() const;
\r
300 HPALETTE CreatePalette(LPLOGPALETTE lpLogPalette);
\r
303 HPALETTE CreateHalftonePalette(CDC* pDC);
\r
304 #endif // !_WIN32_WCE
\r
307 int GetEntryCount() const;
\r
308 UINT GetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors) const;
\r
309 UINT SetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors);
\r
313 BOOL ResizePalette(UINT nNumEntries);
\r
314 void AnimatePalette(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors);
\r
315 #endif // !_WIN32_WCE
\r
317 UINT GetNearestPaletteIndex (COLORREF crColor) const;
\r
322 ///////////////////////////////////////////////
\r
323 // Declarations for the CPen class
\r
325 class CPen : public CGDIObject
\r
330 CPen(int nPenStyle, int nWidth, COLORREF crColor);
\r
332 CPen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL);
\r
333 #endif // !_WIN32_WCE
\r
334 operator HPEN() const;
\r
337 HPEN CreatePen(int nPenStyle, int nWidth, COLORREF crColor);
\r
338 HPEN CreatePenIndirect(LPLOGPEN lpLogPen);
\r
339 LOGPEN GetLogPen() const;
\r
342 HPEN ExtCreatePen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL);
\r
343 EXTLOGPEN GetExtLogPen() const;
\r
344 #endif // !_WIN32_WCE
\r
349 ///////////////////////////////////////////////
\r
350 // Declarations for the CRgn class
\r
352 class CRgn : public CGDIObject
\r
357 operator HRGN() const;
\r
361 HRGN CreateRectRgn(int x1, int y1, int x2, int y2);
\r
362 HRGN CreateRectRgnIndirect(const RECT& rc);
\r
363 HRGN CreateFromData(const XFORM* lpXForm, int nCount, const RGNDATA* pRgnData);
\r
366 HRGN CreateEllipticRgn(int x1, int y1, int x2, int y2);
\r
367 HRGN CreateEllipticRgnIndirect(const RECT& rc);
\r
368 HRGN CreatePolygonRgn(LPPOINT lpPoints, int nCount, int nMode);
\r
369 HRGN CreatePolyPolygonRgn(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount, int nPolyFillMode);
\r
370 HRGN CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3);
\r
371 HRGN CreateFromPath(HDC hDC);
\r
372 #endif // !_WIN32_WCE
\r
375 void SetRectRgn(int x1, int y1, int x2, int y2);
\r
376 void SetRectRgn(const RECT& rc);
\r
377 int CombineRgn(CRgn* pRgnSrc1, CRgn* pRgnSrc2, int nCombineMode);
\r
378 int CombineRgn(CRgn* pRgnSrc, int nCombineMode);
\r
379 int CopyRgn(CRgn* pRgnSrc);
\r
380 BOOL EqualRgn(CRgn* pRgn) const;
\r
381 int OffsetRgn(int x, int y);
\r
382 int OffsetRgn(POINT& pt);
\r
383 int GetRgnBox(RECT& rc) const;
\r
384 BOOL PtInRegion(int x, int y) const;
\r
385 BOOL PtInRegion(POINT& pt) const;
\r
386 BOOL RectInRegion(const RECT& rc) const;
\r
387 int GetRegionData(LPRGNDATA lpRgnData, int nDataSize) const;
\r
391 ///////////////////////////////////////////////
\r
392 // Declarations for the CDC class
\r
396 friend class CWinApp;
\r
398 friend CDC* FromHandle(HDC hDC);
\r
401 struct DataMembers // A structure that contains the data members for CDC
\r
403 std::vector<GDIPtr> m_vGDIObjects; // Smart pointers to internally created Bitmaps, Brushes, Fonts, Bitmaps and Regions
\r
404 HDC hDC; // The HDC belonging to this CDC
\r
405 long Count; // Reference count
\r
406 BOOL bRemoveHDC; // Delete/Release the HDC on destruction
\r
407 HWND hWnd; // The HWND of a Window or Client window DC
\r
408 int nSavedDCState; // The save state of the HDC.
\r
411 CDC(); // Constructs a new CDC without assigning a HDC
\r
412 CDC(HDC hDC, HWND hWnd = 0); // Assigns a HDC to a new CDC
\r
413 CDC(const CDC& rhs); // Constructs a new copy of the CDC
\r
415 operator HDC() const { return m_pData->hDC; } // Converts a CDC to a HDC
\r
416 CDC& operator = (const CDC& rhs); // Assigns a CDC to an existing CDC
\r
418 void Attach(HDC hDC, HWND hWnd = 0);
\r
421 HDC GetHDC() const { return m_pData->hDC; }
\r
422 CPalette* SelectPalette(const CPalette* pPalette, BOOL bForceBkgnd);
\r
423 CBitmap* SelectObject(const CBitmap* pBitmap);
\r
424 CBrush* SelectObject(const CBrush* pBrush);
\r
425 CFont* SelectObject(const CFont* pFont);
\r
426 CPalette* SelectObject(const CPalette* pPalette);
\r
427 CPen* SelectObject(const CPen* pPen);
\r
430 void operator = (const HDC hDC);
\r
434 BOOL CreateCompatibleDC(CDC* pDC);
\r
435 BOOL CreateDC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData);
\r
436 int GetDeviceCaps(int nIndex) const;
\r
438 BOOL CreateIC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData);
\r
441 // Create and Select Bitmaps
\r
442 void CreateBitmap(int cx, int cy, UINT Planes, UINT BitsPerPixel, LPCVOID pvColors);
\r
443 void CreateCompatibleBitmap(CDC* pDC, int cx, int cy);
\r
444 void CreateDIBSection(CDC* pDC, const BITMAPINFO& bmi, UINT iUsage, LPVOID *ppvBits,
\r
445 HANDLE hSection, DWORD dwOffset);
\r
447 CBitmap DetachBitmap();
\r
448 BITMAP GetBitmapData() const;
\r
449 BOOL LoadBitmap(UINT nID);
\r
450 BOOL LoadBitmap(LPCTSTR lpszName);
\r
451 BOOL LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad);
\r
452 BOOL LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad);
\r
453 BOOL LoadOEMBitmap(UINT nIDBitmap); // for OBM_/OCR_/OIC
\r
456 void CreateBitmapIndirect(LPBITMAP pBitmap);
\r
457 void CreateDIBitmap(CDC* pDC, const BITMAPINFOHEADER& bmih, DWORD fdwInit, LPCVOID lpbInit,
\r
458 BITMAPINFO& bmi, UINT fuUsage);
\r
459 void CreateMappedBitmap(UINT nIDBitmap, UINT nFlags /*= 0*/, LPCOLORMAP lpColorMap /*= NULL*/, int nMapSize /*= 0*/);
\r
462 // Create and Select Brushes
\r
463 void CreatePatternBrush(CBitmap* pBitmap);
\r
464 void CreateSolidBrush(COLORREF rbg);
\r
465 LOGBRUSH GetLogBrush() const;
\r
468 void CreateBrushIndirect(LPLOGBRUSH pLogBrush);
\r
469 void CreateHatchBrush(int fnStyle, COLORREF rgb);
\r
470 void CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec);
\r
471 void CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT iUsage);
\r
474 // Create and Select Fonts
\r
475 void CreateFontIndirect(LPLOGFONT plf);
\r
476 LOGFONT GetLogFont() const;
\r
479 void CreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight,
\r
480 DWORD fdwItalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet,
\r
481 DWORD fdwOutputPrecision, DWORD fdwClipPrecision, DWORD fdwQuality,
\r
482 DWORD fdwPitchAndFamily, LPCTSTR lpszFace);
\r
485 // Create and Select Pens
\r
486 void CreatePen(int nStyle, int nWidth, COLORREF rgb);
\r
487 void CreatePenIndirect(LPLOGPEN pLogPen);
\r
488 LOGPEN GetLogPen() const;
\r
490 // Create Select Regions
\r
491 int CreateRectRgn(int left, int top, int right, int bottom);
\r
492 int CreateRectRgnIndirect(const RECT& rc);
\r
493 int CreateFromData(const XFORM* Xform, DWORD nCount, const RGNDATA *pRgnData);
\r
495 int CreateEllipticRgn(int left, int top, int right, int bottom);
\r
496 int CreateEllipticRgnIndirect(const RECT& rc);
\r
497 int CreatePolygonRgn(LPPOINT ppt, int cPoints, int fnPolyFillMode);
\r
498 int CreatePolyPolygonRgn(LPPOINT ppt, LPINT pPolyCounts, int nCount, int fnPolyFillMode);
\r
501 // Wrappers for WinAPI functions
\r
503 // Point and Line Drawing Functions
\r
504 CPoint GetCurrentPosition() const;
\r
505 CPoint MoveTo(int x, int y) const;
\r
506 CPoint MoveTo(POINT pt) const;
\r
507 BOOL LineTo(int x, int y) const;
\r
508 BOOL LineTo(POINT pt) const;
\r
509 COLORREF GetPixel(int x, int y) const;
\r
510 COLORREF GetPixel(POINT pt) const;
\r
511 COLORREF SetPixel(int x, int y, COLORREF crColor) const;
\r
512 COLORREF SetPixel(POINT pt, COLORREF crColor) const;
\r
514 BOOL Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const;
\r
515 BOOL Arc(RECT& rc, POINT ptStart, POINT ptEnd) const;
\r
516 BOOL ArcTo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const;
\r
517 BOOL ArcTo(RECT& rc, POINT ptStart, POINT ptEnd) const;
\r
518 BOOL AngleArc(int x, int y, int nRadius, float fStartAngle, float fSweepAngle) const;
\r
519 int GetArcDirection() const;
\r
520 int SetArcDirection(int nArcDirection) const;
\r
521 BOOL PolyDraw(const POINT* lpPoints, const BYTE* lpTypes, int nCount) const;
\r
522 BOOL Polyline(LPPOINT lpPoints, int nCount) const;
\r
523 BOOL PolyPolyline(const POINT* lpPoints, const DWORD* lpPolyPoints, int nCount) const;
\r
524 BOOL PolylineTo(const POINT* lpPoints, int nCount) const;
\r
525 BOOL PolyBezier(const POINT* lpPoints, int nCount) const;
\r
526 BOOL PolyBezierTo(const POINT* lpPoints, int nCount) const;
\r
527 BOOL SetPixelV(int x, int y, COLORREF crColor) const;
\r
528 BOOL SetPixelV(POINT pt, COLORREF crColor) const;
\r
531 // Shape Drawing Functions
\r
532 void DrawFocusRect(const RECT& rc) const;
\r
533 BOOL Ellipse(int x1, int y1, int x2, int y2) const;
\r
534 BOOL Ellipse(const RECT& rc) const;
\r
535 BOOL Polygon(LPPOINT lpPoints, int nCount) const;
\r
536 BOOL Rectangle(int x1, int y1, int x2, int y2) const;
\r
537 BOOL Rectangle(const RECT& rc) const;
\r
538 BOOL RoundRect(int x1, int y1, int x2, int y2, int nWidth, int nHeight) const;
\r
539 BOOL RoundRect(const RECT& rc, int nWidth, int nHeight) const;
\r
542 BOOL Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const;
\r
543 BOOL Chord(const RECT& rc, POINT ptStart, POINT ptEnd) const;
\r
544 BOOL Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const;
\r
545 BOOL Pie(const RECT& rc, POINT ptStart, POINT ptEnd) const;
\r
546 BOOL PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount) const;
\r
549 // Fill and Image Drawing functions
\r
550 BOOL FillRect(const RECT& rc, CBrush* pBrushr) const;
\r
551 BOOL InvertRect(const RECT& rc) const;
\r
552 BOOL DrawIconEx(int xLeft, int yTop, HICON hIcon, int cxWidth, int cyWidth, UINT istepIfAniCur, CBrush* pFlickerFreeDraw, UINT diFlags) const;
\r
553 BOOL DrawEdge(const RECT& rc, UINT nEdge, UINT nFlags) const;
\r
554 BOOL DrawFrameControl(const RECT& rc, UINT nType, UINT nState) const;
\r
555 BOOL FillRgn(CRgn* pRgn, CBrush* pBrush) const;
\r
556 void GradientFill(COLORREF Color1, COLORREF Color2, const RECT& rc, BOOL bVertical);
\r
557 void SolidFill(COLORREF Color, const RECT& rc);
\r
560 BOOL DrawIcon(int x, int y, HICON hIcon) const;
\r
561 BOOL DrawIcon(POINT point, HICON hIcon) const;
\r
562 BOOL FrameRect(const RECT& rc, CBrush* pBrush) const;
\r
563 BOOL PaintRgn(CRgn* pRgn) const;
\r
566 // Bitmap Functions
\r
567 void DrawBitmap(int x, int y, int cx, int cy, CBitmap& Bitmap, COLORREF clrMask);
\r
568 int StretchDIBits(int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth,
\r
569 int nSrcHeight, CONST VOID *lpBits, BITMAPINFO& bi, UINT iUsage, DWORD dwRop) const;
\r
570 BOOL PatBlt(int x, int y, int nWidth, int nHeight, DWORD dwRop) const;
\r
571 BOOL BitBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop) const;
\r
572 BOOL StretchBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop) const;
\r
575 int GetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbi, UINT uUsage) const;
\r
576 int SetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, CONST VOID *lpvBits, LPBITMAPINFO lpbi, UINT fuColorUse) const;
\r
577 int GetStretchBltMode() const;
\r
578 int SetStretchBltMode(int iStretchMode) const;
\r
579 BOOL FloodFill(int x, int y, COLORREF crColor) const;
\r
580 BOOL ExtFloodFill(int x, int y, COLORREF crColor, UINT nFillType) const;
\r
584 #ifdef GetDCBrushColor
\r
585 COLORREF GetDCBrushColor() const;
\r
586 COLORREF SetDCBrushColor(COLORREF crColor) const;
\r
589 // Clipping Functions
\r
590 int ExcludeClipRect(int Left, int Top, int Right, int BottomRect);
\r
591 int ExcludeClipRect(const RECT& rc);
\r
592 int GetClipBox(RECT& rc);
\r
593 int GetClipRgn(HRGN hrgn);
\r
594 int IntersectClipRect(int Left, int Top, int Right, int Bottom);
\r
595 int IntersectClipRect(const RECT& rc);
\r
596 BOOL RectVisible(const RECT& rc);
\r
597 int SelectClipRgn(CRgn* pRgn);
\r
600 int ExtSelectClipRgn(CRgn* pRgn, int fnMode);
\r
601 int OffsetClipRgn(int nXOffset, int nYOffset);
\r
602 BOOL PtVisible(int X, int Y);
\r
605 // Co-ordinate Functions
\r
607 BOOL DPtoLP(LPPOINT lpPoints, int nCount) const;
\r
608 BOOL DPtoLP(RECT& rc) const;
\r
609 BOOL LPtoDP(LPPOINT lpPoints, int nCount) const;
\r
610 BOOL LPtoDP(RECT& rc) const;
\r
613 // Layout Functions
\r
614 DWORD GetLayout() const;
\r
615 DWORD SetLayout(DWORD dwLayout) const;
\r
617 // Mapping functions
\r
619 int GetMapMode() const;
\r
620 int SetMapMode(int nMapMode) const;
\r
621 BOOL GetViewportOrgEx(LPPOINT lpPoint) const;
\r
622 BOOL SetViewportOrgEx(int x, int y, LPPOINT lpPoint = NULL) const;
\r
623 BOOL SetViewportOrgEx(POINT point, LPPOINT lpPointRet = NULL) const;
\r
624 BOOL OffsetViewportOrgEx(int nWidth, int nHeight, LPPOINT lpPoint = NULL) const;
\r
625 BOOL GetViewportExtEx(LPSIZE lpSize) const;
\r
626 BOOL SetViewportExtEx(int x, int y, LPSIZE lpSize) const;
\r
627 BOOL SetViewportExtEx(SIZE size, LPSIZE lpSizeRet) const;
\r
628 BOOL ScaleViewportExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize) const;
\r
629 BOOL OffsetWindowOrg(int nWidth, int nHeight, LPPOINT lpPoint) const;
\r
630 BOOL GetWindowExtEx(LPSIZE lpSize) const;
\r
631 BOOL SetWindowExtEx(int x, int y, LPSIZE lpSize) const;
\r
632 BOOL SetWindowExtEx(SIZE size, LPSIZE lpSizeRet) const;
\r
633 BOOL ScaleWindowExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize) const;
\r
634 BOOL GetWindowOrgEx(LPPOINT lpPoint) const;
\r
635 BOOL SetWindowOrgEx(int x, int y, LPPOINT lpPoint) const;
\r
636 BOOL SetWindowOrgEx(POINT point, LPPOINT lpPointRet) const;
\r
637 BOOL OffsetWindowOrgEx(int nWidth, int nHeight, LPPOINT lpPoint) const;
\r
640 // Printer Functions
\r
641 int StartDoc(LPDOCINFO lpDocInfo) const;
\r
642 int EndDoc() const;
\r
643 int StartPage() const;
\r
644 int EndPage() const;
\r
645 int AbortDoc() const;
\r
646 int SetAbortProc(BOOL (CALLBACK* lpfn)(HDC, int)) const;
\r
649 int DrawText(LPCTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat) const;
\r
650 BOOL ExtTextOut(int x, int y, UINT nOptions, LPCRECT lprc, LPCTSTR lpszString, int nCount = -1, LPINT lpDxWidths = NULL) const;
\r
651 COLORREF GetBkColor() const;
\r
652 int GetBkMode() const;
\r
653 UINT GetTextAlign() const;
\r
654 int GetTextFace(int nCount, LPTSTR lpszFacename) const;
\r
655 COLORREF GetTextColor() const;
\r
656 BOOL GetTextMetrics(TEXTMETRIC& Metrics) const;
\r
657 COLORREF SetBkColor(COLORREF crColor) const;
\r
658 int SetBkMode(int iBkMode) const;
\r
659 UINT SetTextAlign(UINT nFlags) const;
\r
660 COLORREF SetTextColor(COLORREF crColor) const;
\r
663 int DrawTextEx(LPTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat, LPDRAWTEXTPARAMS lpDTParams) const;
\r
664 CSize GetTabbedTextExtent(LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions) const;
\r
665 int GetTextCharacterExtra() const;
\r
666 CSize GetTextExtentPoint32(LPCTSTR lpszString, int nCount) const;
\r
667 BOOL GrayString(CBrush* pBrush, GRAYSTRINGPROC lpOutputFunc, LPARAM lpData, int nCount, int x, int y, int nWidth, int nHeight) const;
\r
668 int SetTextCharacterExtra(int nCharExtra) const;
\r
669 int SetTextJustification(int nBreakExtra, int nBreakCount) const;
\r
670 CSize TabbedTextOut(int x, int y, LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin) const;
\r
671 BOOL TextOut(int x, int y, LPCTSTR lpszString, int nCount = -1) const;
\r
676 static CDC* AddTempHDC(HDC hDC, HWND hWnd);
\r
678 BOOL RemoveFromMap();
\r
680 DataMembers* m_pData; // pointer to the class's data members
\r
683 class CClientDC : public CDC
\r
686 CClientDC(const CWnd* pWnd)
\r
688 if (pWnd) assert(pWnd->IsWindow());
\r
689 HWND hWnd = pWnd? pWnd->GetHwnd() : GetDesktopWindow();
\r
690 Attach(::GetDC(hWnd), hWnd);
\r
692 virtual ~CClientDC() {}
\r
695 class CMemDC : public CDC
\r
698 CMemDC(const CDC* pDC)
\r
700 if (pDC) assert(pDC->GetHDC());
\r
701 HDC hDC = pDC? pDC->GetHDC() : NULL;
\r
702 Attach(::CreateCompatibleDC(hDC));
\r
704 virtual ~CMemDC() {}
\r
707 class CPaintDC : public CDC
\r
710 CPaintDC(const CWnd* pWnd)
\r
712 assert(pWnd->IsWindow());
\r
713 m_hWnd = pWnd->GetHwnd();
\r
714 Attach(::BeginPaint(pWnd->GetHwnd(), &m_ps), m_hWnd);
\r
717 virtual ~CPaintDC() { ::EndPaint(m_hWnd, &m_ps); }
\r
724 class CWindowDC : public CDC
\r
727 CWindowDC(const CWnd* pWnd)
\r
729 if (pWnd) assert(pWnd->IsWindow());
\r
730 HWND hWnd = pWnd? pWnd->GetHwnd() : GetDesktopWindow();
\r
731 Attach(::GetWindowDC(hWnd), hWnd);
\r
733 virtual ~CWindowDC() {}
\r
737 class CMetaFileDC : public CDC
\r
740 CMetaFileDC() : m_hMF(0), m_hEMF(0) {}
\r
741 virtual ~CMetaFileDC()
\r
745 ::CloseMetaFile(GetHDC());
\r
746 ::DeleteMetaFile(m_hMF);
\r
750 ::CloseEnhMetaFile(GetHDC());
\r
751 ::DeleteEnhMetaFile(m_hEMF);
\r
754 void Create(LPCTSTR lpszFilename = NULL) { Attach(::CreateMetaFile(lpszFilename)); }
\r
755 void CreateEnhanced(CDC* pDCRef, LPCTSTR lpszFileName, LPCRECT lpBounds, LPCTSTR lpszDescription)
\r
757 HDC hDC = pDCRef? pDCRef->GetHDC() : NULL;
\r
758 ::CreateEnhMetaFile(hDC, lpszFileName, lpBounds, lpszDescription);
\r
761 HMETAFILE Close() { return ::CloseMetaFile(GetHDC()); }
\r
762 HENHMETAFILE CloseEnhanced() { return ::CloseEnhMetaFile(GetHDC()); }
\r
766 HENHMETAFILE m_hEMF;
\r
771 ///////////////////////////////////////////////
\r
772 // Declarations for the CBitmapInfoPtr class
\r
773 // The CBitmapInfoPtr class is a convienient wrapper for the BITMAPINFO structure.
\r
774 class CBitmapInfoPtr
\r
777 CBitmapInfoPtr(CBitmap* pBitmap)
\r
779 BITMAP bmSource = pBitmap->GetBitmapData();
\r
781 // Convert the color format to a count of bits.
\r
782 WORD cClrBits = (WORD)(bmSource.bmPlanes * bmSource.bmBitsPixel);
\r
783 if (cClrBits == 1) cClrBits = 1;
\r
784 else if (cClrBits <= 4) cClrBits = 4;
\r
785 else if (cClrBits <= 8) cClrBits = 8;
\r
786 else if (cClrBits <= 16) cClrBits = 16;
\r
787 else if (cClrBits <= 24) cClrBits = 24;
\r
788 else cClrBits = 32;
\r
790 // Allocate memory for the BITMAPINFO structure.
\r
791 UINT uQuadSize = (cClrBits == 24)? 0 : sizeof(RGBQUAD) * (int)(1 << cClrBits);
\r
792 m_bmi.assign(sizeof(BITMAPINFOHEADER) + uQuadSize, 0);
\r
793 m_pbmiArray = (LPBITMAPINFO) &m_bmi[0];
\r
795 m_pbmiArray->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
796 m_pbmiArray->bmiHeader.biHeight = bmSource.bmHeight;
\r
797 m_pbmiArray->bmiHeader.biWidth = bmSource.bmWidth;
\r
798 m_pbmiArray->bmiHeader.biPlanes = bmSource.bmPlanes;
\r
799 m_pbmiArray->bmiHeader.biBitCount = bmSource.bmBitsPixel;
\r
800 m_pbmiArray->bmiHeader.biCompression = BI_RGB;
\r
802 m_pbmiArray->bmiHeader.biClrUsed = (1<<cClrBits);
\r
804 LPBITMAPINFO get() const { return m_pbmiArray; }
\r
805 operator LPBITMAPINFO() const { return m_pbmiArray; }
\r
806 LPBITMAPINFO operator->() const { return m_pbmiArray; }
\r
809 CBitmapInfoPtr(const CBitmapInfoPtr&); // Disable copy construction
\r
810 CBitmapInfoPtr& operator = (const CBitmapInfoPtr&); // Disable assignment operator
\r
811 LPBITMAPINFO m_pbmiArray;
\r
812 std::vector<byte> m_bmi;
\r
816 CBitmap* FromHandle(HBITMAP hBitmap);
\r
817 CBrush* FromHandle(HBRUSH hBrush);
\r
818 CFont* FromHandle(HFONT hFont);
\r
819 CPalette* FromHandle(HPALETTE hPalette);
\r
820 CPen* FromHandle(HPEN hPen);
\r
821 CRgn* FromHandle(HRGN hRgn);
\r
825 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\r
831 ///////////////////////////////////////////////
\r
832 // Declarations for the CGDIObject class
\r
835 inline CGDIObject::CGDIObject()
\r
836 // Constructs the CGDIObject
\r
838 m_pData = new DataMembers;
\r
839 m_pData->hGDIObject = 0;
\r
840 m_pData->Count = 1L;
\r
841 m_pData->bRemoveObject = TRUE;
\r
844 inline CGDIObject::CGDIObject(const CGDIObject& rhs)
\r
845 // Note: A copy of a CGDIObject is a clone of the original.
\r
846 // Both objects manipulate the one HGDIOBJ.
\r
848 m_pData = rhs.m_pData;
\r
849 InterlockedIncrement(&m_pData->Count);
\r
852 inline CGDIObject::~CGDIObject()
\r
853 // Deconstructs the CGDIObject
\r
858 inline CGDIObject& CGDIObject::operator = ( const CGDIObject& rhs )
\r
859 // Note: A copy of a CGDIObject is a clone of the original.
\r
860 // Both objects manipulate the one HGDIOBJ.
\r
864 InterlockedIncrement(&rhs.m_pData->Count);
\r
866 m_pData = rhs.m_pData;
\r
872 inline void CGDIObject::operator = (HGDIOBJ hObject)
\r
875 assert (m_pData->hGDIObject == NULL);
\r
876 m_pData->hGDIObject = hObject;
\r
879 inline void CGDIObject::AddToMap()
\r
880 // Store the HDC and CDC pointer in the HDC map
\r
882 assert( GetApp() );
\r
883 GetApp()->m_csMapLock.Lock();
\r
885 assert(m_pData->hGDIObject);
\r
886 assert(!GetApp()->GetCGDIObjectFromMap(m_pData->hGDIObject));
\r
888 GetApp()->m_mapGDI.insert(std::make_pair(m_pData->hGDIObject, this));
\r
889 GetApp()->m_csMapLock.Release();
\r
892 inline void CGDIObject::Attach(HGDIOBJ hObject)
\r
893 // Attaches a GDI HANDLE to the CGDIObject.
\r
894 // The HGDIOBJ will be automatically deleted when the destructor is called unless it is detached.
\r
898 if (m_pData->hGDIObject != NULL && m_pData->hGDIObject != hObject)
\r
900 ::DeleteObject(Detach());
\r
903 CGDIObject* pObject = GetApp()->GetCGDIObjectFromMap(hObject);
\r
907 m_pData = pObject->m_pData;
\r
908 InterlockedIncrement(&m_pData->Count);
\r
912 m_pData->hGDIObject = hObject;
\r
917 inline void CGDIObject::DeleteObject()
\r
921 if (m_pData->hGDIObject)
\r
923 ::DeleteObject(Detach());
\r
927 inline HGDIOBJ CGDIObject::Detach()
\r
928 // Detaches the HGDIOBJ from this object.
\r
931 assert(m_pData->hGDIObject);
\r
933 GetApp()->m_csMapLock.Lock();
\r
935 HGDIOBJ hObject = m_pData->hGDIObject;
\r
936 m_pData->hGDIObject = 0;
\r
938 if (m_pData->Count)
\r
940 if (InterlockedDecrement(&m_pData->Count) == 0)
\r
946 GetApp()->m_csMapLock.Release();
\r
948 // Assign values to our data members
\r
949 m_pData = new DataMembers;
\r
950 m_pData->hGDIObject = 0;
\r
951 m_pData->Count = 1L;
\r
952 m_pData->bRemoveObject = TRUE;
\r
957 inline HGDIOBJ CGDIObject::GetHandle() const
\r
960 return m_pData->hGDIObject;
\r
963 inline int CGDIObject::GetObject(int nCount, LPVOID pObject) const
\r
966 return ::GetObject(m_pData->hGDIObject, nCount, pObject);
\r
969 inline void CGDIObject::Release()
\r
972 BOOL bSucceeded = TRUE;
\r
974 if (InterlockedDecrement(&m_pData->Count) == 0)
\r
976 if (m_pData->hGDIObject != NULL)
\r
978 if (m_pData->bRemoveObject)
\r
979 bSucceeded = ::DeleteObject(m_pData->hGDIObject);
\r
989 assert(bSucceeded);
\r
992 inline BOOL CGDIObject::RemoveFromMap()
\r
994 BOOL Success = FALSE;
\r
998 // Allocate an iterator for our HDC map
\r
999 std::map<HGDIOBJ, CGDIObject*, CompareGDI>::iterator m;
\r
1001 CWinApp* pApp = GetApp();
\r
1004 // Erase the CGDIObject pointer entry from the map
\r
1005 pApp->m_csMapLock.Lock();
\r
1006 m = pApp->m_mapGDI.find(m_pData->hGDIObject);
\r
1007 if (m != pApp->m_mapGDI.end())
\r
1009 pApp->m_mapGDI.erase(m);
\r
1013 pApp->m_csMapLock.Release();
\r
1021 ///////////////////////////////////////////////
\r
1022 // Declarations for the CBitmap class
\r
1024 inline CBitmap::CBitmap()
\r
1028 inline CBitmap::CBitmap(HBITMAP hBitmap)
\r
1034 inline CBitmap::CBitmap(LPCTSTR lpszName)
\r
1036 LoadBitmap(lpszName);
\r
1039 inline CBitmap::CBitmap(int nID)
\r
1044 inline CBitmap::operator HBITMAP() const
\r
1047 return (HBITMAP)m_pData->hGDIObject;
\r
1050 inline CBitmap::~CBitmap()
\r
1054 inline BOOL CBitmap::LoadBitmap(int nID)
\r
1055 // Loads a bitmap from a resource using the resource ID.
\r
1057 return LoadBitmap(MAKEINTRESOURCE(nID));
\r
1060 inline BOOL CBitmap::LoadBitmap(LPCTSTR lpszName)
\r
1061 // Loads a bitmap from a resource using the resource string.
\r
1066 HBITMAP hBitmap = (HBITMAP)::LoadImage(GetApp()->GetResourceHandle(), lpszName, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
\r
1071 return (0 != hBitmap); // boolean expression
\r
1074 inline BOOL CBitmap::LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad)
\r
1075 // Loads a bitmap from a resource using the resource ID.
\r
1077 return LoadImage(MAKEINTRESOURCE(nID), cxDesired, cyDesired, fuLoad);
\r
1080 inline BOOL CBitmap::LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad)
\r
1081 // Loads a bitmap from a resource using the resource string.
\r
1086 HBITMAP hBitmap = (HBITMAP)::LoadImage(GetApp()->GetResourceHandle(), lpszName, IMAGE_BITMAP, cxDesired, cyDesired, fuLoad);
\r
1091 return (0 != hBitmap); // boolean expression
\r
1094 inline BOOL CBitmap::LoadOEMBitmap(UINT nIDBitmap) // for OBM_/OCR_/OIC_
\r
1095 // Loads a predefined bitmap
\r
1096 // Predefined bitmaps include: OBM_BTNCORNERS, OBM_BTSIZE, OBM_CHECK, OBM_CHECKBOXES, OBM_CLOSE, OBM_COMBO
\r
1097 // OBM_DNARROW, OBM_DNARROWD, OBM_DNARROWI, OBM_LFARROW, OBM_LFARROWD, OBM_LFARROWI, OBM_MNARROW,OBM_OLD_CLOSE
\r
1098 // OBM_OLD_DNARROW, OBM_OLD_LFARROW, OBM_OLD_REDUCE, OBM_OLD_RESTORE, OBM_OLD_RGARROW, OBM_OLD_UPARROW
\r
1099 // OBM_OLD_ZOOM, OBM_REDUCE, OBM_REDUCED, OBM_RESTORE, OBM_RESTORED, OBM_RGARROW, OBM_RGARROWD, OBM_RGARROWI
\r
1100 // OBM_SIZE, OBM_UPARROW, OBM_UPARROWD, OBM_UPARROWI, OBM_ZOOM, OBM_ZOOMD
\r
1104 HBITMAP hBitmap = ::LoadBitmap(NULL, MAKEINTRESOURCE(nIDBitmap));
\r
1107 Attach( ::LoadBitmap(NULL, MAKEINTRESOURCE(nIDBitmap)) );
\r
1109 return (0 != hBitmap); // boolean expression
\r
1112 #ifndef _WIN32_WCE
\r
1113 inline HBITMAP CBitmap::CreateMappedBitmap(UINT nIDBitmap, UINT nFlags /*= 0*/, LPCOLORMAP lpColorMap /*= NULL*/, int nMapSize /*= 0*/)
\r
1114 // Creates a new bitmap using the bitmap data and colors specified by the bitmap resource and the color mapping information.
\r
1118 HBITMAP hBitmap = ::CreateMappedBitmap(GetApp()->GetResourceHandle(), nIDBitmap, (WORD)nFlags, lpColorMap, nMapSize);
\r
1122 #endif // !_WIN32_WCE
\r
1124 inline HBITMAP CBitmap::CreateBitmap(int nWidth, int nHeight, UINT nPlanes, UINT nBitsPerPixel, LPCVOID lpBits)
\r
1125 // Creates a bitmap with the specified width, height, and color format (color planes and bits-per-pixel).
\r
1128 HBITMAP hBitmap = ::CreateBitmap(nWidth, nHeight, nPlanes, nBitsPerPixel, lpBits);
\r
1133 #ifndef _WIN32_WCE
\r
1134 inline HBITMAP CBitmap::CreateBitmapIndirect(LPBITMAP lpBitmap)
\r
1135 // Creates a bitmap with the width, height, and color format specified in the BITMAP structure.
\r
1138 HBITMAP hBitmap = ::CreateBitmapIndirect(lpBitmap);
\r
1142 #endif // !_WIN32_WCE
\r
1144 inline HBITMAP CBitmap::CreateCompatibleBitmap(CDC* pDC, int nWidth, int nHeight)
\r
1145 // Creates a bitmap compatible with the device that is associated with the specified device context.
\r
1149 HBITMAP hBitmap = ::CreateCompatibleBitmap(pDC->GetHDC(), nWidth, nHeight);
\r
1155 inline BITMAP CBitmap::GetBitmapData() const
\r
1156 // Retrieves the BITMAP structure
\r
1159 assert(m_pData->hGDIObject != NULL);
\r
1161 ::GetObject(m_pData->hGDIObject, sizeof(BITMAP), &bmp);
\r
1165 #ifndef _WIN32_WCE
\r
1166 inline CSize CBitmap::GetBitmapDimensionEx() const
\r
1167 // Retrieves the dimensions of a compatible bitmap.
\r
1168 // The retrieved dimensions must have been set by the SetBitmapDimensionEx function.
\r
1171 assert(m_pData->hGDIObject != NULL);
\r
1173 ::GetBitmapDimensionEx((HBITMAP)m_pData->hGDIObject, &Size);
\r
1177 inline CSize CBitmap::SetBitmapDimensionEx(int nWidth, int nHeight)
\r
1178 // The SetBitmapDimensionEx function assigns preferred dimensions to a bitmap.
\r
1179 // These dimensions can be used by applications; however, they are not used by the system.
\r
1182 assert(m_pData->hGDIObject != NULL);
\r
1184 ::SetBitmapDimensionEx((HBITMAP)m_pData->hGDIObject, nWidth, nHeight, Size);
\r
1189 inline HBITMAP CBitmap::CreateDIBitmap(CDC* pDC, CONST BITMAPINFOHEADER* lpbmih, DWORD dwInit, CONST VOID* lpbInit, CONST BITMAPINFO* lpbmi, UINT uColorUse)
\r
1190 // Creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits.
\r
1194 HBITMAP hBitmap = ::CreateDIBitmap(pDC->GetHDC(), lpbmih, dwInit, lpbInit, lpbmi, uColorUse);
\r
1198 #endif // !_WIN32_WCE
\r
1200 inline HBITMAP CBitmap::CreateDIBSection(CDC* pDC, CONST BITMAPINFO* lpbmi, UINT uColorUse, VOID** ppvBits, HANDLE hSection, DWORD dwOffset)
\r
1201 // Creates a DIB that applications can write to directly. The function gives you a pointer to the location of the bitmap bit values.
\r
1202 // You can supply a handle to a file-mapping object that the function will use to create the bitmap, or you can let the system allocate the memory for the bitmap.
\r
1206 HBITMAP hBitmap = ::CreateDIBSection(pDC->GetHDC(), lpbmi, uColorUse, ppvBits, hSection, dwOffset);
\r
1211 #ifndef _WIN32_WCE
\r
1212 inline int CBitmap::GetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT uColorUse) const
\r
1213 // Retrieves the bits of the specified compatible bitmap and copies them into a buffer as a DIB using the specified format.
\r
1217 assert(m_pData->hGDIObject != NULL);
\r
1218 return ::GetDIBits(pDC->GetHDC(), (HBITMAP)m_pData->hGDIObject, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
\r
1221 inline int CBitmap::SetDIBits(CDC* pDC, UINT uStartScan, UINT cScanLines, CONST VOID* lpvBits, CONST BITMAPINFO* lpbmi, UINT uColorUse)
\r
1222 // Sets the pixels in a compatible bitmap (DDB) using the color data found in the specified DIB.
\r
1226 assert(m_pData->hGDIObject != NULL);
\r
1227 return ::SetDIBits(pDC->GetHDC(), (HBITMAP)m_pData->hGDIObject, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
\r
1229 #endif // !_WIN32_WCE
\r
1232 ///////////////////////////////////////////////
\r
1233 // Definitions of the CBrush class
\r
1235 inline CBrush::CBrush()
\r
1239 inline CBrush::CBrush(HBRUSH hBrush)
\r
1245 inline CBrush::CBrush(COLORREF crColor)
\r
1247 Attach( ::CreateSolidBrush(crColor) );
\r
1248 assert (m_pData->hGDIObject);
\r
1251 inline CBrush::operator HBRUSH() const
\r
1254 return (HBRUSH)m_pData->hGDIObject;
\r
1257 inline CBrush::~CBrush()
\r
1261 inline HBRUSH CBrush::CreateSolidBrush(COLORREF crColor)
\r
1262 // Creates a logical brush that has the specified solid color.
\r
1265 HBRUSH hBrush = ::CreateSolidBrush(crColor);
\r
1270 #ifndef _WIN32_WCE
\r
1271 inline HBRUSH CBrush::CreateHatchBrush(int nIndex, COLORREF crColor)
\r
1272 // Creates a logical brush that has the specified hatch pattern and color.
\r
1275 HBRUSH hBrush = ::CreateHatchBrush(nIndex, crColor);
\r
1280 inline HBRUSH CBrush::CreateBrushIndirect(LPLOGBRUSH lpLogBrush)
\r
1281 // Creates a logical brush from style, color, and pattern specified in the LOGPRUSH struct.
\r
1284 HBRUSH hBrush = ::CreateBrushIndirect(lpLogBrush);
\r
1289 inline HBRUSH CBrush::CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec)
\r
1290 // Creates a logical brush that has the pattern specified by the specified device-independent bitmap (DIB).
\r
1293 HBRUSH hBrush = ::CreateDIBPatternBrush(hglbDIBPacked, fuColorSpec);
\r
1298 inline HBRUSH CBrush::CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT nUsage)
\r
1299 // Creates a logical brush that has the pattern specified by the device-independent bitmap (DIB).
\r
1302 HBRUSH hBrush = ::CreateDIBPatternBrushPt(lpPackedDIB, nUsage);
\r
1307 #endif // !defined(_WIN32_WCE)
\r
1309 inline HBRUSH CBrush::CreatePatternBrush(CBitmap* pBitmap)
\r
1310 // Creates a logical brush with the specified bitmap pattern. The bitmap can be a DIB section bitmap,
\r
1311 // which is created by the CreateDIBSection function, or it can be a device-dependent bitmap.
\r
1315 HBRUSH hBrush = ::CreatePatternBrush(*pBitmap);
\r
1320 inline LOGBRUSH CBrush::GetLogBrush() const
\r
1321 // Retrieves the LOGBRUSH structure that defines the style, color, and pattern of a physical brush.
\r
1324 assert(m_pData->hGDIObject != NULL);
\r
1325 LOGBRUSH LogBrush = {0};
\r
1326 ::GetObject (m_pData->hGDIObject, sizeof(LOGBRUSH), &LogBrush);
\r
1331 ///////////////////////////////////////////////
\r
1332 // Definitions of the CFont class
\r
1334 inline CFont::CFont()
\r
1338 inline CFont::CFont(HFONT hFont)
\r
1344 inline CFont::CFont(const LOGFONT* lpLogFont)
\r
1347 Attach( ::CreateFontIndirect(lpLogFont) );
\r
1350 inline CFont::operator HFONT() const
\r
1353 return (HFONT)m_pData->hGDIObject;
\r
1356 inline CFont::~CFont()
\r
1360 inline HFONT CFont::CreateFontIndirect(const LOGFONT* lpLogFont)
\r
1361 // Creates a logical font that has the specified characteristics.
\r
1364 HFONT hFont = ::CreateFontIndirect(lpLogFont);
\r
1369 inline HFONT CFont::CreatePointFont(int nPointSize, LPCTSTR lpszFaceName, CDC* pDC /*= NULL*/, BOOL bBold /*= FALSE*/, BOOL bItalic /*= FALSE*/)
\r
1370 // Creates a font of a specified typeface and point size.
\r
1372 LOGFONT logFont = { 0 };
\r
1373 logFont.lfCharSet = DEFAULT_CHARSET;
\r
1374 logFont.lfHeight = nPointSize;
\r
1376 lstrcpy(logFont.lfFaceName, lpszFaceName);
\r
1379 logFont.lfWeight = FW_BOLD;
\r
1381 logFont.lfItalic = (BYTE)TRUE;
\r
1383 return CreatePointFontIndirect(&logFont, pDC);
\r
1386 inline HFONT CFont::CreatePointFontIndirect(const LOGFONT* lpLogFont, CDC* pDC /* = NULL*/)
\r
1387 // Creates a font of a specified typeface and point size.
\r
1388 // This function automatically converts the height in lfHeight to logical units using the specified device context.
\r
1390 HDC hDC = pDC? pDC->GetHDC() : NULL;
\r
1391 HDC hDC1 = (hDC != NULL) ? hDC : ::GetDC(HWND_DESKTOP);
\r
1393 // convert nPointSize to logical units based on hDC
\r
1394 LOGFONT logFont = *lpLogFont;
\r
1396 #ifndef _WIN32_WCE
\r
1397 POINT pt = { 0, 0 };
\r
1398 pt.y = ::MulDiv(::GetDeviceCaps(hDC1, LOGPIXELSY), logFont.lfHeight, 720); // 72 points/inch, 10 decipoints/point
\r
1399 ::DPtoLP(hDC1, &pt, 1);
\r
1401 POINT ptOrg = { 0, 0 };
\r
1402 ::DPtoLP(hDC1, &ptOrg, 1);
\r
1404 logFont.lfHeight = -abs(pt.y - ptOrg.y);
\r
1405 #else // CE specific
\r
1406 // DP and LP are always the same on CE
\r
1407 logFont.lfHeight = -abs(((::GetDeviceCaps(hDC1, LOGPIXELSY)* logFont.lfHeight)/ 720));
\r
1408 #endif // _WIN32_WCE
\r
1411 ::ReleaseDC (NULL, hDC1);
\r
1413 return CreateFontIndirect (&logFont);
\r
1416 #ifndef _WIN32_WCE
\r
1418 inline HFONT CFont::CreateFont(int nHeight, int nWidth, int nEscapement,
\r
1419 int nOrientation, int nWeight, DWORD dwItalic, DWORD dwUnderline,
\r
1420 DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision,
\r
1421 DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily,
\r
1422 LPCTSTR lpszFacename)
\r
1423 // Creates a logical font with the specified characteristics.
\r
1425 HFONT hFont = ::CreateFont(nHeight, nWidth, nEscapement,
\r
1426 nOrientation, nWeight, dwItalic, dwUnderline, dwStrikeOut,
\r
1427 dwCharSet, dwOutPrecision, dwClipPrecision, dwQuality,
\r
1428 dwPitchAndFamily, lpszFacename);
\r
1433 #endif // #ifndef _WIN32_WCE
\r
1435 inline LOGFONT CFont::GetLogFont() const
\r
1436 // Retrieves the Logfont structure that contains font attributes.
\r
1439 assert(m_pData->hGDIObject != NULL);
\r
1440 LOGFONT LogFont = {0};
\r
1441 ::GetObject(m_pData->hGDIObject, sizeof(LOGFONT), &LogFont);
\r
1446 ///////////////////////////////////////////////
\r
1447 // Definitions of the CPalette class
\r
1449 inline CPalette::CPalette()
\r
1453 inline CPalette::CPalette(HPALETTE hPalette)
\r
1458 inline CPalette::operator HPALETTE() const
\r
1461 return (HPALETTE)m_pData->hGDIObject;
\r
1464 inline CPalette::~CPalette ()
\r
1468 inline HPALETTE CPalette::CreatePalette(LPLOGPALETTE lpLogPalette)
\r
1469 // Creates a logical palette from the information in the specified LOGPALETTE structure.
\r
1472 HPALETTE hPalette = ::CreatePalette (lpLogPalette);
\r
1477 #ifndef _WIN32_WCE
\r
1478 inline HPALETTE CPalette::CreateHalftonePalette(CDC* pDC)
\r
1479 // Creates a halftone palette for the specified device context (DC).
\r
1483 HPALETTE hPalette = ::CreateHalftonePalette(pDC->GetHDC());
\r
1487 #endif // !_WIN32_WCE
\r
1489 inline int CPalette::GetEntryCount() const
\r
1490 // Retrieve the number of entries in the palette.
\r
1493 assert(m_pData->hGDIObject != NULL);
\r
1494 WORD nEntries = 0;
\r
1495 ::GetObject(m_pData->hGDIObject, sizeof(WORD), &nEntries);
\r
1496 return (int)nEntries;
\r
1499 inline UINT CPalette::GetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors) const
\r
1500 // Retrieves a specified range of palette entries from the palette.
\r
1503 assert(m_pData->hGDIObject != NULL);
\r
1504 return ::GetPaletteEntries((HPALETTE)m_pData->hGDIObject, nStartIndex, nNumEntries, lpPaletteColors);
\r
1507 inline UINT CPalette::SetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors)
\r
1508 // Sets RGB (red, green, blue) color values and flags in a range of entries in the palette.
\r
1511 assert(m_pData->hGDIObject != NULL);
\r
1512 return ::SetPaletteEntries((HPALETTE)m_pData->hGDIObject, nStartIndex, nNumEntries, lpPaletteColors);
\r
1515 #ifndef _WIN32_WCE
\r
1516 inline void CPalette::AnimatePalette(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors)
\r
1517 // Replaces entries in the palette.
\r
1520 assert(m_pData->hGDIObject != NULL);
\r
1521 ::AnimatePalette((HPALETTE)m_pData->hGDIObject, nStartIndex, nNumEntries, lpPaletteColors);
\r
1524 inline BOOL CPalette::ResizePalette(UINT nNumEntries)
\r
1525 // Increases or decreases the size of the palette based on the specified value.
\r
1528 assert(m_pData->hGDIObject != NULL);
\r
1529 return ::ResizePalette((HPALETTE)m_pData->hGDIObject, nNumEntries);
\r
1531 #endif // !_WIN32_WCE
\r
1533 inline UINT CPalette::GetNearestPaletteIndex(COLORREF crColor) const
\r
1534 // Retrieves the index for the entry in the palette most closely matching a specified color value.
\r
1537 assert(m_pData->hGDIObject != NULL);
\r
1538 return ::GetNearestPaletteIndex((HPALETTE)m_pData->hGDIObject, crColor);
\r
1542 ///////////////////////////////////////////////
\r
1543 // Declarations for the CPen class
\r
1545 inline CPen::CPen()
\r
1549 inline CPen::CPen(HPEN hPen)
\r
1554 inline CPen::CPen(int nPenStyle, int nWidth, COLORREF crColor)
\r
1557 Attach( ::CreatePen(nPenStyle, nWidth, crColor) );
\r
1560 #ifndef _WIN32_WCE
\r
1561 inline CPen::CPen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount /*= 0*/, const DWORD* lpStyle /*= NULL*/)
\r
1564 Attach( ::ExtCreatePen(nPenStyle, nWidth, pLogBrush, nStyleCount, lpStyle) );
\r
1566 #endif // !_WIN32_WCE
\r
1568 inline CPen::operator HPEN () const
\r
1571 return (HPEN)m_pData->hGDIObject;
\r
1574 inline CPen::~CPen()
\r
1578 inline HPEN CPen::CreatePen(int nPenStyle, int nWidth, COLORREF crColor)
\r
1579 // Creates a logical pen that has the specified style, width, and color.
\r
1582 HPEN hPen = ::CreatePen(nPenStyle, nWidth, crColor);
\r
1587 inline HPEN CPen::CreatePenIndirect(LPLOGPEN lpLogPen)
\r
1588 // Creates a logical cosmetic pen that has the style, width, and color specified in a structure.
\r
1591 HPEN hPen = ::CreatePenIndirect(lpLogPen);
\r
1596 inline LOGPEN CPen::GetLogPen() const
\r
1598 // Retrieves the LOGPEN struct that specifies the pen's style, width, and color.
\r
1600 assert(m_pData->hGDIObject != NULL);
\r
1602 LOGPEN LogPen = {0};
\r
1603 ::GetObject(m_pData->hGDIObject, sizeof(LOGPEN), &LogPen);
\r
1607 #ifndef _WIN32_WCE
\r
1608 inline HPEN CPen::ExtCreatePen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount /* = 0*/, const DWORD* lpStyle /*= NULL*/)
\r
1609 // Creates a logical cosmetic or geometric pen that has the specified style, width, and brush attributes.
\r
1612 HPEN hPen = ::ExtCreatePen(nPenStyle, nWidth, pLogBrush, nStyleCount, lpStyle);
\r
1617 inline EXTLOGPEN CPen::GetExtLogPen() const
\r
1618 // Retrieves the EXTLOGPEN struct that specifies the pen's style, width, color and brush attributes.
\r
1621 assert(m_pData->hGDIObject != NULL);
\r
1623 EXTLOGPEN ExLogPen = {0};
\r
1624 ::GetObject(m_pData->hGDIObject, sizeof(EXTLOGPEN), &ExLogPen);
\r
1627 #endif // !_WIN32_WCE
\r
1630 ///////////////////////////////////////////////
\r
1631 // Definitions of the CRgn class
\r
1633 inline CRgn::CRgn()
\r
1637 inline CRgn::CRgn(HRGN hRgn)
\r
1643 inline CRgn::operator HRGN() const
\r
1646 return (HRGN)m_pData->hGDIObject;
\r
1649 inline CRgn::~CRgn()
\r
1653 inline HRGN CRgn::CreateRectRgn(int x1, int y1, int x2, int y2)
\r
1654 // Creates a rectangular region.
\r
1657 HRGN hRgn = ::CreateRectRgn(x1, y1, x2, y2);
\r
1662 inline HRGN CRgn::CreateRectRgnIndirect(const RECT& rc)
\r
1663 // Creates a rectangular region.
\r
1666 HRGN hRgn = ::CreateRectRgnIndirect(&rc);
\r
1671 #ifndef _WIN32_WCE
\r
1672 inline HRGN CRgn::CreateEllipticRgn(int x1, int y1, int x2, int y2)
\r
1673 // Creates an elliptical region.
\r
1676 HRGN hRgn = ::CreateEllipticRgn(x1, y1, x2, y2);
\r
1681 inline HRGN CRgn::CreateEllipticRgnIndirect(const RECT& rc)
\r
1682 // Creates an elliptical region.
\r
1685 HRGN hRgn = ::CreateEllipticRgnIndirect(&rc);
\r
1690 inline HRGN CRgn::CreatePolygonRgn(LPPOINT lpPoints, int nCount, int nMode)
\r
1691 // Creates a polygonal region.
\r
1694 HRGN hRgn = ::CreatePolygonRgn(lpPoints, nCount, nMode);
\r
1699 inline HRGN CRgn::CreatePolyPolygonRgn(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount, int nPolyFillMode)
\r
1700 // Creates a region consisting of a series of polygons. The polygons can overlap.
\r
1703 HRGN hRgn = ::CreatePolyPolygonRgn(lpPoints, lpPolyCounts, nCount, nPolyFillMode);
\r
1708 inline HRGN CRgn::CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3)
\r
1709 // Creates a rectangular region with rounded corners.
\r
1712 HRGN hRgn = ::CreateRoundRectRgn(x1, y1, x2, y2, x3, y3);
\r
1717 inline HRGN CRgn::CreateFromPath(HDC hDC)
\r
1718 // Creates a region from the path that is selected into the specified device context.
\r
1719 // The resulting region uses device coordinates.
\r
1722 assert(hDC != NULL);
\r
1723 HRGN hRgn = ::PathToRegion(hDC);
\r
1728 #endif // !_WIN32_WCE
\r
1730 inline HRGN CRgn::CreateFromData(const XFORM* lpXForm, int nCount, const RGNDATA* pRgnData)
\r
1731 // Creates a region from the specified region and transformation data.
\r
1734 HRGN hRgn = ::ExtCreateRegion(lpXForm, nCount, pRgnData);
\r
1739 inline void CRgn::SetRectRgn(int x1, int y1, int x2, int y2)
\r
1740 // converts the region into a rectangular region with the specified coordinates.
\r
1743 assert(m_pData->hGDIObject != NULL);
\r
1744 ::SetRectRgn((HRGN)m_pData->hGDIObject, x1, y1, x2, y2);
\r
1747 inline void CRgn::SetRectRgn(const RECT& rc)
\r
1748 // converts the region into a rectangular region with the specified coordinates.
\r
1751 assert(m_pData->hGDIObject != NULL);
\r
1752 ::SetRectRgn((HRGN)m_pData->hGDIObject, rc.left, rc.top, rc.right, rc.bottom);
\r
1755 inline int CRgn::CombineRgn(CRgn* pRgnSrc1, CRgn* pRgnSrc2, int nCombineMode)
\r
1756 // Combines two sepcified regions and stores the result.
\r
1759 assert(m_pData->hGDIObject != NULL);
\r
1762 return ::CombineRgn((HRGN)m_pData->hGDIObject, *pRgnSrc1, *pRgnSrc2, nCombineMode);
\r
1765 inline int CRgn::CombineRgn(CRgn* pRgnSrc, int nCombineMode)
\r
1766 // Combines the sepcified region with the current region.
\r
1769 assert(m_pData->hGDIObject != NULL);
\r
1771 return ::CombineRgn((HRGN)m_pData->hGDIObject, (HRGN)m_pData->hGDIObject, *pRgnSrc, nCombineMode);
\r
1774 inline int CRgn::CopyRgn(CRgn* pRgnSrc)
\r
1775 // Assigns the specified region to the current region.
\r
1778 assert(m_pData->hGDIObject == NULL);
\r
1780 return ::CombineRgn((HRGN)m_pData->hGDIObject, *pRgnSrc, NULL, RGN_COPY);
\r
1783 inline BOOL CRgn::EqualRgn(CRgn* pRgn) const
\r
1784 // Checks the two specified regions to determine whether they are identical.
\r
1787 assert(m_pData->hGDIObject != NULL);
\r
1789 return ::EqualRgn((HRGN)m_pData->hGDIObject, *pRgn);
\r
1792 inline int CRgn::OffsetRgn(int x, int y)
\r
1793 // Moves a region by the specified offsets.
\r
1796 assert(m_pData->hGDIObject != NULL);
\r
1797 return ::OffsetRgn((HRGN)m_pData->hGDIObject, x, y);
\r
1800 inline int CRgn::OffsetRgn(POINT& pt)
\r
1801 // Moves a region by the specified offsets.
\r
1804 assert(m_pData->hGDIObject != NULL);
\r
1805 return ::OffsetRgn((HRGN)m_pData->hGDIObject, pt.x, pt.y);
\r
1808 inline int CRgn::GetRgnBox(RECT& rc) const
\r
1809 // Retrieves the bounding rectangle of the region, and stores it in the specified RECT.
\r
1810 // The return value indicates the region's complexity: NULLREGION;SIMPLEREGION; or COMPLEXREGION.
\r
1813 assert(m_pData->hGDIObject != NULL);
\r
1814 return ::GetRgnBox((HRGN)m_pData->hGDIObject, &rc);
\r
1817 inline int CRgn::GetRegionData(LPRGNDATA lpRgnData, int nDataSize) const
\r
1818 // Fills the specified buffer with data describing a region.
\r
1821 assert(m_pData->hGDIObject != NULL);
\r
1822 return (int)::GetRegionData((HRGN)m_pData->hGDIObject, nDataSize, lpRgnData);
\r
1825 inline BOOL CRgn::PtInRegion(int x, int y) const
\r
1826 // Determines whether the specified point is inside the specified region.
\r
1829 assert(m_pData->hGDIObject != NULL);
\r
1830 return ::PtInRegion((HRGN)m_pData->hGDIObject, x, y);
\r
1833 inline BOOL CRgn::PtInRegion(POINT& pt) const
\r
1834 // Determines whether the specified point is inside the specified region.
\r
1837 assert(m_pData->hGDIObject != NULL);
\r
1838 return ::PtInRegion((HRGN)m_pData->hGDIObject, pt.x, pt.y);
\r
1841 inline BOOL CRgn::RectInRegion(const RECT& rc) const
\r
1842 // Determines whether the specified rect is inside the specified region.
\r
1845 assert(m_pData->hGDIObject != NULL);
\r
1846 return ::RectInRegion((HRGN)m_pData->hGDIObject, &rc);
\r
1850 ///////////////////////////////////////////////
\r
1851 // Definitions of the CDC class
\r
1855 // Allocate memory for our data members
\r
1856 m_pData = new DataMembers;
\r
1858 // Assign values to our data members
\r
1860 m_pData->Count = 1L;
\r
1861 m_pData->bRemoveHDC = TRUE;
\r
1862 m_pData->hWnd = 0;
\r
1865 inline CDC::CDC(HDC hDC, HWND hWnd /*= 0*/)
\r
1866 // This constructor assigns an existing HDC to the CDC
\r
1867 // The HDC WILL be released or deleted when the CDC object is destroyed
\r
1868 // The hWnd paramter is only used in WindowsCE. It specifies the HWND of a Window or
\r
1869 // Window Client DC
\r
1871 // Note: this constructor permits a call like this:
\r
1872 // CDC MyCDC = SomeHDC;
\r
1874 // CDC MyCDC = ::CreateCompatibleDC(SomeHDC);
\r
1876 // CDC MyCDC = ::GetDC(SomeHWND);
\r
1878 UNREFERENCED_PARAMETER(hWnd);
\r
1881 CDC* pDC = GetApp()->GetCDCFromMap(hDC);
\r
1884 m_pData = pDC->m_pData;
\r
1885 InterlockedIncrement(&m_pData->Count);
\r
1889 // Allocate memory for our data members
\r
1890 m_pData = new DataMembers;
\r
1892 // Assign values to our data members
\r
1893 m_pData->hDC = hDC;
\r
1894 m_pData->Count = 1L;
\r
1895 m_pData->bRemoveHDC = TRUE;
\r
1896 m_pData->nSavedDCState = ::SaveDC(hDC);
\r
1897 #ifndef _WIN32_WCE
\r
1898 m_pData->hWnd = ::WindowFromDC(hDC);
\r
1900 m_pData->hWnd = hWnd;
\r
1902 if (m_pData->hWnd == 0)
\r
1907 #ifndef _WIN32_WCE
\r
1908 inline void CDC::operator = (const HDC hDC)
\r
1909 // Note: this assignment operater permits a call like this:
\r
1911 // MyCDC = SomeHDC;
\r
1917 inline CDC::CDC(const CDC& rhs) // Copy constructor
\r
1918 // The copy constructor is called when a temporary copy of the CDC needs to be created.
\r
1919 // This can happen when a CDC is passed by value in a function call. Each CDC copy manages
\r
1920 // the same Device Context and GDI objects.
\r
1922 m_pData = rhs.m_pData;
\r
1923 InterlockedIncrement(&m_pData->Count);
\r
1926 inline CDC& CDC::operator = (const CDC& rhs)
\r
1927 // Note: A copy of a CDC is a clone of the original.
\r
1928 // Both objects manipulate the one HDC
\r
1932 InterlockedIncrement(&rhs.m_pData->Count);
\r
1934 m_pData = rhs.m_pData;
\r
1940 inline CDC::~CDC ()
\r
1945 inline void CDC::AddToMap()
\r
1946 // Store the HDC and CDC pointer in the HDC map
\r
1948 assert( GetApp() );
\r
1949 assert(m_pData->hDC);
\r
1950 GetApp()->m_csMapLock.Lock();
\r
1952 assert(m_pData->hDC);
\r
1953 assert(!GetApp()->GetCDCFromMap(m_pData->hDC));
\r
1955 GetApp()->m_mapHDC.insert(std::make_pair(m_pData->hDC, this));
\r
1956 GetApp()->m_csMapLock.Release();
\r
1959 inline void CDC::Attach(HDC hDC, HWND hWnd /* = 0*/)
\r
1960 // Attaches a HDC to the CDC object.
\r
1961 // The HDC will be automatically deleted or released when the destructor is called.
\r
1962 // The hWnd parameter is only used on WindowsCE. It specifies the HWND of a Window or
\r
1963 // Window Client DC
\r
1965 UNREFERENCED_PARAMETER(hWnd);
\r
1967 assert(0 == m_pData->hDC);
\r
1970 CDC* pDC = GetApp()->GetCDCFromMap(hDC);
\r
1974 m_pData = pDC->m_pData;
\r
1975 InterlockedIncrement(&m_pData->Count);
\r
1979 m_pData->hDC = hDC;
\r
1981 #ifndef _WIN32_WCE
\r
1982 m_pData->hWnd = ::WindowFromDC(hDC);
\r
1984 m_pData->hWnd = hWnd;
\r
1987 if (m_pData->hWnd == 0)
\r
1989 m_pData->nSavedDCState = ::SaveDC(hDC);
\r
1993 inline HDC CDC::Detach()
\r
1994 // Detaches the HDC from this object.
\r
1997 assert(m_pData->hDC);
\r
1999 GetApp()->m_csMapLock.Lock();
\r
2001 HDC hDC = m_pData->hDC;
\r
2004 if (m_pData->Count)
\r
2006 if (InterlockedDecrement(&m_pData->Count) == 0)
\r
2012 GetApp()->m_csMapLock.Release();
\r
2014 // Assign values to our data members
\r
2015 m_pData = new DataMembers;
\r
2017 m_pData->Count = 1L;
\r
2018 m_pData->bRemoveHDC = TRUE;
\r
2019 m_pData->hWnd = 0;
\r
2025 inline BOOL CDC::CreateCompatibleDC(CDC* pDC)
\r
2026 // Returns a memory device context (DC) compatible with the specified device.
\r
2028 assert(m_pData->hDC == NULL);
\r
2029 HDC hdcSource = (pDC == NULL)? NULL : pDC->GetHDC();
\r
2030 HDC hDC = ::CreateCompatibleDC(hdcSource);
\r
2033 m_pData->hDC = hDC;
\r
2036 return (hDC != NULL); // boolean expression
\r
2039 inline BOOL CDC::CreateDC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData)
\r
2040 // Returns a device context (DC) for a device using the specified name.
\r
2042 assert(m_pData->hDC == NULL);
\r
2043 HDC hDC = ::CreateDC(lpszDriver, lpszDevice, lpszOutput, pInitData);
\r
2046 m_pData->hDC = hDC;
\r
2049 return (hDC != NULL); // boolean expression
\r
2052 #ifndef _WIN32_WCE
\r
2053 inline BOOL CDC::CreateIC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData)
\r
2055 assert(m_pData->hDC == NULL);
\r
2056 HDC hDC = ::CreateIC(lpszDriver, lpszDevice, lpszOutput, pInitData);
\r
2059 m_pData->hDC = hDC;
\r
2062 return (hDC != NULL); // boolean expression
\r
2066 inline void CDC::DrawBitmap(int x, int y, int cx, int cy, CBitmap& Bitmap, COLORREF clrMask)
\r
2067 // Draws the specified bitmap to the specified DC using the mask colour provided as the transparent colour
\r
2068 // Suitable for use with a Window DC or a memory DC
\r
2070 // Create the Image memory DC
\r
2071 CMemDC dcImage(this);
\r
2072 dcImage.SetBkColor(clrMask);
\r
2073 dcImage.SelectObject(&Bitmap);
\r
2075 // Create the Mask memory DC
\r
2076 CMemDC dcMask(this);
\r
2077 dcMask.CreateBitmap(cx, cy, 1, 1, NULL);
\r
2078 dcMask.BitBlt(0, 0, cx, cy, &dcImage, 0, 0, SRCCOPY);
\r
2080 // Mask the image to 'this' DC
\r
2081 BitBlt(x, y, cx, cy, &dcImage, 0, 0, SRCINVERT);
\r
2082 BitBlt(x, y, cx, cy, &dcMask, 0, 0, SRCAND);
\r
2083 BitBlt(x, y, cx, cy, &dcImage, 0, 0, SRCINVERT);
\r
2086 inline CDC* CDC::AddTempHDC(HDC hDC, HWND hWnd)
\r
2087 // Returns the CDC object associated with the device context handle
\r
2088 // The HDC is removed when the CDC is destroyed
\r
2090 assert( GetApp() );
\r
2091 CDC* pDC = new CDC;
\r
2092 pDC->m_pData->hDC = hDC;
\r
2093 GetApp()->AddTmpDC(pDC);
\r
2094 pDC->m_pData->bRemoveHDC = TRUE;
\r
2095 pDC->m_pData->hWnd = hWnd;
\r
2099 inline void CDC::GradientFill(COLORREF Color1, COLORREF Color2, const RECT& rc, BOOL bVertical)
\r
2100 // An efficient color gradient filler compatible with all Windows operating systems
\r
2102 int Width = rc.right - rc.left;
\r
2103 int Height = rc.bottom - rc.top;
\r
2105 int r1 = GetRValue(Color1);
\r
2106 int g1 = GetGValue(Color1);
\r
2107 int b1 = GetBValue(Color1);
\r
2109 int r2 = GetRValue(Color2);
\r
2110 int g2 = GetGValue(Color2);
\r
2111 int b2 = GetBValue(Color2);
\r
2113 COLORREF OldBkColor = GetBkColor();
\r
2117 for(int i=0; i < Width; ++i)
\r
2119 int r = r1 + (i * (r2-r1) / Width);
\r
2120 int g = g1 + (i * (g2-g1) / Width);
\r
2121 int b = b1 + (i * (b2-b1) / Width);
\r
2122 SetBkColor(RGB(r, g, b));
\r
2123 CRect line( i + rc.left, rc.top, i + 1 + rc.left, rc.top+Height);
\r
2124 ExtTextOut(0, 0, ETO_OPAQUE, line, NULL, 0, 0);
\r
2129 for(int i=0; i < Height; ++i)
\r
2131 int r = r1 + (i * (r2-r1) / Height);
\r
2132 int g = g1 + (i * (g2-g1) / Height);
\r
2133 int b = b1 + (i * (b2-b1) / Height);
\r
2134 SetBkColor(RGB(r, g, b));
\r
2135 CRect line(rc.left, i + rc.top, rc.left+Width, i + 1 + rc.top);
\r
2136 ExtTextOut(0, 0, ETO_OPAQUE, line, NULL, 0, 0);
\r
2140 SetBkColor(OldBkColor);
\r
2143 inline void CDC::Release()
\r
2145 GetApp()->m_csMapLock.Lock();
\r
2147 if (m_pData->Count)
\r
2149 if (InterlockedDecrement(&m_pData->Count) == 0)
\r
2157 GetApp()->m_csMapLock.Release();
\r
2160 inline BOOL CDC::RemoveFromMap()
\r
2162 BOOL Success = FALSE;
\r
2166 // Allocate an iterator for our HDC map
\r
2167 std::map<HDC, CDC*, CompareHDC>::iterator m;
\r
2169 CWinApp* pApp = GetApp();
\r
2172 // Erase the CDC pointer entry from the map
\r
2173 pApp->m_csMapLock.Lock();
\r
2174 m = pApp->m_mapHDC.find(m_pData->hDC);
\r
2175 if (m != pApp->m_mapHDC.end())
\r
2177 pApp->m_mapHDC.erase(m);
\r
2181 pApp->m_csMapLock.Release();
\r
2187 inline void CDC::SolidFill(COLORREF Color, const RECT& rc)
\r
2188 // Fills a rectangle with a solid color
\r
2190 COLORREF OldColor = SetBkColor(Color);
\r
2191 ExtTextOut(0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
\r
2192 SetBkColor(OldColor);
\r
2195 // Bitmap functions
\r
2196 inline void CDC::CreateCompatibleBitmap(CDC* pDC, int cx, int cy)
\r
2197 // Creates a compatible bitmap and selects it into the device context.
\r
2199 assert(m_pData->hDC);
\r
2202 CBitmap* pBitmap = new CBitmap;
\r
2203 pBitmap->CreateCompatibleBitmap(pDC, cx, cy);
\r
2204 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2205 ::SelectObject(m_pData->hDC, *pBitmap);
\r
2208 inline void CDC::CreateBitmap(int cx, int cy, UINT Planes, UINT BitsPerPixel, LPCVOID pvColors)
\r
2209 // Creates a bitmap and selects it into the device context.
\r
2210 // Returns a pointer to the old bitmap selected out of the device context
\r
2212 assert(m_pData->hDC);
\r
2214 CBitmap* pBitmap = new CBitmap;
\r
2215 pBitmap->CreateBitmap(cx, cy, Planes, BitsPerPixel, pvColors);
\r
2216 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2217 ::SelectObject(m_pData->hDC, *pBitmap);
\r
2220 #ifndef _WIN32_WCE
\r
2221 inline void CDC::CreateBitmapIndirect (LPBITMAP lpBitmap)
\r
2222 // Creates a bitmap and selects it into the device context.
\r
2223 // Returns a pointer to the old bitmap selected out of the device context
\r
2225 assert(m_pData->hDC);
\r
2227 CBitmap* pBitmap = new CBitmap;
\r
2228 pBitmap->CreateBitmapIndirect(lpBitmap);
\r
2229 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2230 ::SelectObject(m_pData->hDC, *pBitmap);
\r
2233 inline void CDC::CreateDIBitmap(CDC* pDC, const BITMAPINFOHEADER& bmih, DWORD fdwInit, LPCVOID lpbInit,
\r
2234 BITMAPINFO& bmi, UINT fuUsage)
\r
2235 // Creates a bitmap and selects it into the device context.
\r
2236 // Returns a pointer to the old bitmap selected out of the device context
\r
2238 assert(m_pData->hDC);
\r
2241 CBitmap* pBitmap = new CBitmap;
\r
2242 pBitmap->CreateDIBitmap(pDC, &bmih, fdwInit, lpbInit, &bmi, fuUsage);
\r
2243 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2244 ::SelectObject(m_pData->hDC, *pBitmap);
\r
2248 inline void CDC::CreateDIBSection(CDC* pDC, const BITMAPINFO& bmi, UINT iUsage, LPVOID *ppvBits,
\r
2249 HANDLE hSection, DWORD dwOffset)
\r
2250 // Creates a bitmap and selects it into the device context.
\r
2251 // Returns a pointer to the old bitmap selected out of the device context
\r
2253 assert(m_pData->hDC);
\r
2256 CBitmap* pBitmap = new CBitmap;
\r
2257 pBitmap->CreateDIBSection(pDC, &bmi, iUsage, ppvBits, hSection, dwOffset);
\r
2258 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2259 ::SelectObject(m_pData->hDC, *pBitmap);
\r
2262 inline CBitmap CDC::DetachBitmap()
\r
2263 // Provides a convenient method of detaching a bitmap from a memory device context.
\r
2264 // Returns the CBitmap detached from the DC.
\r
2265 // Useage: CBitmap MyBitmap = MyMemDC.DetachBitmap();
\r
2267 // Create a stock bitmap to replace the current one.
\r
2268 CBitmap* pBitmap = new CBitmap;
\r
2269 pBitmap->CreateBitmap(1, 1, 1, 1, 0);
\r
2270 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2272 // Select our new stock bitmap into the device context
\r
2273 HBITMAP hBitmap = (HBITMAP)::SelectObject(*this, *pBitmap);
\r
2275 // Detach the bitmap from our internally managed GDIObjects
\r
2276 std::vector<GDIPtr>::iterator it;
\r
2277 for (it = m_pData->m_vGDIObjects.begin(); it < m_pData->m_vGDIObjects.end(); ++it)
\r
2279 if((*it)->GetHandle() == hBitmap)
\r
2283 // Create a local CBitmap. We can return this by value because it is reference counted
\r
2284 CBitmap Bitmap(hBitmap);
\r
2288 inline void CDC::Destroy()
\r
2289 // Deletes or releases the device context and returns the CDC object to its
\r
2290 // default state, ready for reuse.
\r
2295 if (m_pData->bRemoveHDC)
\r
2297 // Return the DC back to its initial state
\r
2298 ::RestoreDC(m_pData->hDC, m_pData->nSavedDCState);
\r
2300 // We need to release a Window DC, and delete a memory DC
\r
2301 if (m_pData->hWnd)
\r
2302 ::ReleaseDC(m_pData->hWnd, m_pData->hDC);
\r
2304 if (!::DeleteDC(m_pData->hDC))
\r
2305 ::ReleaseDC(NULL, m_pData->hDC);
\r
2308 m_pData->hWnd = 0;
\r
2309 m_pData->bRemoveHDC = TRUE;
\r
2314 inline BITMAP CDC::GetBitmapData() const
\r
2315 // Retrieves the BITMAP information for the current HBITMAP.
\r
2317 assert(m_pData->hDC);
\r
2319 HBITMAP hbm = (HBITMAP)::GetCurrentObject(m_pData->hDC, OBJ_BITMAP);
\r
2321 ::GetObject(hbm, sizeof(bm), &bm);
\r
2325 inline BOOL CDC::LoadBitmap(UINT nID)
\r
2326 // Loads a bitmap from the resource and selects it into the device context
\r
2328 return LoadBitmap(MAKEINTRESOURCE(nID));
\r
2331 inline BOOL CDC::LoadBitmap(LPCTSTR lpszName)
\r
2332 // Loads a bitmap from the resource and selects it into the device context
\r
2333 // Returns a pointer to the old bitmap selected out of the device context
\r
2335 assert(m_pData->hDC);
\r
2337 CBitmap* pBitmap = new CBitmap;
\r
2338 BOOL bResult = pBitmap->LoadBitmap(lpszName);
\r
2339 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2342 ::SelectObject(*this, *pBitmap);
\r
2347 inline BOOL CDC::LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad)
\r
2348 // Loads a bitmap from the resource and selects it into the device context
\r
2349 // Returns a pointer to the old bitmap selected out of the device context
\r
2351 return LoadImage(nID, cxDesired, cyDesired, fuLoad);
\r
2354 inline BOOL CDC::LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad)
\r
2355 // Loads a bitmap from the resource and selects it into the device context
\r
2356 // Returns a pointer to the old bitmap selected out of the device context
\r
2358 assert(m_pData->hDC);
\r
2360 CBitmap* pBitmap = new CBitmap;
\r
2361 BOOL bResult = pBitmap->LoadImage(lpszName, cxDesired, cyDesired, fuLoad);
\r
2362 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2365 ::SelectObject(*this, *pBitmap);
\r
2370 inline BOOL CDC::LoadOEMBitmap(UINT nIDBitmap) // for OBM_/OCR_/OIC_
\r
2371 // Loads a predefined system bitmap and selects it into the device context
\r
2372 // Returns a pointer to the old bitmap selected out of the device context
\r
2374 assert(m_pData->hDC);
\r
2376 CBitmap* pBitmap = new CBitmap;
\r
2377 BOOL bResult = pBitmap->LoadOEMBitmap(nIDBitmap);
\r
2378 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2381 ::SelectObject(*this, *pBitmap);
\r
2386 #ifndef _WIN32_WCE
\r
2387 inline void CDC::CreateMappedBitmap(UINT nIDBitmap, UINT nFlags /*= 0*/, LPCOLORMAP lpColorMap /*= NULL*/, int nMapSize /*= 0*/)
\r
2388 // creates and selects a new bitmap using the bitmap data and colors specified by the bitmap resource and the color mapping information.
\r
2389 // Returns a pointer to the old bitmap selected out of the device context
\r
2391 assert(m_pData->hDC);
\r
2393 CBitmap* pBitmap = new CBitmap;
\r
2394 pBitmap->CreateMappedBitmap(nIDBitmap, (WORD)nFlags, lpColorMap, nMapSize);
\r
2395 m_pData->m_vGDIObjects.push_back(pBitmap);
\r
2396 ::SelectObject(m_pData->hDC, *pBitmap);;
\r
2398 #endif // !_WIN32_WCE
\r
2401 // Brush functions
\r
2402 #ifndef _WIN32_WCE
\r
2403 inline void CDC::CreateBrushIndirect(LPLOGBRUSH pLogBrush)
\r
2404 // Creates the brush and selects it into the device context.
\r
2405 // Returns a pointer to the old brush selected out of the device context.
\r
2407 assert(m_pData->hDC);
\r
2409 CBrush* pBrush = new CBrush;
\r
2410 pBrush->CreateBrushIndirect(pLogBrush);
\r
2411 m_pData->m_vGDIObjects.push_back(pBrush);
\r
2412 ::SelectObject(m_pData->hDC, *pBrush);
\r
2415 inline void CDC::CreateHatchBrush(int fnStyle, COLORREF rgb)
\r
2416 // Creates a brush with the specified hatch pattern and color, and selects it into the device context.
\r
2417 // Returns a pointer to the old brush selected out of the device context.
\r
2419 assert(m_pData->hDC);
\r
2421 CBrush* pBrush = new CBrush;
\r
2422 pBrush->CreateHatchBrush(fnStyle, rgb);
\r
2423 m_pData->m_vGDIObjects.push_back(pBrush);
\r
2424 ::SelectObject(m_pData->hDC, *pBrush);
\r
2427 inline void CDC::CreateDIBPatternBrush(HGLOBAL hglbDIBPacked, UINT fuColorSpec)
\r
2428 // Creates a logical from the specified device-independent bitmap (DIB), and selects it into the device context.
\r
2429 // Returns a pointer to the old brush selected out of the device context.
\r
2431 assert(m_pData->hDC);
\r
2433 CBrush* pBrush = new CBrush;
\r
2434 pBrush->CreateDIBPatternBrush(hglbDIBPacked, fuColorSpec);
\r
2435 m_pData->m_vGDIObjects.push_back(pBrush);
\r
2436 ::SelectObject(m_pData->hDC, *pBrush);
\r
2439 inline void CDC::CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT iUsage)
\r
2440 // Creates a logical from the specified device-independent bitmap (DIB), and selects it into the device context.
\r
2441 // Returns a pointer to the old brush selected out of the device context.
\r
2443 assert(m_pData->hDC);
\r
2445 CBrush* pBrush = new CBrush;
\r
2446 pBrush->CreateDIBPatternBrushPt(lpPackedDIB, iUsage);
\r
2447 m_pData->m_vGDIObjects.push_back(pBrush);
\r
2448 ::SelectObject(m_pData->hDC, *pBrush);
\r
2452 inline void CDC::CreatePatternBrush(CBitmap* pBitmap)
\r
2453 // Creates the brush with the specified pattern, and selects it into the device context.
\r
2454 // Returns a pointer to the old brush selected out of the device context.
\r
2456 assert(m_pData->hDC);
\r
2459 CBrush* pBrush = new CBrush;
\r
2460 pBrush->CreatePatternBrush(pBitmap);
\r
2461 m_pData->m_vGDIObjects.push_back(pBrush);
\r
2462 ::SelectObject(m_pData->hDC, *pBrush);
\r
2465 inline void CDC::CreateSolidBrush(COLORREF rgb)
\r
2466 // Creates the brush with the specified color, and selects it into the device context.
\r
2467 // Returns a pointer to the old brush selected out of the device context.
\r
2469 assert(m_pData->hDC);
\r
2471 CBrush* pBrush = new CBrush;
\r
2472 pBrush->CreateSolidBrush(rgb);
\r
2473 m_pData->m_vGDIObjects.push_back(pBrush);
\r
2474 ::SelectObject(m_pData->hDC, *pBrush);
\r
2477 inline LOGBRUSH CDC::GetLogBrush() const
\r
2478 // Retrieves the current brush information
\r
2480 assert(m_pData->hDC);
\r
2482 HBRUSH hBrush = (HBRUSH)::GetCurrentObject(m_pData->hDC, OBJ_BRUSH);
\r
2483 LOGBRUSH lBrush = {0};
\r
2484 ::GetObject(hBrush, sizeof(lBrush), &lBrush);
\r
2490 #ifndef _WIN32_WCE
\r
2491 inline void CDC::CreateFont (
\r
2492 int nHeight, // height of font
\r
2493 int nWidth, // average character width
\r
2494 int nEscapement, // angle of escapement
\r
2495 int nOrientation, // base-line orientation angle
\r
2496 int fnWeight, // font weight
\r
2497 DWORD fdwItalic, // italic attribute option
\r
2498 DWORD fdwUnderline, // underline attribute option
\r
2499 DWORD fdwStrikeOut, // strikeout attribute option
\r
2500 DWORD fdwCharSet, // character set identifier
\r
2501 DWORD fdwOutputPrecision, // output precision
\r
2502 DWORD fdwClipPrecision, // clipping precision
\r
2503 DWORD fdwQuality, // output quality
\r
2504 DWORD fdwPitchAndFamily, // pitch and family
\r
2505 LPCTSTR lpszFace // typeface name
\r
2508 // Creates a logical font with the specified characteristics.
\r
2509 // Returns a pointer to the old font selected out of the device context.
\r
2511 assert(m_pData->hDC);
\r
2513 CFont* pFont = new CFont;
\r
2514 pFont->CreateFont (nHeight, nWidth, nEscapement, nOrientation, fnWeight,
\r
2515 fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet,
\r
2516 fdwOutputPrecision, fdwClipPrecision, fdwQuality,
\r
2517 fdwPitchAndFamily, lpszFace);
\r
2518 m_pData->m_vGDIObjects.push_back(pFont);
\r
2519 ::SelectObject(m_pData->hDC, *pFont);
\r
2523 inline void CDC::CreateFontIndirect(LPLOGFONT plf)
\r
2524 // Creates a logical font and selects it into the device context.
\r
2525 // Returns a pointer to the old font selected out of the device context.
\r
2527 assert(m_pData->hDC);
\r
2529 CFont* pFont = new CFont;
\r
2530 pFont->CreateFontIndirect(plf);
\r
2531 m_pData->m_vGDIObjects.push_back(pFont);
\r
2532 ::SelectObject(m_pData->hDC, *pFont);
\r
2535 inline LOGFONT CDC::GetLogFont() const
\r
2536 // Retrieves the current font information.
\r
2538 assert(m_pData->hDC);
\r
2540 HFONT hFont = (HFONT)::GetCurrentObject(m_pData->hDC, OBJ_FONT);
\r
2541 LOGFONT lFont = {0};
\r
2542 ::GetObject(hFont, sizeof(lFont), &lFont);
\r
2547 inline void CDC::CreatePen (int nStyle, int nWidth, COLORREF rgb)
\r
2548 // Creates the pen and selects it into the device context.
\r
2549 // Returns a pointer to the old pen selected out of the device context.
\r
2551 assert(m_pData->hDC);
\r
2553 CPen* pPen = new CPen;
\r
2554 pPen->CreatePen(nStyle, nWidth, rgb);
\r
2555 m_pData->m_vGDIObjects.push_back(pPen);
\r
2556 ::SelectObject(m_pData->hDC, *pPen);
\r
2559 inline void CDC::CreatePenIndirect (LPLOGPEN pLogPen)
\r
2560 // Creates the pen and selects it into the device context.
\r
2561 // Returns a pointer to the old pen selected out of the device context.
\r
2563 assert(m_pData->hDC);
\r
2565 CPen* pPen = new CPen;
\r
2566 pPen->CreatePenIndirect(pLogPen);
\r
2567 m_pData->m_vGDIObjects.push_back(pPen);
\r
2568 ::SelectObject(m_pData->hDC, *pPen);
\r
2571 inline LOGPEN CDC::GetLogPen() const
\r
2572 // Retrieves the current pen information as a LOGPEN
\r
2574 assert(m_pData->hDC);
\r
2576 HPEN hPen = (HPEN)::GetCurrentObject(m_pData->hDC, OBJ_PEN);
\r
2577 LOGPEN lPen = {0};
\r
2578 ::GetObject(hPen, sizeof(lPen), &lPen);
\r
2582 // Region functions
\r
2583 inline int CDC::CreateRectRgn(int left, int top, int right, int bottom)
\r
2584 // Creates a rectangular region from the rectangle co-ordinates.
\r
2585 // The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
\r
2587 assert(m_pData->hDC);
\r
2589 CRgn* pRgn = new CRgn;
\r
2590 pRgn->CreateRectRgn(left, top, right, bottom);
\r
2591 m_pData->m_vGDIObjects.push_back(pRgn);
\r
2592 return SelectClipRgn(pRgn);
\r
2595 inline int CDC::CreateRectRgnIndirect(const RECT& rc)
\r
2596 // Creates a rectangular region from the rectangle co-ordinates.
\r
2597 // The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
\r
2599 assert(m_pData->hDC);
\r
2601 CRgn* pRgn = new CRgn;
\r
2602 pRgn->CreateRectRgnIndirect(rc);
\r
2603 m_pData->m_vGDIObjects.push_back(pRgn);
\r
2604 return SelectClipRgn(pRgn);
\r
2607 inline int CDC::CreateFromData(const XFORM* Xform, DWORD nCount, const RGNDATA *pRgnData)
\r
2608 // Creates a region from the specified region data and tranformation data.
\r
2609 // The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
\r
2610 // Notes: GetRegionData can be used to get a region's data
\r
2611 // If the XFROM pointer is NULL, the identity transformation is used.
\r
2613 assert(m_pData->hDC);
\r
2615 CRgn* pRgn = new CRgn;
\r
2616 pRgn->CreateFromData(Xform, nCount, pRgnData);
\r
2617 m_pData->m_vGDIObjects.push_back(pRgn);
\r
2618 return SelectClipRgn(pRgn);
\r
2622 #ifndef _WIN32_WCE
\r
2623 inline int CDC::CreateEllipticRgn(int left, int top, int right, int bottom)
\r
2624 // Creates the ellyiptical region from the bounding rectangle co-ordinates
\r
2625 // and selects it into the device context.
\r
2626 // The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
\r
2628 assert(m_pData->hDC);
\r
2630 CRgn* pRgn = new CRgn;
\r
2631 pRgn->CreateEllipticRgn(left, top, right, bottom);
\r
2632 m_pData->m_vGDIObjects.push_back(pRgn);
\r
2633 return SelectClipRgn(pRgn);
\r
2636 inline int CDC::CreateEllipticRgnIndirect(const RECT& rc)
\r
2637 // Creates the ellyiptical region from the bounding rectangle co-ordinates
\r
2638 // and selects it into the device context.
\r
2639 // The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
\r
2641 assert(m_pData->hDC);
\r
2643 CRgn* pRgn = new CRgn;
\r
2644 pRgn->CreateEllipticRgnIndirect(rc);
\r
2645 m_pData->m_vGDIObjects.push_back(pRgn);
\r
2646 return SelectClipRgn(pRgn);
\r
2649 inline int CDC::CreatePolygonRgn(LPPOINT ppt, int cPoints, int fnPolyFillMode)
\r
2650 // Creates the polygon region from the array of points and selects it into
\r
2651 // the device context. The polygon is presumed closed.
\r
2652 // The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
\r
2654 assert(m_pData->hDC);
\r
2656 CRgn* pRgn = new CRgn;
\r
2657 pRgn->CreatePolygonRgn(ppt, cPoints, fnPolyFillMode);
\r
2658 m_pData->m_vGDIObjects.push_back(pRgn);
\r
2659 return SelectClipRgn(pRgn);
\r
2662 inline int CDC::CreatePolyPolygonRgn(LPPOINT ppt, LPINT pPolyCounts, int nCount, int fnPolyFillMode)
\r
2663 // Creates the polygon region from a series of polygons.The polygons can overlap.
\r
2664 // The return value specifies the region's complexity: NULLREGION;SIMPLEREGION;COMPLEXREGION;ERROR.
\r
2666 assert(m_pData->hDC);
\r
2668 CRgn* pRgn = new CRgn;
\r
2669 pRgn->CreatePolyPolygonRgn(ppt, pPolyCounts, nCount, fnPolyFillMode);
\r
2670 m_pData->m_vGDIObjects.push_back(pRgn);
\r
2671 return SelectClipRgn(pRgn);
\r
2676 // Wrappers for WinAPI functions
\r
2678 inline int CDC::GetDeviceCaps (int nIndex) const
\r
2679 // Retrieves device-specific information for the specified device.
\r
2681 assert(m_pData->hDC);
\r
2682 return ::GetDeviceCaps(m_pData->hDC, nIndex);
\r
2685 // Brush Functions
\r
2686 #ifdef GetDCBrushColor
\r
2687 inline COLORREF CDC::GetDCBrushColor() const
\r
2689 assert(m_pData->hDC);
\r
2690 return ::GetDCBrushColor(m_pData->hDC);
\r
2693 inline COLORREF CDC::SetDCBrushColor(COLORREF crColor) const
\r
2695 assert(m_pData->hDC);
\r
2696 return ::SetDCBrushColor(m_pData->hDC, crColor);
\r
2700 // Clipping functions
\r
2701 inline int CDC::ExcludeClipRect(int Left, int Top, int Right, int BottomRect)
\r
2702 // Creates a new clipping region that consists of the existing clipping region minus the specified rectangle.
\r
2704 assert(m_pData->hDC);
\r
2705 return ::ExcludeClipRect(m_pData->hDC, Left, Top, Right, BottomRect);
\r
2708 inline int CDC::ExcludeClipRect(const RECT& rc)
\r
2709 // Creates a new clipping region that consists of the existing clipping region minus the specified rectangle.
\r
2711 assert(m_pData->hDC);
\r
2712 return ::ExcludeClipRect(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);
\r
2715 inline int CDC::GetClipBox (RECT& rc)
\r
2716 // Retrieves the dimensions of the tightest bounding rectangle that can be drawn around the current visible area on the device.
\r
2718 assert(m_pData->hDC);
\r
2719 return ::GetClipBox(m_pData->hDC, &rc);
\r
2722 inline int CDC::GetClipRgn(HRGN hrgn)
\r
2723 // Retrieves a handle identifying the current application-defined clipping region for the specified device context.
\r
2724 // hrgn: A handle to an existing region before the function is called.
\r
2725 // After the function returns, this parameter is a handle to a copy of the current clipping region.
\r
2727 assert(m_pData->hDC);
\r
2728 return ::GetClipRgn(m_pData->hDC, hrgn);
\r
2731 inline int CDC::IntersectClipRect(int Left, int Top, int Right, int Bottom)
\r
2732 // Creates a new clipping region from the intersection of the current clipping region and the specified rectangle.
\r
2734 assert(m_pData->hDC);
\r
2735 return ::IntersectClipRect(m_pData->hDC, Left, Top, Right, Bottom);
\r
2738 inline int CDC::IntersectClipRect(const RECT& rc)
\r
2739 // Creates a new clipping region from the intersection of the current clipping region and the specified rectangle.
\r
2741 assert(m_pData->hDC);
\r
2742 return ::IntersectClipRect(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);
\r
2745 inline BOOL CDC::RectVisible(const RECT& rc)
\r
2746 // Determines whether any part of the specified rectangle lies within the clipping region of a device context.
\r
2748 assert(m_pData->hDC);
\r
2749 return ::RectVisible (m_pData->hDC, &rc);
\r
2752 inline int CDC::SelectClipRgn(CRgn* pRgn)
\r
2753 // Selects a region as the current clipping region for the specified device context.
\r
2754 // Note: Only a copy of the selected region is used.
\r
2755 // To remove a device-context's clipping region, specify a NULL region handle.
\r
2757 assert(m_pData->hDC);
\r
2758 return ::SelectClipRgn(m_pData->hDC, pRgn? (HRGN)pRgn->GetHandle() : 0);
\r
2761 #ifndef _WIN32_WCE
\r
2762 inline int CDC::ExtSelectClipRgn(CRgn* pRgn, int fnMode)
\r
2763 // Combines the specified region with the current clipping region using the specified mode.
\r
2765 assert(m_pData->hDC);
\r
2767 return ::ExtSelectClipRgn(m_pData->hDC, *pRgn, fnMode);
\r
2771 inline CBitmap* CDC::SelectObject(const CBitmap* pBitmap)
\r
2772 // Use this to attach an existing bitmap.
\r
2774 assert(m_pData->hDC);
\r
2777 return FromHandle( (HBITMAP)::SelectObject(m_pData->hDC, *pBitmap) );
\r
2780 inline CBrush* CDC::SelectObject(const CBrush* pBrush)
\r
2781 // Use this to attach an existing brush.
\r
2783 assert(m_pData->hDC);
\r
2786 return FromHandle( (HBRUSH)::SelectObject(m_pData->hDC, *pBrush) );
\r
2789 inline CFont* CDC::SelectObject(const CFont* pFont)
\r
2790 // Use this to attach an existing font.
\r
2792 assert(m_pData->hDC);
\r
2795 return FromHandle( (HFONT)::SelectObject(m_pData->hDC, *pFont) );
\r
2798 inline CPalette* CDC::SelectObject(const CPalette* pPalette)
\r
2799 // Use this to attach an existing Palette.
\r
2801 assert(m_pData->hDC);
\r
2804 return FromHandle( (HPALETTE)::SelectObject(m_pData->hDC, *pPalette) );
\r
2807 inline CPen* CDC::SelectObject(const CPen* pPen)
\r
2808 // Use this to attach an existing pen.
\r
2810 assert(m_pData->hDC);
\r
2813 return FromHandle( (HPEN)::SelectObject(m_pData->hDC, *pPen) );
\r
2816 inline CPalette* CDC::SelectPalette(const CPalette* pPalette, BOOL bForceBkgnd)
\r
2817 // Use this to attach an existing palette.
\r
2819 assert(m_pData->hDC);
\r
2822 return FromHandle( (HPALETTE)::SelectPalette(m_pData->hDC, *pPalette, bForceBkgnd) );
\r
2824 #ifndef _WIN32_WCE
\r
2825 inline BOOL CDC::PtVisible(int X, int Y)
\r
2826 // Determines whether the specified point is within the clipping region of a device context.
\r
2828 assert(m_pData->hDC);
\r
2829 return ::PtVisible (m_pData->hDC, X, Y);
\r
2832 inline int CDC::OffsetClipRgn(int nXOffset, int nYOffset)
\r
2833 // Moves the clipping region of a device context by the specified offsets.
\r
2835 assert(m_pData->hDC);
\r
2836 return ::OffsetClipRgn (m_pData->hDC, nXOffset, nYOffset);
\r
2840 // Point and Line Drawing Functions
\r
2841 inline CPoint CDC::GetCurrentPosition() const
\r
2842 // Returns the current "MoveToEx" position.
\r
2844 assert(m_pData->hDC);
\r
2846 ::MoveToEx(m_pData->hDC, 0, 0, &pt);
\r
2847 ::MoveToEx(m_pData->hDC, pt.x, pt.y, NULL);
\r
2851 inline CPoint CDC::MoveTo(int x, int y) const
\r
2852 // Updates the current position to the specified point.
\r
2854 assert(m_pData->hDC);
\r
2855 return ::MoveToEx(m_pData->hDC, x, y, NULL);
\r
2858 inline CPoint CDC::MoveTo(POINT pt) const
\r
2859 // Updates the current position to the specified point
\r
2861 assert(m_pData->hDC);
\r
2862 return ::MoveToEx(m_pData->hDC, pt.x, pt.y, NULL);
\r
2865 inline BOOL CDC::LineTo(int x, int y) const
\r
2866 // Draws a line from the current position up to, but not including, the specified point.
\r
2868 assert(m_pData->hDC);
\r
2869 return ::LineTo(m_pData->hDC, x, y);
\r
2872 inline BOOL CDC::LineTo(POINT pt) const
\r
2873 // Draws a line from the current position up to, but not including, the specified point.
\r
2875 assert(m_pData->hDC);
\r
2876 return ::LineTo(m_pData->hDC, pt.x, pt.y);
\r
2879 #ifndef _WIN32_WCE
\r
2880 inline BOOL CDC::Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const
\r
2881 // Draws an elliptical arc.
\r
2883 assert(m_pData->hDC);
\r
2884 return ::Arc(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);
\r
2887 inline BOOL CDC::Arc(RECT& rc, POINT ptStart, POINT ptEnd) const
\r
2888 // Draws an elliptical arc.
\r
2890 assert(m_pData->hDC);
\r
2891 return ::Arc(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom,
\r
2892 ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
\r
2895 inline BOOL CDC::ArcTo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const
\r
2896 // Draws an elliptical arc.
\r
2898 assert(m_pData->hDC);
\r
2899 return ::ArcTo(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);
\r
2902 inline BOOL CDC::ArcTo(RECT& rc, POINT ptStart, POINT ptEnd) const
\r
2903 // Draws an elliptical arc.
\r
2905 assert(m_pData->hDC);
\r
2906 return ::ArcTo (m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom,
\r
2907 ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
\r
2910 inline BOOL CDC::AngleArc(int x, int y, int nRadius, float fStartAngle, float fSweepAngle) const
\r
2911 // Draws a line segment and an arc.
\r
2913 assert(m_pData->hDC);
\r
2914 return ::AngleArc(m_pData->hDC, x, y, nRadius, fStartAngle, fSweepAngle);
\r
2917 inline int CDC::GetArcDirection() const
\r
2918 // Retrieves the current arc direction ( AD_COUNTERCLOCKWISE or AD_CLOCKWISE ).
\r
2920 assert(m_pData->hDC);
\r
2921 return ::GetArcDirection(m_pData->hDC);
\r
2924 inline int CDC::SetArcDirection(int nArcDirection) const
\r
2925 // Sets the current arc direction ( AD_COUNTERCLOCKWISE or AD_CLOCKWISE ).
\r
2927 assert(m_pData->hDC);
\r
2928 return ::SetArcDirection(m_pData->hDC, nArcDirection);
\r
2931 inline BOOL CDC::PolyDraw(const POINT* lpPoints, const BYTE* lpTypes, int nCount) const
\r
2932 // Draws a set of line segments and Bzier curves.
\r
2934 assert(m_pData->hDC);
\r
2935 return ::PolyDraw(m_pData->hDC, lpPoints, lpTypes, nCount);
\r
2938 inline BOOL CDC::Polyline(LPPOINT lpPoints, int nCount) const
\r
2939 // Draws a series of line segments by connecting the points in the specified array.
\r
2941 assert(m_pData->hDC);
\r
2942 return ::Polyline(m_pData->hDC, lpPoints, nCount);
\r
2945 inline BOOL CDC::PolyPolyline(const POINT* lpPoints, const DWORD* lpPolyPoints, int nCount) const
\r
2946 // Draws multiple series of connected line segments.
\r
2948 assert(m_pData->hDC);
\r
2949 return ::PolyPolyline(m_pData->hDC, lpPoints, lpPolyPoints, nCount);
\r
2952 inline BOOL CDC::PolylineTo(const POINT* lpPoints, int nCount) const
\r
2953 // Draws one or more straight lines.
\r
2955 assert(m_pData->hDC);
\r
2956 return ::PolylineTo(m_pData->hDC, lpPoints, nCount);
\r
2958 inline BOOL CDC::PolyBezier(const POINT* lpPoints, int nCount) const
\r
2959 // Draws one or more Bzier curves.
\r
2961 assert(m_pData->hDC);
\r
2962 return ::PolyBezier(m_pData->hDC, lpPoints, nCount);
\r
2965 inline BOOL CDC::PolyBezierTo(const POINT* lpPoints, int nCount) const
\r
2966 // Draws one or more Bzier curves.
\r
2968 assert(m_pData->hDC);
\r
2969 return ::PolyBezierTo(m_pData->hDC, lpPoints, nCount );
\r
2972 inline COLORREF CDC::GetPixel(int x, int y) const
\r
2973 // Retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
\r
2975 assert(m_pData->hDC);
\r
2976 return ::GetPixel(m_pData->hDC, x, y);
\r
2979 inline COLORREF CDC::GetPixel(POINT pt) const
\r
2980 // Retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
\r
2982 assert(m_pData->hDC);
\r
2983 return ::GetPixel(m_pData->hDC, pt.x, pt.y);
\r
2986 inline COLORREF CDC::SetPixel (int x, int y, COLORREF crColor) const
\r
2987 // Sets the pixel at the specified coordinates to the specified color.
\r
2989 assert(m_pData->hDC);
\r
2990 return ::SetPixel(m_pData->hDC, x, y, crColor);
\r
2993 inline COLORREF CDC::SetPixel(POINT pt, COLORREF crColor) const
\r
2994 // Sets the pixel at the specified coordinates to the specified color.
\r
2996 assert(m_pData->hDC);
\r
2997 return ::SetPixel(m_pData->hDC, pt.x, pt.y, crColor);
\r
3000 inline BOOL CDC::SetPixelV(int x, int y, COLORREF crColor) const
\r
3001 // Sets the pixel at the specified coordinates to the closest approximation of the specified color.
\r
3003 assert(m_pData->hDC);
\r
3004 return ::SetPixelV(m_pData->hDC, x, y, crColor);
\r
3007 inline BOOL CDC::SetPixelV(POINT pt, COLORREF crColor) const
\r
3008 // Sets the pixel at the specified coordinates to the closest approximation of the specified color.
\r
3010 assert(m_pData->hDC);
\r
3011 return ::SetPixelV(m_pData->hDC, pt.x, pt.y, crColor);
\r
3015 // Shape Drawing Functions
\r
3016 inline void CDC::DrawFocusRect(const RECT& rc) const
\r
3017 // Draws a rectangle in the style used to indicate that the rectangle has the focus.
\r
3019 assert(m_pData->hDC);
\r
3020 ::DrawFocusRect(m_pData->hDC, &rc);
\r
3023 inline BOOL CDC::Ellipse(int x1, int y1, int x2, int y2) const
\r
3024 // Draws an ellipse. The center of the ellipse is the center of the specified bounding rectangle.
\r
3026 assert(m_pData->hDC);
\r
3027 return ::Ellipse(m_pData->hDC, x1, y1, x2, y2);
\r
3030 inline BOOL CDC::Ellipse(const RECT& rc) const
\r
3031 // Draws an ellipse. The center of the ellipse is the center of the specified bounding rectangle.
\r
3033 assert(m_pData->hDC);
\r
3034 return ::Ellipse(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);
\r
3037 inline BOOL CDC::Polygon(LPPOINT lpPoints, int nCount) const
\r
3038 // Draws a polygon consisting of two or more vertices connected by straight lines.
\r
3040 assert(m_pData->hDC);
\r
3041 return ::Polygon(m_pData->hDC, lpPoints, nCount);
\r
3044 inline BOOL CDC::Rectangle(int x1, int y1, int x2, int y2) const
\r
3045 // Draws a rectangle. The rectangle is outlined by using the current pen and filled by using the current brush.
\r
3047 assert(m_pData->hDC);
\r
3048 return ::Rectangle(m_pData->hDC, x1, y1, x2, y2);
\r
3051 inline BOOL CDC::Rectangle(const RECT& rc) const
\r
3052 // Draws a rectangle. The rectangle is outlined by using the current pen and filled by using the current brush.
\r
3054 assert(m_pData->hDC);
\r
3055 return ::Rectangle(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);
\r
3058 inline BOOL CDC::RoundRect(int x1, int y1, int x2, int y2, int nWidth, int nHeight) const
\r
3059 // Draws a rectangle with rounded corners.
\r
3061 assert(m_pData->hDC);
\r
3062 return ::RoundRect(m_pData->hDC, x1, y1, x2, y2, nWidth, nHeight);
\r
3064 inline BOOL CDC::RoundRect(const RECT& rc, int nWidth, int nHeight) const
\r
3065 // Draws a rectangle with rounded corners.
\r
3067 assert(m_pData->hDC);
\r
3068 return ::RoundRect(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom, nWidth, nHeight );
\r
3071 #ifndef _WIN32_WCE
\r
3072 inline BOOL CDC::Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const
\r
3073 // Draws a chord (a region bounded by the intersection of an ellipse and a line segment, called a secant).
\r
3075 assert(m_pData->hDC);
\r
3076 return ::Chord(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);
\r
3079 inline BOOL CDC::Chord(const RECT& rc, POINT ptStart, POINT ptEnd) const
\r
3080 // Draws a chord (a region bounded by the intersection of an ellipse and a line segment, called a secant).
\r
3082 assert(m_pData->hDC);
\r
3083 return ::Chord(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom,
\r
3084 ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
\r
3087 inline BOOL CDC::Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const
\r
3088 // Draws a pie-shaped wedge bounded by the intersection of an ellipse and two radials.
\r
3090 assert(m_pData->hDC);
\r
3091 return ::Pie(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);
\r
3094 inline BOOL CDC::Pie(const RECT& rc, POINT ptStart, POINT ptEnd) const
\r
3095 // Draws a pie-shaped wedge bounded by the intersection of an ellipse and two radials.
\r
3097 assert(m_pData->hDC);
\r
3098 return ::Pie(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom,
\r
3099 ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
\r
3102 inline BOOL CDC::PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount) const
\r
3103 // Draws a series of closed polygons.
\r
3105 assert(m_pData->hDC);
\r
3106 return ::PolyPolygon(m_pData->hDC, lpPoints, lpPolyCounts, nCount);
\r
3110 // Fill and 3D Drawing functions
\r
3111 inline BOOL CDC::FillRect(const RECT& rc, CBrush* pBrush) const
\r
3112 // Fills a rectangle by using the specified brush.
\r
3114 assert(m_pData->hDC);
\r
3116 return (BOOL)::FillRect(m_pData->hDC, &rc, *pBrush);
\r
3119 inline BOOL CDC::InvertRect(const RECT& rc) const
\r
3120 // Inverts a rectangle in a window by performing a logical NOT operation on the color values for each pixel in the rectangle's interior.
\r
3122 assert(m_pData->hDC);
\r
3123 return ::InvertRect( m_pData->hDC, &rc);
\r
3126 inline BOOL CDC::DrawIconEx(int xLeft, int yTop, HICON hIcon, int cxWidth, int cyWidth, UINT istepIfAniCur, CBrush* pFlickerFreeDraw, UINT diFlags) const
\r
3127 // draws an icon or cursor, performing the specified raster operations, and stretching or compressing the icon or cursor as specified.
\r
3129 assert(m_pData->hDC);
\r
3130 HBRUSH hFlickerFreeDraw = pFlickerFreeDraw? (HBRUSH)pFlickerFreeDraw->GetHandle() : NULL;
\r
3131 return ::DrawIconEx(m_pData->hDC, xLeft, yTop, hIcon, cxWidth, cyWidth, istepIfAniCur, hFlickerFreeDraw, diFlags);
\r
3134 inline BOOL CDC::DrawEdge(const RECT& rc, UINT nEdge, UINT nFlags) const
\r
3135 // Draws one or more edges of rectangle.
\r
3137 assert(m_pData->hDC);
\r
3138 return ::DrawEdge(m_pData->hDC, (LPRECT)&rc, nEdge, nFlags);
\r
3141 inline BOOL CDC::DrawFrameControl(const RECT& rc, UINT nType, UINT nState) const
\r
3142 // Draws a frame control of the specified type and style.
\r
3144 assert(m_pData->hDC);
\r
3145 return ::DrawFrameControl(m_pData->hDC, (LPRECT)&rc, nType, nState);
\r
3148 inline BOOL CDC::FillRgn(CRgn* pRgn, CBrush* pBrush) const
\r
3149 // Fills a region by using the specified brush.
\r
3151 assert(m_pData->hDC);
\r
3154 return ::FillRgn(m_pData->hDC, *pRgn, *pBrush);
\r
3157 #ifndef _WIN32_WCE
\r
3158 inline BOOL CDC::DrawIcon(int x, int y, HICON hIcon) const
\r
3159 // Draws an icon or cursor.
\r
3161 assert(m_pData->hDC);
\r
3162 return ::DrawIcon(m_pData->hDC, x, y, hIcon);
\r
3165 inline BOOL CDC::DrawIcon(POINT pt, HICON hIcon) const
\r
3166 // Draws an icon or cursor.
\r
3168 assert(m_pData->hDC);
\r
3169 return ::DrawIcon(m_pData->hDC, pt.x, pt.y, hIcon);
\r
3172 inline BOOL CDC::FrameRect(const RECT& rc, CBrush* pBrush) const
\r
3173 // Draws a border around the specified rectangle by using the specified brush.
\r
3175 assert(m_pData->hDC);
\r
3177 return (BOOL)::FrameRect(m_pData->hDC, &rc, *pBrush);
\r
3180 inline BOOL CDC::PaintRgn(CRgn* pRgn) const
\r
3181 // Paints the specified region by using the brush currently selected into the device context.
\r
3183 assert(m_pData->hDC);
\r
3185 return ::PaintRgn(m_pData->hDC, *pRgn);
\r
3189 // Bitmap Functions
\r
3190 inline int CDC::StretchDIBits(int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth,
\r
3191 int nSrcHeight, CONST VOID *lpBits, BITMAPINFO& bi, UINT iUsage, DWORD dwRop) const
\r
3192 // Copies the color data for a rectangle of pixels in a DIB to the specified destination rectangle.
\r
3194 assert(m_pData->hDC);
\r
3195 return ::StretchDIBits(m_pData->hDC, XDest, YDest, nDestWidth, nDestHeight, XSrc, YSrc, nSrcWidth, nSrcHeight, lpBits, &bi, iUsage, dwRop);
\r
3198 inline BOOL CDC::PatBlt(int x, int y, int nWidth, int nHeight, DWORD dwRop) const
\r
3199 // Paints the specified rectangle using the brush that is currently selected into the device context.
\r
3201 assert(m_pData->hDC);
\r
3202 return ::PatBlt(m_pData->hDC, x, y, nWidth, nHeight, dwRop);
\r
3205 inline BOOL CDC::BitBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop) const
\r
3206 // Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
\r
3208 assert(m_pData->hDC);
\r
3210 return ::BitBlt(m_pData->hDC, x, y, nWidth, nHeight, pSrcDC->GetHDC(), xSrc, ySrc, dwRop);
\r
3213 inline BOOL CDC::StretchBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop) const
\r
3214 // Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
\r
3216 assert(m_pData->hDC);
\r
3218 return ::StretchBlt(m_pData->hDC, x, y, nWidth, nHeight, pSrcDC->GetHDC(), xSrc, ySrc, nSrcWidth, nSrcHeight, dwRop);
\r
3221 #ifndef _WIN32_WCE
\r
3222 inline int CDC::GetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbi, UINT uUsage) const
\r
3223 // Retrieves the bits of the specified compatible bitmap and copies them into a buffer as a DIB using the specified format.
\r
3225 assert(m_pData->hDC);
\r
3227 return ::GetDIBits(m_pData->hDC, *pBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage);
\r
3230 inline int CDC::SetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, CONST VOID *lpvBits, LPBITMAPINFO lpbi, UINT fuColorUse) const
\r
3231 // Sets the pixels in a compatible bitmap (DDB) using the color data found in the specified DIB.
\r
3233 assert(m_pData->hDC);
\r
3234 return ::SetDIBits(m_pData->hDC, *pBitmap, uStartScan, cScanLines, lpvBits, lpbi, fuColorUse);
\r
3237 inline int CDC::GetStretchBltMode() const
\r
3238 // Retrieves the current stretching mode.
\r
3239 // Possible modes: BLACKONWHITE, COLORONCOLOR, HALFTONE, STRETCH_ANDSCANS, STRETCH_DELETESCANS, STRETCH_HALFTONE, STRETCH_ORSCANS, WHITEONBLACK
\r
3241 assert(m_pData->hDC);
\r
3242 return ::GetStretchBltMode(m_pData->hDC);
\r
3245 inline int CDC::SetStretchBltMode(int iStretchMode) const
\r
3246 // Sets the stretching mode.
\r
3247 // Possible modes: BLACKONWHITE, COLORONCOLOR, HALFTONE, STRETCH_ANDSCANS, STRETCH_DELETESCANS, STRETCH_HALFTONE, STRETCH_ORSCANS, WHITEONBLACK
\r
3249 assert(m_pData->hDC);
\r
3250 return ::SetStretchBltMode(m_pData->hDC, iStretchMode);
\r
3253 inline BOOL CDC::FloodFill(int x, int y, COLORREF crColor) const
\r
3254 // Fills an area of the display surface with the current brush.
\r
3256 assert(m_pData->hDC);
\r
3257 return ::FloodFill(m_pData->hDC, x, y, crColor);
\r
3260 inline BOOL CDC::ExtFloodFill(int x, int y, COLORREF crColor, UINT nFillType) const
\r
3261 // Fills an area of the display surface with the current brush.
\r
3262 // Fill type: FLOODFILLBORDER or FLOODFILLSURFACE
\r
3264 assert(m_pData->hDC);
\r
3265 return ::ExtFloodFill(m_pData->hDC, x, y, crColor, nFillType );
\r
3268 // co-ordinate functions
\r
3269 inline BOOL CDC::DPtoLP(LPPOINT lpPoints, int nCount) const
\r
3270 // Converts device coordinates into logical coordinates.
\r
3272 assert(m_pData->hDC);
\r
3273 return ::DPtoLP(m_pData->hDC, lpPoints, nCount);
\r
3276 inline BOOL CDC::DPtoLP(RECT& rc) const
\r
3277 // Converts device coordinates into logical coordinates.
\r
3279 assert(m_pData->hDC);
\r
3280 return ::DPtoLP(m_pData->hDC, (LPPOINT)&rc, 2);
\r
3283 inline BOOL CDC::LPtoDP(LPPOINT lpPoints, int nCount) const
\r
3284 // Converts logical coordinates into device coordinates.
\r
3286 assert(m_pData->hDC);
\r
3287 return ::LPtoDP(m_pData->hDC, lpPoints, nCount);
\r
3290 inline BOOL CDC::LPtoDP(RECT& rc) const
\r
3291 // Converts logical coordinates into device coordinates.
\r
3293 assert(m_pData->hDC);
\r
3294 return ::LPtoDP(m_pData->hDC, (LPPOINT)&rc, 2);
\r
3299 // Layout Functions
\r
3300 inline DWORD CDC::GetLayout() const
\r
3301 // Returns the layout of a device context (LAYOUT_RTL and LAYOUT_BITMAPORIENTATIONPRESERVED).
\r
3303 #if defined(WINVER) && defined(GetLayout) && (WINVER >= 0x0500)
\r
3304 return ::GetLayout(m_pData->hDC);
\r
3310 inline DWORD CDC::SetLayout(DWORD dwLayout) const
\r
3311 // changes the layout of a device context (DC).
\r
3312 // dwLayout values: LAYOUT_RTL or LAYOUT_BITMAPORIENTATIONPRESERVED
\r
3314 #if defined(WINVER) && defined (SetLayout) && (WINVER >= 0x0500)
\r
3315 // Sets the layout of a device context
\r
3316 return ::SetLayout(m_pData->hDC, dwLayout);
\r
3318 UNREFERENCED_PARAMETER(dwLayout); // no-op
\r
3323 // Mapping Functions
\r
3324 #ifndef _WIN32_WCE
\r
3325 inline int CDC::GetMapMode() const
\r
3326 // Rretrieves the current mapping mode.
\r
3327 // Possible modes: MM_ANISOTROPIC, MM_HIENGLISH, MM_HIMETRIC, MM_ISOTROPIC, MM_LOENGLISH, MM_LOMETRIC, MM_TEXT, and MM_TWIPS.
\r
3329 assert(m_pData->hDC);
\r
3330 return ::GetMapMode(m_pData->hDC);
\r
3333 inline BOOL CDC::GetViewportOrgEx(LPPOINT lpPoint) const
\r
3334 // Retrieves the x-coordinates and y-coordinates of the viewport origin for the device context.
\r
3336 assert(m_pData->hDC);
\r
3337 return ::GetViewportOrgEx(m_pData->hDC, lpPoint);
\r
3340 inline int CDC::SetMapMode(int nMapMode) const
\r
3341 // Sets the mapping mode of the specified device context.
\r
3343 assert(m_pData->hDC);
\r
3344 return ::SetMapMode(m_pData->hDC, nMapMode);
\r
3347 inline BOOL CDC::SetViewportOrgEx(int x, int y, LPPOINT lpPoint /* = NULL */) const
\r
3348 // Specifies which device point maps to the window origin (0,0).
\r
3350 assert(m_pData->hDC);
\r
3351 return ::SetViewportOrgEx(m_pData->hDC, x, y, lpPoint);
\r
3354 inline BOOL CDC::SetViewportOrgEx(POINT point, LPPOINT lpPointRet /* = NULL */) const
\r
3355 // Specifies which device point maps to the window origin (0,0).
\r
3357 assert(m_pData->hDC);
\r
3358 return SetViewportOrgEx(point.x, point.y, lpPointRet);
\r
3361 inline BOOL CDC::OffsetViewportOrgEx(int nWidth, int nHeight, LPPOINT lpPoint /* = NULL */) const
\r
3362 // Modifies the viewport origin for the device context using the specified horizontal and vertical offsets.
\r
3364 assert(m_pData->hDC);
\r
3365 return ::OffsetViewportOrgEx(m_pData->hDC, nWidth, nHeight, lpPoint);
\r
3368 inline BOOL CDC::GetViewportExtEx(LPSIZE lpSize) const
\r
3369 // Retrieves the x-extent and y-extent of the current viewport for the device context.
\r
3371 assert(m_pData->hDC);
\r
3372 return ::GetViewportExtEx(m_pData->hDC, lpSize);
\r
3375 inline BOOL CDC::SetViewportExtEx(int x, int y, LPSIZE lpSize ) const
\r
3376 // Sets the horizontal and vertical extents of the viewport for the device context by using the specified values.
\r
3378 assert(m_pData->hDC);
\r
3379 return ::SetViewportExtEx(m_pData->hDC, x, y, lpSize);
\r
3382 inline BOOL CDC::SetViewportExtEx(SIZE size, LPSIZE lpSizeRet ) const
\r
3383 // Sets the horizontal and vertical extents of the viewport for the device context by using the specified values.
\r
3385 assert(m_pData->hDC);
\r
3386 return SetViewportExtEx(size.cx, size.cy, lpSizeRet);
\r
3389 inline BOOL CDC::ScaleViewportExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize ) const
\r
3390 // Modifies the viewport for the device context using the ratios formed by the specified multiplicands and divisors.
\r
3392 assert(m_pData->hDC);
\r
3393 return ::ScaleViewportExtEx(m_pData->hDC, xNum, xDenom, yNum, yDenom, lpSize);
\r
3396 inline BOOL CDC::GetWindowOrgEx(LPPOINT lpPoint) const
\r
3397 // Retrieves the x-coordinates and y-coordinates of the window origin for the device context.
\r
3399 assert(m_pData->hDC);
\r
3400 return ::GetWindowOrgEx(m_pData->hDC, lpPoint);
\r
3403 inline BOOL CDC::SetWindowOrgEx(int x, int y, LPPOINT lpPoint ) const
\r
3404 // Specifies which window point maps to the viewport origin (0,0).
\r
3406 assert(m_pData->hDC);
\r
3407 return ::SetWindowOrgEx(m_pData->hDC, x, y, lpPoint);
\r
3410 inline BOOL CDC::SetWindowOrgEx(POINT point, LPPOINT lpPointRet ) const
\r
3411 // Specifies which window point maps to the viewport origin (0,0).
\r
3413 assert(m_pData->hDC);
\r
3414 return SetWindowOrgEx(point.x, point.y, lpPointRet);
\r
3417 inline BOOL CDC::OffsetWindowOrgEx(int nWidth, int nHeight, LPPOINT lpPoint ) const
\r
3418 // Modifies the window origin for the device context using the specified horizontal and vertical offsets.
\r
3420 assert(m_pData->hDC);
\r
3421 return ::OffsetWindowOrgEx(m_pData->hDC, nWidth, nHeight, lpPoint);
\r
3424 inline BOOL CDC::GetWindowExtEx(LPSIZE lpSize) const
\r
3425 // Retrieves the x-extent and y-extent of the window for the device context.
\r
3427 assert(m_pData->hDC);
\r
3428 return ::GetWindowExtEx(m_pData->hDC, lpSize);
\r
3431 inline BOOL CDC::SetWindowExtEx(int x, int y, LPSIZE lpSize ) const
\r
3432 // Sets the horizontal and vertical extents of the window for the device context by using the specified values.
\r
3434 assert(m_pData->hDC);
\r
3435 return ::SetWindowExtEx(m_pData->hDC, x, y, lpSize);
\r
3438 inline BOOL CDC::SetWindowExtEx(SIZE size, LPSIZE lpSizeRet) const
\r
3439 // Sets the horizontal and vertical extents of the window for the device context by using the specified values.
\r
3441 assert(m_pData->hDC);
\r
3442 return SetWindowExtEx(size.cx, size.cy, lpSizeRet);
\r
3445 inline BOOL CDC::ScaleWindowExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize) const
\r
3446 // Modifies the window for the device context using the ratios formed by the specified multiplicands and divisors.
\r
3448 assert(m_pData->hDC);
\r
3449 return ::ScaleWindowExtEx(m_pData->hDC, xNum, xDenom, yNum, yDenom, lpSize);
\r
3453 // Printer Functions
\r
3454 inline int CDC::StartDoc(LPDOCINFO lpDocInfo) const
\r
3455 // Starts a print job.
\r
3457 assert(m_pData->hDC);
\r
3458 return ::StartDoc(m_pData->hDC, lpDocInfo);
\r
3461 inline int CDC::EndDoc() const
\r
3462 // Ends a print job.
\r
3464 assert(m_pData->hDC);
\r
3465 return ::EndDoc(m_pData->hDC);
\r
3468 inline int CDC::StartPage() const
\r
3469 // Prepares the printer driver to accept data.
\r
3471 assert(m_pData->hDC);
\r
3472 return ::StartPage(m_pData->hDC);
\r
3475 inline int CDC::EndPage() const
\r
3476 // Notifies the device that the application has finished writing to a page.
\r
3478 assert(m_pData->hDC);
\r
3479 return ::EndPage(m_pData->hDC);
\r
3482 inline int CDC::AbortDoc() const
\r
3483 // Stops the current print job and erases everything drawn since the last call to the StartDoc function.
\r
3485 assert(m_pData->hDC);
\r
3486 return ::AbortDoc(m_pData->hDC);
\r
3489 inline int CDC::SetAbortProc(BOOL (CALLBACK* lpfn)(HDC, int)) const
\r
3490 // Sets the application-defined abort function that allows a print job to be canceled during spooling.
\r
3492 assert(m_pData->hDC);
\r
3493 return ::SetAbortProc(m_pData->hDC, lpfn);
\r
3497 inline BOOL CDC::ExtTextOut(int x, int y, UINT nOptions, LPCRECT lprc, LPCTSTR lpszString, int nCount /*= -1*/, LPINT lpDxWidths /*=NULL*/) const
\r
3498 // Draws text using the currently selected font, background color, and text color
\r
3500 assert(m_pData->hDC);
\r
3503 nCount = lstrlen (lpszString);
\r
3505 return ::ExtTextOut(m_pData->hDC, x, y, nOptions, lprc, lpszString, nCount, lpDxWidths );
\r
3508 inline int CDC::DrawText(LPCTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat) const
\r
3509 // Draws formatted text in the specified rectangle
\r
3511 assert(m_pData->hDC);
\r
3512 return ::DrawText(m_pData->hDC, lpszString, nCount, lprc, nFormat );
\r
3515 inline UINT CDC::GetTextAlign() const
\r
3516 // Retrieves the text-alignment setting
\r
3517 // Values: TA_BASELINE, TA_BOTTOM, TA_TOP, TA_CENTER, TA_LEFT, TA_RIGHT, TA_RTLREADING, TA_NOUPDATECP, TA_UPDATECP
\r
3519 assert(m_pData->hDC);
\r
3520 return ::GetTextAlign(m_pData->hDC);
\r
3523 inline UINT CDC::SetTextAlign(UINT nFlags) const
\r
3524 // Sets the text-alignment setting
\r
3525 // Values: TA_BASELINE, TA_BOTTOM, TA_TOP, TA_CENTER, TA_LEFT, TA_RIGHT, TA_RTLREADING, TA_NOUPDATECP, TA_UPDATECP
\r
3527 assert(m_pData->hDC);
\r
3528 return ::SetTextAlign(m_pData->hDC, nFlags);
\r
3531 inline int CDC::GetTextFace(int nCount, LPTSTR lpszFacename) const
\r
3532 // Retrieves the typeface name of the font that is selected into the device context
\r
3534 assert(m_pData->hDC);
\r
3535 return ::GetTextFace(m_pData->hDC, nCount, lpszFacename);
\r
3538 inline BOOL CDC::GetTextMetrics(TEXTMETRIC& Metrics) const
\r
3539 // Fills the specified buffer with the metrics for the currently selected font
\r
3541 assert(m_pData->hDC);
\r
3542 return ::GetTextMetrics(m_pData->hDC, &Metrics);
\r
3545 inline COLORREF CDC::GetBkColor() const
\r
3546 // Returns the current background color
\r
3548 assert(m_pData->hDC);
\r
3549 return ::GetBkColor(m_pData->hDC);
\r
3552 inline COLORREF CDC::SetBkColor(COLORREF crColor) const
\r
3553 // Sets the current background color to the specified color value
\r
3555 assert(m_pData->hDC);
\r
3556 return ::SetBkColor(m_pData->hDC, crColor);
\r
3559 inline COLORREF CDC::GetTextColor() const
\r
3560 // Retrieves the current text color
\r
3562 assert(m_pData->hDC);
\r
3563 return ::GetTextColor(m_pData->hDC);
\r
3566 inline COLORREF CDC::SetTextColor(COLORREF crColor) const
\r
3567 // Sets the current text color
\r
3569 assert(m_pData->hDC);
\r
3570 return ::SetTextColor(m_pData->hDC, crColor);
\r
3573 inline int CDC::GetBkMode() const
\r
3574 // returns the current background mix mode (OPAQUE or TRANSPARENT)
\r
3576 assert(m_pData->hDC);
\r
3577 return ::GetBkMode(m_pData->hDC);
\r
3580 inline int CDC::SetBkMode(int iBkMode) const
\r
3581 // Sets the current background mix mode (OPAQUE or TRANSPARENT)
\r
3583 assert(m_pData->hDC);
\r
3584 return ::SetBkMode(m_pData->hDC, iBkMode);
\r
3587 #ifndef _WIN32_WCE
\r
3588 inline int CDC::DrawTextEx(LPTSTR lpszString, int nCount, LPRECT lprc, UINT nFormat, LPDRAWTEXTPARAMS lpDTParams) const
\r
3589 // Draws formatted text in the specified rectangle with more formatting options
\r
3591 assert(m_pData->hDC);
\r
3592 return ::DrawTextEx(m_pData->hDC, lpszString, nCount, lprc, nFormat, lpDTParams);
\r
3595 inline CSize CDC::GetTextExtentPoint32(LPCTSTR lpszString, int nCount) const
\r
3596 // Computes the width and height of the specified string of text
\r
3598 assert(m_pData->hDC);
\r
3600 ::GetTextExtentPoint32(m_pData->hDC, lpszString, nCount, &sz);
\r
3604 inline CSize CDC::GetTabbedTextExtent(LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions) const
\r
3605 // Computes the width and height of a character string
\r
3607 assert(m_pData->hDC);
\r
3608 DWORD dwSize = ::GetTabbedTextExtent(m_pData->hDC, lpszString, nCount, nTabPositions, lpnTabStopPositions );
\r
3613 inline BOOL CDC::GrayString(CBrush* pBrush, GRAYSTRINGPROC lpOutputFunc, LPARAM lpData, int nCount, int x, int y, int nWidth, int nHeight) const
\r
3614 // Draws gray text at the specified location
\r
3616 assert(m_pData->hDC);
\r
3618 return ::GrayString(m_pData->hDC, *pBrush, lpOutputFunc, lpData, nCount, x, y, nWidth, nHeight);
\r
3621 inline int CDC::SetTextJustification(int nBreakExtra, int nBreakCount) const
\r
3622 // Specifies the amount of space the system should add to the break characters in a string of text
\r
3624 assert(m_pData->hDC);
\r
3625 return ::SetTextJustification(m_pData->hDC, nBreakExtra, nBreakCount);
\r
3628 inline int CDC::GetTextCharacterExtra() const
\r
3629 // Retrieves the current intercharacter spacing for the device context
\r
3631 assert(m_pData->hDC);
\r
3632 return ::GetTextCharacterExtra(m_pData->hDC);
\r
3635 inline int CDC::SetTextCharacterExtra(int nCharExtra) const
\r
3636 // Sets the intercharacter spacing
\r
3638 assert(m_pData->hDC);
\r
3639 return ::SetTextCharacterExtra(m_pData->hDC, nCharExtra);
\r
3642 inline CSize CDC::TabbedTextOut(int x, int y, LPCTSTR lpszString, int nCount, int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin) const
\r
3643 // Writes a character string at a specified location, expanding tabs to the values specified in an array of tab-stop positions
\r
3645 assert(m_pData->hDC);
\r
3646 DWORD dwSize = ::TabbedTextOut(m_pData->hDC, x, y, lpszString, nCount, nTabPositions, lpnTabStopPositions, nTabOrigin );
\r
3651 inline BOOL CDC::TextOut(int x, int y, LPCTSTR lpszString, int nCount/* = -1*/) const
\r
3652 // Writes a character string at the specified location
\r
3654 assert(m_pData->hDC);
\r
3656 nCount = lstrlen (lpszString);
\r
3658 return ::TextOut(m_pData->hDC, x, y, lpszString, nCount);
\r
3665 /////////////////////////////////////////////////////////////////
\r
3666 // Definitions for some global functions in the Win32xx namespace
\r
3669 #ifndef _WIN32_WCE
\r
3670 inline void TintBitmap (CBitmap* pbmSource, int cRed, int cGreen, int cBlue)
\r
3671 // Modifies the colour of the supplied Device Dependant Bitmap, by the colour
\r
3672 // correction values specified. The correction values can range from -255 to +255.
\r
3673 // This function gains its speed by accessing the bitmap colour information
\r
3674 // directly, rather than using GetPixel/SetPixel.
\r
3676 // Create our LPBITMAPINFO object
\r
3677 CBitmapInfoPtr pbmi(pbmSource);
\r
3678 pbmi->bmiHeader.biBitCount = 24;
\r
3680 // Create the reference DC for GetDIBits to use
\r
3681 CMemDC MemDC(NULL);
\r
3683 // Use GetDIBits to create a DIB from our DDB, and extract the colour data
\r
3684 MemDC.GetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, NULL, pbmi, DIB_RGB_COLORS);
\r
3685 std::vector<byte> vBits(pbmi->bmiHeader.biSizeImage, 0);
\r
3686 byte* pByteArray = &vBits[0];
\r
3688 MemDC.GetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, pByteArray, pbmi, DIB_RGB_COLORS);
\r
3689 UINT nWidthBytes = pbmi->bmiHeader.biSizeImage/pbmi->bmiHeader.biHeight;
\r
3691 // Ensure sane colour correction values
\r
3692 cBlue = MIN(cBlue, 255);
\r
3693 cBlue = MAX(cBlue, -255);
\r
3694 cRed = MIN(cRed, 255);
\r
3695 cRed = MAX(cRed, -255);
\r
3696 cGreen = MIN(cGreen, 255);
\r
3697 cGreen = MAX(cGreen, -255);
\r
3699 // Pre-calculate the RGB modification values
\r
3700 int b1 = 256 - cBlue;
\r
3701 int g1 = 256 - cGreen;
\r
3702 int r1 = 256 - cRed;
\r
3704 int b2 = 256 + cBlue;
\r
3705 int g2 = 256 + cGreen;
\r
3706 int r2 = 256 + cRed;
\r
3708 // Modify the colour
\r
3712 for (int Row=0; Row < pbmi->bmiHeader.biHeight; Row++)
\r
3716 for (int Column=0; Column < pbmi->bmiHeader.biWidth; Column++)
\r
3718 // Calculate Index
\r
3719 Index = yOffset + xOffset;
\r
3721 // Adjust the colour values
\r
3723 pByteArray[Index] = (BYTE)(cBlue + (((pByteArray[Index] *b1)) >>8));
\r
3724 else if (cBlue < 0)
\r
3725 pByteArray[Index] = (BYTE)((pByteArray[Index] *b2) >>8);
\r
3728 pByteArray[Index+1] = (BYTE)(cGreen + (((pByteArray[Index+1] *g1)) >>8));
\r
3729 else if (cGreen < 0)
\r
3730 pByteArray[Index+1] = (BYTE)((pByteArray[Index+1] *g2) >>8);
\r
3733 pByteArray[Index+2] = (BYTE)(cRed + (((pByteArray[Index+2] *r1)) >>8));
\r
3734 else if (cRed < 0)
\r
3735 pByteArray[Index+2] = (BYTE)((pByteArray[Index+2] *r2) >>8);
\r
3737 // Increment the horizontal offset
\r
3738 xOffset += pbmi->bmiHeader.biBitCount >> 3;
\r
3741 // Increment vertical offset
\r
3742 yOffset += nWidthBytes;
\r
3745 // Save the modified colour back into our source DDB
\r
3746 MemDC.SetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, pByteArray, pbmi, DIB_RGB_COLORS);
\r
3749 inline void GrayScaleBitmap(CBitmap* pbmSource)
\r
3751 // Create our LPBITMAPINFO object
\r
3752 CBitmapInfoPtr pbmi(pbmSource);
\r
3754 // Create the reference DC for GetDIBits to use
\r
3755 CMemDC MemDC(NULL);
\r
3757 // Use GetDIBits to create a DIB from our DDB, and extract the colour data
\r
3758 MemDC.GetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, NULL, pbmi, DIB_RGB_COLORS);
\r
3759 std::vector<byte> vBits(pbmi->bmiHeader.biSizeImage, 0);
\r
3760 byte* pByteArray = &vBits[0];
\r
3762 MemDC.GetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, pByteArray, pbmi, DIB_RGB_COLORS);
\r
3763 UINT nWidthBytes = pbmi->bmiHeader.biSizeImage/pbmi->bmiHeader.biHeight;
\r
3769 for (int Row=0; Row < pbmi->bmiHeader.biHeight; Row++)
\r
3773 for (int Column=0; Column < pbmi->bmiHeader.biWidth; Column++)
\r
3775 // Calculate Index
\r
3776 Index = yOffset + xOffset;
\r
3778 BYTE byGray = (BYTE) ((pByteArray[Index] + pByteArray[Index+1]*6 + pByteArray[Index+2] *3)/10);
\r
3779 pByteArray[Index] = byGray;
\r
3780 pByteArray[Index+1] = byGray;
\r
3781 pByteArray[Index+2] = byGray;
\r
3783 // Increment the horizontal offset
\r
3784 xOffset += pbmi->bmiHeader.biBitCount >> 3;
\r
3787 // Increment vertical offset
\r
3788 yOffset += nWidthBytes;
\r
3791 // Save the modified colour back into our source DDB
\r
3792 MemDC.SetDIBits(pbmSource, 0, pbmi->bmiHeader.biHeight, pByteArray, pbmi, DIB_RGB_COLORS);
\r
3795 inline HIMAGELIST CreateDisabledImageList(HIMAGELIST himlNormal)
\r
3796 // Returns a greyed image list, created from hImageList
\r
3799 int nCount = ImageList_GetImageCount(himlNormal);
\r
3803 ImageList_GetIconSize(himlNormal, &cx, &cy);
\r
3805 // Create the disabled ImageList
\r
3806 HIMAGELIST himlDisabled = ImageList_Create(cx, cy, ILC_COLOR24 | ILC_MASK, nCount, 0);
\r
3808 // Process each image in the ImageList
\r
3809 for (int i = 0 ; i < nCount; ++i)
\r
3811 CClientDC DesktopDC(NULL);
\r
3812 CMemDC MemDC(NULL);
\r
3813 MemDC.CreateCompatibleBitmap(&DesktopDC, cx, cx);
\r
3815 rc.SetRect(0, 0, cx, cx);
\r
3817 // Set the mask color to grey for the new ImageList
\r
3818 COLORREF crMask = RGB(200, 199, 200);
\r
3819 if ( GetDeviceCaps(DesktopDC, BITSPIXEL) < 24)
\r
3821 HPALETTE hPal = (HPALETTE)GetCurrentObject(DesktopDC, OBJ_PAL);
\r
3822 UINT Index = GetNearestPaletteIndex(hPal, crMask);
\r
3823 if (Index != CLR_INVALID) crMask = PALETTEINDEX(Index);
\r
3826 MemDC.SolidFill(crMask, rc);
\r
3828 // Draw the image on the memory DC
\r
3829 ImageList_SetBkColor(himlNormal, crMask);
\r
3830 ImageList_Draw(himlNormal, i, MemDC, 0, 0, ILD_NORMAL);
\r
3832 // Convert colored pixels to gray
\r
3833 for (int x = 0 ; x < cx; ++x)
\r
3835 for (int y = 0; y < cy; ++y)
\r
3837 COLORREF clr = ::GetPixel(MemDC, x, y);
\r
3839 if (clr != crMask)
\r
3841 BYTE byGray = (BYTE) (95 + (GetRValue(clr) *3 + GetGValue(clr)*6 + GetBValue(clr))/20);
\r
3842 MemDC.SetPixel(x, y, RGB(byGray, byGray, byGray));
\r
3848 // Detach the bitmap so we can use it.
\r
3849 CBitmap Bitmap = MemDC.DetachBitmap();
\r
3850 ImageList_AddMasked(himlDisabled, Bitmap, crMask);
\r
3853 return himlDisabled;
\r
3857 ////////////////////////////////////////////
\r
3858 // Global Function Definitions
\r
3861 inline CDC* FromHandle(HDC hDC)
\r
3862 // Returns the CDC object associated with the device context handle
\r
3863 // If a CDC object doesn't already exist, a temporary CDC object is created.
\r
3864 // The HDC belonging to a temporary CDC is not released or destroyed when the
\r
3865 // temporary CDC is deconstructed.
\r
3867 assert( GetApp() );
\r
3868 CDC* pDC = GetApp()->GetCDCFromMap(hDC);
\r
3869 if (hDC != 0 && pDC == 0)
\r
3872 GetApp()->AddTmpDC(pDC);
\r
3873 pDC->m_pData->hDC = hDC;
\r
3874 pDC->m_pData->bRemoveHDC = FALSE;
\r
3879 inline CBitmap* FromHandle(HBITMAP hBitmap)
\r
3880 // Returns the CBitmap associated with the Bitmap handle
\r
3881 // If a CBitmap object doesn't already exist, a temporary CBitmap object is created.
\r
3882 // The HBITMAP belonging to a temporary CBitmap is not released or destroyed
\r
3883 // when the temporary CBitmap is deconstructed.
\r
3885 assert( GetApp() );
\r
3886 CBitmap* pBitmap = (CBitmap*)GetApp()->GetCGDIObjectFromMap(hBitmap);
\r
3887 if (hBitmap != 0 && pBitmap == 0)
\r
3889 pBitmap = new CBitmap;
\r
3890 GetApp()->AddTmpGDI(pBitmap);
\r
3891 pBitmap->m_pData->hGDIObject = hBitmap;
\r
3892 pBitmap->m_pData->bRemoveObject = FALSE;
\r
3897 inline CBrush* FromHandle(HBRUSH hBrush)
\r
3898 // Returns the CBrush associated with the Brush handle
\r
3899 // If a CBrush object doesn't already exist, a temporary CBrush object is created.
\r
3900 // The HBRUSH belonging to a temporary CBrush is not released or destroyed
\r
3901 // when the temporary CBrush is deconstructed.
\r
3903 assert( GetApp() );
\r
3904 CBrush* pBrush = (CBrush*)GetApp()->GetCGDIObjectFromMap(hBrush);
\r
3905 if (hBrush != 0 && pBrush == 0)
\r
3907 pBrush = new CBrush;
\r
3908 GetApp()->AddTmpGDI(pBrush);
\r
3909 pBrush->m_pData->hGDIObject = hBrush;
\r
3910 pBrush->m_pData->bRemoveObject = FALSE;
\r
3915 inline CFont* FromHandle(HFONT hFont)
\r
3916 // Returns the CFont associated with the Font handle
\r
3917 // If a CFont object doesn't already exist, a temporary CFont object is created.
\r
3918 // The HFONT belonging to a temporary CFont is not released or destroyed
\r
3919 // when the temporary CFont is deconstructed.
\r
3921 assert( GetApp() );
\r
3922 CFont* pFont = (CFont*)GetApp()->GetCGDIObjectFromMap(hFont);
\r
3923 if (hFont != 0 && pFont == 0)
\r
3925 pFont = new CFont;
\r
3926 GetApp()->AddTmpGDI(pFont);
\r
3927 pFont->m_pData->hGDIObject = hFont;
\r
3928 pFont->m_pData->bRemoveObject = FALSE;
\r
3933 inline CPalette* FromHandle(HPALETTE hPalette)
\r
3934 // Returns the CPalette associated with the palette handle
\r
3935 // If a CPalette object doesn't already exist, a temporary CPalette object is created.
\r
3936 // The HPALETTE belonging to a temporary CPalette is not released or destroyed
\r
3937 // when the temporary CPalette is deconstructed.
\r
3939 assert( GetApp() );
\r
3940 CPalette* pPalette = (CPalette*)GetApp()->GetCGDIObjectFromMap(hPalette);
\r
3941 if (hPalette != 0 && pPalette == 0)
\r
3943 pPalette = new CPalette;
\r
3944 GetApp()->AddTmpGDI(pPalette);
\r
3945 pPalette->m_pData->hGDIObject = hPalette;
\r
3946 pPalette->m_pData->bRemoveObject = FALSE;
\r
3951 inline CPen* FromHandle(HPEN hPen)
\r
3952 // Returns the CPen associated with the HPEN.
\r
3953 // If a CPen object doesn't already exist, a temporary CPen object is created.
\r
3954 // The HPEN belonging to a temporary CPen is not released or destroyed
\r
3955 // when the temporary CPen is deconstructed.
\r
3957 assert( GetApp() );
\r
3958 CPen* pPen = (CPen*)GetApp()->GetCGDIObjectFromMap(hPen);
\r
3959 if (hPen != 0 && pPen == 0)
\r
3962 GetApp()->AddTmpGDI(pPen);
\r
3963 pPen->m_pData->hGDIObject = hPen;
\r
3964 pPen->m_pData->bRemoveObject = FALSE;
\r
3969 inline CRgn* FromHandle(HRGN hRgn)
\r
3970 // Returns the CRgn associated with the HRGN.
\r
3971 // If a CRgn object doesn't already exist, a temporary CRgn object is created.
\r
3972 // The HRGN belonging to a temporary CRgn is not released or destroyed
\r
3973 // when the temporary CRgn is deconstructed.
\r
3975 assert( GetApp() );
\r
3976 CRgn* pRgn = (CRgn*)GetApp()->GetCGDIObjectFromMap(hRgn);
\r
3977 if (hRgn != 0 && pRgn == 0)
\r
3980 GetApp()->AddTmpGDI(pRgn);
\r
3981 pRgn->m_pData->hGDIObject = hRgn;
\r
3982 pRgn->m_pData->bRemoveObject = FALSE;
\r
3989 } // namespace Win32xx
\r
3991 #endif // _WIN32XX_GDI_H_
\r