Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / include / gdi.h
1 // Win32++   Version 7.3\r
2 // Released: 30th November 2011\r
3 //\r
4 //      David Nash\r
5 //      email: [email protected]\r
6 //      url: https://sourceforge.net/projects/win32-framework\r
7 //\r
8 //\r
9 // Copyright (c) 2005-2011  David Nash\r
10 //\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
20 //\r
21 // The above copyright notice and this permission notice\r
22 // shall be included in all copies or substantial portions\r
23 // of the Software.\r
24 //\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
34 //\r
35 ////////////////////////////////////////////////////////\r
36 \r
37 \r
38 ////////////////////////////////////////////////////////\r
39 // gdi.h\r
40 //  Declaration of the CDC class, and CBitmapInfoPtr class\r
41 \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
47 //  exception.\r
48 //\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
55 //  shown below.\r
56 //\r
57 // Coding Exampe without CDC ...\r
58 //  void DrawLine()\r
59 //  {\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
75 //  }\r
76 //\r
77 // Coding Example with CDC classes ...\r
78 //  void DrawLine()\r
79 //  {\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
87 //  }\r
88 //\r
89 // Coding Example with CDC classes and CPen ...\r
90 //  void DrawLine()\r
91 //  {\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
100 //  }\r
101 \r
102 // Notes:\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
119 \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
126 //\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
131 \r
132 #ifndef _WIN32XX_GDI_H_\r
133 #define _WIN32XX_GDI_H_\r
134 \r
135 #include "wincore.h"\r
136 \r
137 // Disable macros from Windowsx.h\r
138 #undef CopyRgn\r
139 \r
140 namespace Win32xx\r
141 {\r
142 \r
143         /////////////////////////////////////////////////////////////////\r
144         // Declarations for some global functions in the Win32xx namespace\r
145         //\r
146 #ifndef _WIN32_WCE\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
150 #endif\r
151 \r
152         ///////////////////////////////////////////////\r
153         // Declarations for the CGDIObject class\r
154         //\r
155         class CGDIObject\r
156         {\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
164 \r
165         public:\r
166                 struct DataMembers      // A structure that contains the data members for CGDIObject\r
167                 {\r
168                         HGDIOBJ hGDIObject;\r
169                         long    Count;\r
170                         BOOL    bRemoveObject;\r
171                 };\r
172                 CGDIObject();\r
173                 CGDIObject(const CGDIObject& rhs);\r
174                 virtual ~CGDIObject();\r
175                 CGDIObject& operator = ( const CGDIObject& rhs );\r
176                 void operator = (HGDIOBJ hObject);\r
177 \r
178                 void    Attach(HGDIOBJ hObject);\r
179                 void    DeleteObject();\r
180                 HGDIOBJ Detach();\r
181                 HGDIOBJ GetHandle() const;\r
182                 int             GetObject(int nCount, LPVOID pObject) const;\r
183 \r
184         protected:\r
185                 DataMembers* m_pData;\r
186 \r
187         private:\r
188                 void    AddToMap();\r
189                 BOOL    RemoveFromMap();\r
190                 void    Release();      \r
191         };\r
192 \r
193 \r
194         ///////////////////////////////////////////////\r
195         // Declarations for the CBitmap class\r
196         //\r
197         class CBitmap : public CGDIObject\r
198         {\r
199           public:\r
200                 CBitmap();\r
201                 CBitmap(HBITMAP hBitmap);\r
202                 CBitmap(LPCTSTR lpstr);\r
203                 CBitmap(int nID);\r
204                 operator HBITMAP() const;\r
205                 ~CBitmap();\r
206 \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
216 \r
217 #ifndef _WIN32_WCE\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
226 \r
227                 // Attributes\r
228                 BITMAP GetBitmapData() const;\r
229         };\r
230 \r
231 \r
232         ///////////////////////////////////////////////\r
233         // Declarations for the CBrush class\r
234         //\r
235         class CBrush : public CGDIObject\r
236         {\r
237           public:\r
238                 CBrush();\r
239                 CBrush(HBRUSH hBrush);\r
240                 CBrush(COLORREF crColor);\r
241                 operator HBRUSH() const;\r
242                 ~CBrush();\r
243 \r
244                 HBRUSH CreateSolidBrush(COLORREF crColor);\r
245                 HBRUSH CreatePatternBrush(CBitmap* pBitmap);\r
246                 LOGBRUSH GetLogBrush() const;\r
247 \r
248 #ifndef _WIN32_WCE\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
254 \r
255         };\r
256 \r
257 \r
258         ///////////////////////////////////////////////\r
259         // Declarations for the CFont class\r
260         //\r
261         class CFont : public CGDIObject\r
262         {\r
263         public:\r
264                 CFont();\r
265                 CFont(HFONT hFont);\r
266                 CFont(const LOGFONT* lpLogFont);\r
267                 operator HFONT() const;\r
268                 ~CFont();\r
269 \r
270                 // Create methods\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
274 \r
275 #ifndef _WIN32_WCE\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
282 \r
283                 // Attributes\r
284                 LOGFONT GetLogFont() const;\r
285         };\r
286 \r
287 \r
288         ///////////////////////////////////////////////\r
289         // Declarations for the CPalette class\r
290         //\r
291         class CPalette : public CGDIObject\r
292         {\r
293           public:\r
294                 CPalette();\r
295                 CPalette(HPALETTE hPalette);\r
296                 operator HPALETTE() const;\r
297                 ~CPalette();\r
298 \r
299                 // Create methods\r
300                 HPALETTE CreatePalette(LPLOGPALETTE lpLogPalette);\r
301 \r
302 #ifndef _WIN32_WCE\r
303                 HPALETTE CreateHalftonePalette(CDC* pDC);\r
304 #endif // !_WIN32_WCE\r
305 \r
306                 // Attributes\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
310 \r
311                 // Operations\r
312 #ifndef _WIN32_WCE\r
313                 BOOL ResizePalette(UINT nNumEntries);\r
314                 void AnimatePalette(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors);\r
315 #endif // !_WIN32_WCE\r
316 \r
317                 UINT GetNearestPaletteIndex (COLORREF crColor) const;\r
318 \r
319         };\r
320 \r
321 \r
322         ///////////////////////////////////////////////\r
323         // Declarations for the CPen class\r
324         //\r
325         class CPen : public CGDIObject\r
326         {\r
327         public:\r
328                 CPen();\r
329                 CPen(HPEN hPen);\r
330                 CPen(int nPenStyle, int nWidth, COLORREF crColor);\r
331 #ifndef _WIN32_WCE\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
335                 ~CPen();\r
336 \r
337                 HPEN CreatePen(int nPenStyle, int nWidth, COLORREF crColor);\r
338                 HPEN CreatePenIndirect(LPLOGPEN lpLogPen);\r
339                 LOGPEN GetLogPen() const;\r
340 \r
341 #ifndef _WIN32_WCE\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
345 \r
346         };\r
347 \r
348 \r
349         ///////////////////////////////////////////////\r
350         // Declarations for the CRgn class\r
351         //\r
352         class CRgn : public CGDIObject\r
353         {\r
354           public:\r
355                 CRgn();\r
356                 CRgn(HRGN hRgn);\r
357                 operator HRGN() const;\r
358                 ~CRgn ();\r
359 \r
360                 // Create methods\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
364 \r
365 #ifndef _WIN32_WCE\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
373 \r
374                 // Operations\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
388         };\r
389 \r
390 \r
391         ///////////////////////////////////////////////\r
392         // Declarations for the CDC class\r
393         //\r
394         class CDC\r
395         {\r
396                 friend class CWinApp;\r
397                 friend class CWnd;\r
398                 friend CDC* FromHandle(HDC hDC);\r
399 \r
400         public:\r
401                 struct DataMembers      // A structure that contains the data members for CDC\r
402                 {\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
409                 };\r
410 \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
414                 virtual ~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
417 \r
418                 void Attach(HDC hDC, HWND hWnd = 0);\r
419                 void Destroy();\r
420                 HDC  Detach();\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
428 \r
429 #ifndef _WIN32_WCE\r
430                 void operator = (const HDC hDC);\r
431 #endif\r
432 \r
433                 // Initialization\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
437 #ifndef _WIN32_WCE\r
438                 BOOL CreateIC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData);\r
439 #endif\r
440 \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
446 \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
454 \r
455 #ifndef _WIN32_WCE\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
460 #endif\r
461 \r
462                 // Create and Select Brushes\r
463                 void CreatePatternBrush(CBitmap* pBitmap);\r
464                 void CreateSolidBrush(COLORREF rbg);\r
465                 LOGBRUSH GetLogBrush() const;\r
466 \r
467 #ifndef _WIN32_WCE\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
472 #endif\r
473 \r
474                 // Create and Select Fonts\r
475                 void CreateFontIndirect(LPLOGFONT plf);\r
476                 LOGFONT GetLogFont() const;\r
477 \r
478 #ifndef _WIN32_WCE\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
483 #endif\r
484 \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
489 \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
494 #ifndef _WIN32_WCE\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
499 #endif\r
500 \r
501                 // Wrappers for WinAPI functions\r
502 \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
513 #ifndef _WIN32_WCE\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
529 #endif\r
530 \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
540 \r
541 #ifndef _WIN32_WCE\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
547 #endif\r
548 \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
558 \r
559 #ifndef _WIN32_WCE\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
564 #endif\r
565 \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
573 \r
574 #ifndef _WIN32_WCE\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
581 #endif\r
582 \r
583                 // Brush Functions\r
584 #ifdef GetDCBrushColor\r
585                 COLORREF GetDCBrushColor() const;\r
586                 COLORREF SetDCBrushColor(COLORREF crColor) const;\r
587 #endif\r
588 \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
598 \r
599 #ifndef _WIN32_WCE\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
603 #endif\r
604 \r
605         // Co-ordinate Functions\r
606 #ifndef _WIN32_WCE\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
611 #endif\r
612 \r
613                 // Layout Functions\r
614                 DWORD GetLayout() const;\r
615                 DWORD SetLayout(DWORD dwLayout) const;\r
616 \r
617                 // Mapping functions\r
618 #ifndef _WIN32_WCE\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
638 #endif\r
639 \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
647 \r
648                 // Text Functions\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
661 \r
662 #ifndef _WIN32_WCE\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
672 #endif\r
673 \r
674         private:\r
675                 void AddToMap();\r
676                 static CDC* AddTempHDC(HDC hDC, HWND hWnd);\r
677                 void Release();\r
678                 BOOL RemoveFromMap();\r
679 \r
680                 DataMembers* m_pData;           // pointer to the class's data members\r
681         };\r
682 \r
683         class CClientDC : public CDC\r
684         {\r
685         public:\r
686                 CClientDC(const CWnd* pWnd)\r
687                 {\r
688                         if (pWnd) assert(pWnd->IsWindow());\r
689                         HWND hWnd = pWnd? pWnd->GetHwnd() : GetDesktopWindow();\r
690                         Attach(::GetDC(hWnd), hWnd);\r
691                 }\r
692                 virtual ~CClientDC() {}\r
693         };\r
694 \r
695         class CMemDC : public CDC\r
696         {\r
697         public:\r
698                 CMemDC(const CDC* pDC)\r
699                 {\r
700                         if (pDC) assert(pDC->GetHDC());\r
701                         HDC hDC = pDC? pDC->GetHDC() : NULL;\r
702                         Attach(::CreateCompatibleDC(hDC));\r
703                 }\r
704                 virtual ~CMemDC() {}\r
705         };\r
706 \r
707         class CPaintDC : public CDC\r
708         {\r
709         public:\r
710                 CPaintDC(const CWnd* pWnd)\r
711                 {\r
712                         assert(pWnd->IsWindow());\r
713                         m_hWnd = pWnd->GetHwnd();\r
714                         Attach(::BeginPaint(pWnd->GetHwnd(), &m_ps), m_hWnd);\r
715                 }\r
716 \r
717                 virtual ~CPaintDC()     { ::EndPaint(m_hWnd, &m_ps); }\r
718 \r
719         private:\r
720                 HWND m_hWnd;\r
721                 PAINTSTRUCT m_ps;\r
722         };\r
723 \r
724         class CWindowDC : public CDC\r
725         {\r
726         public:\r
727                 CWindowDC(const CWnd* pWnd)\r
728                 {\r
729                         if (pWnd) assert(pWnd->IsWindow());\r
730                         HWND hWnd = pWnd? pWnd->GetHwnd() : GetDesktopWindow();\r
731                         Attach(::GetWindowDC(hWnd), hWnd);\r
732                 }\r
733                 virtual ~CWindowDC() {}\r
734         };\r
735 \r
736 #ifndef _WIN32_WCE\r
737         class CMetaFileDC : public CDC\r
738         {\r
739         public:\r
740                 CMetaFileDC() : m_hMF(0), m_hEMF(0) {}\r
741                 virtual ~CMetaFileDC()\r
742                 {\r
743                         if (m_hMF)\r
744                         {\r
745                                 ::CloseMetaFile(GetHDC());\r
746                                 ::DeleteMetaFile(m_hMF);\r
747                         }\r
748                         if (m_hEMF)\r
749                         {\r
750                                 ::CloseEnhMetaFile(GetHDC());\r
751                                 ::DeleteEnhMetaFile(m_hEMF);\r
752                         }\r
753                 }\r
754                 void Create(LPCTSTR lpszFilename = NULL) { Attach(::CreateMetaFile(lpszFilename)); }\r
755                 void CreateEnhanced(CDC* pDCRef, LPCTSTR lpszFileName, LPCRECT lpBounds, LPCTSTR lpszDescription)\r
756                 {\r
757                         HDC hDC = pDCRef? pDCRef->GetHDC() : NULL;\r
758                         ::CreateEnhMetaFile(hDC, lpszFileName, lpBounds, lpszDescription);\r
759                         assert(GetHDC());\r
760                 }\r
761                 HMETAFILE Close() {     return ::CloseMetaFile(GetHDC()); }\r
762                 HENHMETAFILE CloseEnhanced() { return ::CloseEnhMetaFile(GetHDC()); }\r
763 \r
764         private:\r
765                 HMETAFILE m_hMF;\r
766                 HENHMETAFILE m_hEMF;\r
767         };\r
768 #endif\r
769 \r
770 \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
775         {\r
776         public:\r
777                 CBitmapInfoPtr(CBitmap* pBitmap)\r
778                 {\r
779                         BITMAP bmSource = pBitmap->GetBitmapData();\r
780 \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
789 \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
794 \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
801                         if (cClrBits < 24)\r
802                                 m_pbmiArray->bmiHeader.biClrUsed = (1<<cClrBits);\r
803                 }\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
807 \r
808         private:\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
813         };\r
814 \r
815 \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
822 \r
823 }\r
824 \r
825 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
826 \r
827 \r
828 namespace Win32xx\r
829 {\r
830 \r
831         ///////////////////////////////////////////////\r
832         // Declarations for the CGDIObject class\r
833         //\r
834 \r
835         inline CGDIObject::CGDIObject()\r
836         // Constructs the CGDIObject\r
837         {\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
842         }\r
843 \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
847         {\r
848                 m_pData = rhs.m_pData;\r
849                 InterlockedIncrement(&m_pData->Count);\r
850         }\r
851 \r
852         inline CGDIObject::~CGDIObject()\r
853         // Deconstructs the CGDIObject\r
854         {\r
855                 Release();\r
856         }\r
857 \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
861         {\r
862                 if (this != &rhs)\r
863                 {\r
864                         InterlockedIncrement(&rhs.m_pData->Count);\r
865                         Release();\r
866                         m_pData = rhs.m_pData;\r
867                 }\r
868 \r
869                 return *this;\r
870         }\r
871 \r
872         inline void CGDIObject::operator = (HGDIOBJ hObject)\r
873         {\r
874                 assert(m_pData);\r
875                 assert (m_pData->hGDIObject == NULL);\r
876                 m_pData->hGDIObject = hObject;\r
877         }\r
878 \r
879         inline void CGDIObject::AddToMap()\r
880         // Store the HDC and CDC pointer in the HDC map\r
881         {\r
882                 assert( GetApp() );\r
883                 GetApp()->m_csMapLock.Lock();\r
884 \r
885                 assert(m_pData->hGDIObject);\r
886                 assert(!GetApp()->GetCGDIObjectFromMap(m_pData->hGDIObject));\r
887 \r
888                 GetApp()->m_mapGDI.insert(std::make_pair(m_pData->hGDIObject, this));\r
889                 GetApp()->m_csMapLock.Release();\r
890         }\r
891 \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
895         {\r
896                 assert(m_pData);\r
897 \r
898                 if (m_pData->hGDIObject != NULL && m_pData->hGDIObject != hObject)\r
899                 {\r
900                         ::DeleteObject(Detach());\r
901                 }\r
902 \r
903                 CGDIObject* pObject = GetApp()->GetCGDIObjectFromMap(hObject);\r
904                 if (pObject)\r
905                 {\r
906                         delete m_pData;\r
907                         m_pData = pObject->m_pData;\r
908                         InterlockedIncrement(&m_pData->Count);\r
909                 }\r
910                 else\r
911                 {\r
912                         m_pData->hGDIObject = hObject;\r
913                         AddToMap();\r
914                 }\r
915         }\r
916 \r
917         inline void CGDIObject::DeleteObject()\r
918         {\r
919                 assert(m_pData);\r
920 \r
921                 if (m_pData->hGDIObject)\r
922                 {\r
923                         ::DeleteObject(Detach());\r
924                 }\r
925         }\r
926 \r
927         inline HGDIOBJ CGDIObject::Detach()\r
928         // Detaches the HGDIOBJ from this object.\r
929         {\r
930                 assert(m_pData);\r
931                 assert(m_pData->hGDIObject);\r
932 \r
933                 GetApp()->m_csMapLock.Lock();\r
934                 RemoveFromMap();\r
935                 HGDIOBJ hObject = m_pData->hGDIObject;\r
936                 m_pData->hGDIObject = 0;\r
937 \r
938                 if (m_pData->Count)\r
939                 {\r
940                         if (InterlockedDecrement(&m_pData->Count) == 0)\r
941                         {\r
942                                 delete m_pData;\r
943                         }\r
944                 }\r
945 \r
946                 GetApp()->m_csMapLock.Release();\r
947 \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
953 \r
954                 return hObject;\r
955         }\r
956 \r
957         inline HGDIOBJ CGDIObject::GetHandle() const\r
958         {\r
959                 assert(m_pData);\r
960                 return m_pData->hGDIObject;\r
961         }\r
962 \r
963         inline int CGDIObject::GetObject(int nCount, LPVOID pObject) const\r
964         {\r
965                 assert(m_pData);\r
966                 return ::GetObject(m_pData->hGDIObject, nCount, pObject);\r
967         }\r
968 \r
969         inline void CGDIObject::Release()\r
970         {\r
971                 assert(m_pData);\r
972                 BOOL bSucceeded = TRUE;\r
973 \r
974                 if (InterlockedDecrement(&m_pData->Count) == 0)\r
975                 {\r
976                         if (m_pData->hGDIObject != NULL)\r
977                         {\r
978                                 if (m_pData->bRemoveObject)\r
979                                         bSucceeded = ::DeleteObject(m_pData->hGDIObject);\r
980                                 else\r
981                                         bSucceeded = TRUE;\r
982                         }\r
983 \r
984                         RemoveFromMap();\r
985                         delete m_pData;\r
986                         m_pData = 0;\r
987                 }\r
988 \r
989                 assert(bSucceeded);\r
990         }\r
991 \r
992         inline BOOL CGDIObject::RemoveFromMap()\r
993         {\r
994                 BOOL Success = FALSE;\r
995 \r
996                 if( GetApp() )\r
997                 {\r
998                         // Allocate an iterator for our HDC map\r
999                         std::map<HGDIOBJ, CGDIObject*, CompareGDI>::iterator m;\r
1000 \r
1001                         CWinApp* pApp = GetApp();\r
1002                         if (pApp)\r
1003                         {\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
1008                                 {\r
1009                                         pApp->m_mapGDI.erase(m);\r
1010                                         Success = TRUE;\r
1011                                 }\r
1012 \r
1013                                 pApp->m_csMapLock.Release();\r
1014                         }\r
1015                 }\r
1016 \r
1017                 return Success;\r
1018         }\r
1019 \r
1020 \r
1021         ///////////////////////////////////////////////\r
1022         // Declarations for the CBitmap class\r
1023         //\r
1024         inline CBitmap::CBitmap()\r
1025         {\r
1026         }\r
1027 \r
1028         inline CBitmap::CBitmap(HBITMAP hBitmap)\r
1029         {\r
1030                 assert(m_pData);\r
1031                 Attach(hBitmap);\r
1032         }\r
1033 \r
1034         inline CBitmap::CBitmap(LPCTSTR lpszName)\r
1035         {\r
1036                 LoadBitmap(lpszName);\r
1037         }\r
1038 \r
1039         inline CBitmap::CBitmap(int nID)\r
1040         {\r
1041                 LoadBitmap(nID);\r
1042         }\r
1043 \r
1044         inline CBitmap::operator HBITMAP() const\r
1045         {\r
1046                 assert(m_pData);\r
1047                 return (HBITMAP)m_pData->hGDIObject;\r
1048         }\r
1049 \r
1050         inline CBitmap::~CBitmap()\r
1051         {\r
1052         }\r
1053 \r
1054         inline BOOL CBitmap::LoadBitmap(int nID)\r
1055         // Loads a bitmap from a resource using the resource ID.\r
1056         {\r
1057                 return LoadBitmap(MAKEINTRESOURCE(nID));\r
1058         }\r
1059 \r
1060         inline BOOL CBitmap::LoadBitmap(LPCTSTR lpszName)\r
1061         // Loads a bitmap from a resource using the resource string.\r
1062         {\r
1063                 assert(GetApp());\r
1064                 assert(m_pData);\r
1065 \r
1066                 HBITMAP hBitmap = (HBITMAP)::LoadImage(GetApp()->GetResourceHandle(), lpszName, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);\r
1067                 if (hBitmap)\r
1068                 {\r
1069                         Attach(hBitmap);\r
1070                 }\r
1071                 return (0 != hBitmap);  // boolean expression\r
1072         }\r
1073 \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
1076         {\r
1077                 return LoadImage(MAKEINTRESOURCE(nID), cxDesired, cyDesired, fuLoad);\r
1078         }\r
1079 \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
1082         {\r
1083                 assert(GetApp());\r
1084                 assert(m_pData);\r
1085 \r
1086                 HBITMAP hBitmap = (HBITMAP)::LoadImage(GetApp()->GetResourceHandle(), lpszName, IMAGE_BITMAP, cxDesired, cyDesired, fuLoad);\r
1087                 if (hBitmap)\r
1088                 {\r
1089                         Attach(hBitmap);\r
1090                 }\r
1091                 return (0 != hBitmap);  // boolean expression\r
1092         }\r
1093 \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
1101         {\r
1102                 assert(m_pData);\r
1103 \r
1104                 HBITMAP hBitmap = ::LoadBitmap(NULL, MAKEINTRESOURCE(nIDBitmap));\r
1105                 if (hBitmap)\r
1106                 {\r
1107                         Attach( ::LoadBitmap(NULL, MAKEINTRESOURCE(nIDBitmap)) );\r
1108                 }\r
1109                 return (0 != hBitmap);  // boolean expression\r
1110         }\r
1111 \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
1115                 {\r
1116                         assert(GetApp());\r
1117                         assert(m_pData);\r
1118                         HBITMAP hBitmap = ::CreateMappedBitmap(GetApp()->GetResourceHandle(), nIDBitmap, (WORD)nFlags, lpColorMap, nMapSize);\r
1119                         Attach(hBitmap);\r
1120                         return hBitmap;\r
1121                 }\r
1122 #endif // !_WIN32_WCE\r
1123 \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
1126                 {\r
1127                         assert(m_pData);\r
1128                         HBITMAP hBitmap = ::CreateBitmap(nWidth, nHeight, nPlanes, nBitsPerPixel, lpBits);\r
1129                         Attach(hBitmap);\r
1130                         return hBitmap;\r
1131                 }\r
1132 \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
1136                 {\r
1137                         assert(m_pData);\r
1138                         HBITMAP hBitmap = ::CreateBitmapIndirect(lpBitmap);\r
1139                         Attach(hBitmap);\r
1140                         return hBitmap;\r
1141                 }\r
1142 #endif // !_WIN32_WCE\r
1143 \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
1146                 {\r
1147                         assert(m_pData);\r
1148                         assert(pDC);\r
1149                         HBITMAP hBitmap = ::CreateCompatibleBitmap(pDC->GetHDC(), nWidth, nHeight);\r
1150                         Attach(hBitmap);\r
1151                         return hBitmap;\r
1152                 }\r
1153 \r
1154                 // Attributes\r
1155                 inline BITMAP CBitmap::GetBitmapData() const\r
1156                 // Retrieves the BITMAP structure\r
1157                 {\r
1158                         assert(m_pData);\r
1159                         assert(m_pData->hGDIObject != NULL);\r
1160                         BITMAP bmp = {0};\r
1161                         ::GetObject(m_pData->hGDIObject, sizeof(BITMAP), &bmp);\r
1162                         return bmp;\r
1163                 }\r
1164 \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
1169                 {\r
1170                         assert(m_pData);\r
1171                         assert(m_pData->hGDIObject != NULL);\r
1172                         CSize Size;\r
1173                         ::GetBitmapDimensionEx((HBITMAP)m_pData->hGDIObject, &Size);\r
1174                         return Size;\r
1175                 }\r
1176 \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
1180                 {\r
1181                         assert(m_pData);\r
1182                         assert(m_pData->hGDIObject != NULL);\r
1183                         CSize Size;\r
1184                         ::SetBitmapDimensionEx((HBITMAP)m_pData->hGDIObject, nWidth, nHeight, Size);\r
1185                         return Size;\r
1186                 }\r
1187 \r
1188                 // DIB support\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
1191                 {\r
1192                         assert(m_pData);\r
1193                         assert(pDC);\r
1194                         HBITMAP hBitmap = ::CreateDIBitmap(pDC->GetHDC(), lpbmih, dwInit, lpbInit, lpbmi, uColorUse);\r
1195                         Attach(hBitmap);\r
1196                         return hBitmap;\r
1197                 }\r
1198 #endif // !_WIN32_WCE\r
1199 \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
1203                 {\r
1204                         assert(m_pData);\r
1205                         assert(pDC);\r
1206                         HBITMAP hBitmap = ::CreateDIBSection(pDC->GetHDC(), lpbmi, uColorUse, ppvBits, hSection, dwOffset);\r
1207                         Attach(hBitmap);\r
1208                         return hBitmap;\r
1209                 }\r
1210 \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
1214                 {\r
1215                         assert(m_pData);\r
1216                         assert(pDC);\r
1217                         assert(m_pData->hGDIObject != NULL);\r
1218                         return ::GetDIBits(pDC->GetHDC(), (HBITMAP)m_pData->hGDIObject, uStartScan, cScanLines,  lpvBits, lpbmi, uColorUse);\r
1219                 }\r
1220 \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
1223                 {\r
1224                         assert(m_pData);\r
1225                         assert(pDC);\r
1226                         assert(m_pData->hGDIObject != NULL);\r
1227                         return ::SetDIBits(pDC->GetHDC(), (HBITMAP)m_pData->hGDIObject, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);\r
1228                 }\r
1229 #endif // !_WIN32_WCE\r
1230 \r
1231 \r
1232         ///////////////////////////////////////////////\r
1233         // Definitions of the CBrush class\r
1234         //\r
1235         inline CBrush::CBrush()\r
1236         {\r
1237         }\r
1238 \r
1239         inline CBrush::CBrush(HBRUSH hBrush)\r
1240         {\r
1241                 assert(m_pData);\r
1242                 Attach(hBrush);\r
1243         }\r
1244 \r
1245         inline CBrush::CBrush(COLORREF crColor)\r
1246         {\r
1247                 Attach( ::CreateSolidBrush(crColor) );\r
1248                 assert (m_pData->hGDIObject);\r
1249         }\r
1250 \r
1251         inline CBrush::operator HBRUSH() const\r
1252         {\r
1253                 assert(m_pData);\r
1254                 return (HBRUSH)m_pData->hGDIObject;\r
1255         }\r
1256 \r
1257         inline CBrush::~CBrush()\r
1258         {\r
1259         }\r
1260 \r
1261         inline HBRUSH CBrush::CreateSolidBrush(COLORREF crColor)\r
1262         // Creates a logical brush that has the specified solid color.\r
1263         {\r
1264                 assert(m_pData);\r
1265                 HBRUSH hBrush = ::CreateSolidBrush(crColor);\r
1266                 Attach(hBrush);\r
1267                 return hBrush;\r
1268         }\r
1269 \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
1273         {\r
1274                 assert(m_pData);\r
1275                 HBRUSH hBrush = ::CreateHatchBrush(nIndex, crColor);\r
1276                 Attach(hBrush);\r
1277                 return hBrush;\r
1278         }\r
1279 \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
1282         {\r
1283                 assert(m_pData);\r
1284                 HBRUSH hBrush = ::CreateBrushIndirect(lpLogBrush);\r
1285                 Attach(hBrush);\r
1286                 return hBrush;\r
1287         }\r
1288 \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
1291         {\r
1292                 assert(m_pData);\r
1293                 HBRUSH hBrush = ::CreateDIBPatternBrush(hglbDIBPacked, fuColorSpec);\r
1294                 Attach(hBrush);\r
1295                 return hBrush;\r
1296         }\r
1297 \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
1300         {\r
1301                 assert(m_pData);\r
1302                 HBRUSH hBrush = ::CreateDIBPatternBrushPt(lpPackedDIB, nUsage);\r
1303                 Attach(hBrush);\r
1304                 return hBrush;\r
1305         }\r
1306 \r
1307 #endif // !defined(_WIN32_WCE)\r
1308 \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
1312         {\r
1313                 assert(m_pData);\r
1314                 assert(pBitmap);\r
1315                 HBRUSH hBrush = ::CreatePatternBrush(*pBitmap);\r
1316                 Attach(hBrush);\r
1317                 return hBrush;\r
1318         }\r
1319 \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
1322         {\r
1323                 assert(m_pData);\r
1324                 assert(m_pData->hGDIObject != NULL);\r
1325                 LOGBRUSH LogBrush = {0};\r
1326                 ::GetObject (m_pData->hGDIObject, sizeof(LOGBRUSH), &LogBrush);\r
1327                 return LogBrush;\r
1328         }\r
1329 \r
1330 \r
1331         ///////////////////////////////////////////////\r
1332         // Definitions of the CFont class\r
1333         //\r
1334         inline CFont::CFont()\r
1335         {\r
1336         }\r
1337 \r
1338         inline CFont::CFont(HFONT hFont)\r
1339         {\r
1340                 assert(m_pData);\r
1341                 Attach(hFont);\r
1342         }\r
1343 \r
1344         inline CFont::CFont(const LOGFONT* lpLogFont)\r
1345         {\r
1346                 assert(m_pData);\r
1347                 Attach( ::CreateFontIndirect(lpLogFont) );\r
1348         }\r
1349 \r
1350         inline CFont::operator HFONT() const\r
1351         {\r
1352                 assert(m_pData);\r
1353                 return (HFONT)m_pData->hGDIObject;\r
1354         }\r
1355 \r
1356         inline CFont::~CFont()\r
1357         {\r
1358         }\r
1359 \r
1360         inline HFONT CFont::CreateFontIndirect(const LOGFONT* lpLogFont)\r
1361         // Creates a logical font that has the specified characteristics.\r
1362         {\r
1363                 assert(m_pData);\r
1364                 HFONT hFont = ::CreateFontIndirect(lpLogFont);\r
1365                 Attach(hFont);\r
1366                 return hFont;\r
1367         }\r
1368 \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
1371         {\r
1372                 LOGFONT logFont = { 0 };\r
1373                 logFont.lfCharSet = DEFAULT_CHARSET;\r
1374                 logFont.lfHeight = nPointSize;\r
1375 \r
1376                 lstrcpy(logFont.lfFaceName, lpszFaceName);\r
1377 \r
1378                 if (bBold)\r
1379                         logFont.lfWeight = FW_BOLD;\r
1380                 if (bItalic)\r
1381                         logFont.lfItalic = (BYTE)TRUE;\r
1382 \r
1383                 return CreatePointFontIndirect(&logFont, pDC);\r
1384         }\r
1385 \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
1389         {\r
1390                 HDC hDC = pDC? pDC->GetHDC() : NULL;\r
1391                 HDC hDC1 = (hDC != NULL) ? hDC : ::GetDC(HWND_DESKTOP);\r
1392 \r
1393                 // convert nPointSize to logical units based on hDC\r
1394                 LOGFONT logFont = *lpLogFont;\r
1395 \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
1400 \r
1401                 POINT ptOrg = { 0, 0 };\r
1402                 ::DPtoLP(hDC1, &ptOrg, 1);\r
1403 \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
1409 \r
1410                 if (hDC == NULL)\r
1411                         ::ReleaseDC (NULL, hDC1);\r
1412 \r
1413                 return CreateFontIndirect (&logFont);\r
1414         }\r
1415 \r
1416 #ifndef _WIN32_WCE\r
1417 \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
1424         {\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
1429 \r
1430                 Attach(hFont);\r
1431                 return hFont;\r
1432         }\r
1433 #endif // #ifndef _WIN32_WCE\r
1434 \r
1435         inline LOGFONT CFont::GetLogFont() const\r
1436         // Retrieves the Logfont structure that contains font attributes.\r
1437         {\r
1438                 assert(m_pData);\r
1439                 assert(m_pData->hGDIObject != NULL);\r
1440                 LOGFONT LogFont = {0};\r
1441                 ::GetObject(m_pData->hGDIObject, sizeof(LOGFONT), &LogFont);\r
1442                 return LogFont;\r
1443         }\r
1444 \r
1445 \r
1446         ///////////////////////////////////////////////\r
1447         // Definitions of the CPalette class\r
1448         //\r
1449         inline CPalette::CPalette()\r
1450         {\r
1451         }\r
1452 \r
1453         inline CPalette::CPalette(HPALETTE hPalette)\r
1454         {\r
1455                 Attach(hPalette);\r
1456         }\r
1457 \r
1458         inline CPalette::operator HPALETTE() const\r
1459         {\r
1460                 assert(m_pData);\r
1461                 return (HPALETTE)m_pData->hGDIObject;\r
1462         }\r
1463 \r
1464         inline CPalette::~CPalette ()\r
1465         {\r
1466         }\r
1467 \r
1468         inline HPALETTE CPalette::CreatePalette(LPLOGPALETTE lpLogPalette)\r
1469         // Creates a logical palette from the information in the specified LOGPALETTE structure.\r
1470         {\r
1471                 assert(m_pData);\r
1472                 HPALETTE hPalette = ::CreatePalette (lpLogPalette);\r
1473                 Attach(hPalette);\r
1474                 return hPalette;\r
1475         }\r
1476 \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
1480         {\r
1481                 assert(m_pData);\r
1482                 assert(pDC);\r
1483                 HPALETTE hPalette = ::CreateHalftonePalette(pDC->GetHDC());\r
1484                 Attach(hPalette);\r
1485                 return hPalette;\r
1486         }\r
1487 #endif // !_WIN32_WCE\r
1488 \r
1489         inline int CPalette::GetEntryCount() const\r
1490         // Retrieve the number of entries in the palette.\r
1491         {\r
1492                 assert(m_pData);\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
1497         }\r
1498 \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
1501         {\r
1502                 assert(m_pData);\r
1503                 assert(m_pData->hGDIObject != NULL);\r
1504                 return ::GetPaletteEntries((HPALETTE)m_pData->hGDIObject, nStartIndex, nNumEntries, lpPaletteColors);\r
1505         }\r
1506 \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
1509         {\r
1510                 assert(m_pData);\r
1511                 assert(m_pData->hGDIObject != NULL);\r
1512                 return ::SetPaletteEntries((HPALETTE)m_pData->hGDIObject, nStartIndex, nNumEntries, lpPaletteColors);\r
1513         }\r
1514 \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
1518         {\r
1519                 assert(m_pData);\r
1520                 assert(m_pData->hGDIObject != NULL);\r
1521                 ::AnimatePalette((HPALETTE)m_pData->hGDIObject, nStartIndex, nNumEntries, lpPaletteColors);\r
1522         }\r
1523 \r
1524         inline BOOL CPalette::ResizePalette(UINT nNumEntries)\r
1525         //  Increases or decreases the size of the palette based on the specified value.\r
1526         {\r
1527                 assert(m_pData);\r
1528                 assert(m_pData->hGDIObject != NULL);\r
1529                 return ::ResizePalette((HPALETTE)m_pData->hGDIObject, nNumEntries);\r
1530         }\r
1531 #endif // !_WIN32_WCE\r
1532 \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
1535         {\r
1536                 assert(m_pData);\r
1537                 assert(m_pData->hGDIObject != NULL);\r
1538                 return ::GetNearestPaletteIndex((HPALETTE)m_pData->hGDIObject, crColor);\r
1539         }\r
1540 \r
1541 \r
1542         ///////////////////////////////////////////////\r
1543         // Declarations for the CPen class\r
1544         //\r
1545         inline CPen::CPen()\r
1546         {\r
1547         }\r
1548 \r
1549         inline CPen::CPen(HPEN hPen)\r
1550         {\r
1551                 Attach(hPen);\r
1552         }\r
1553 \r
1554         inline CPen::CPen(int nPenStyle, int nWidth, COLORREF crColor)\r
1555         {\r
1556                 assert(m_pData);\r
1557                 Attach( ::CreatePen(nPenStyle, nWidth, crColor) );\r
1558         }\r
1559 \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
1562         {\r
1563                 assert(m_pData);\r
1564                 Attach( ::ExtCreatePen(nPenStyle, nWidth, pLogBrush, nStyleCount, lpStyle) );\r
1565         }\r
1566 #endif // !_WIN32_WCE\r
1567 \r
1568         inline CPen::operator HPEN () const\r
1569         {\r
1570                 assert(m_pData);\r
1571                 return (HPEN)m_pData->hGDIObject;\r
1572         }\r
1573 \r
1574         inline CPen::~CPen()\r
1575         {\r
1576         }\r
1577 \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
1580         {\r
1581                 assert(m_pData);\r
1582                 HPEN hPen = ::CreatePen(nPenStyle, nWidth, crColor);\r
1583                 Attach(hPen);\r
1584                 return hPen;\r
1585         }\r
1586 \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
1589         {\r
1590                 assert(m_pData);\r
1591                 HPEN hPen = ::CreatePenIndirect(lpLogPen);\r
1592                 Attach(hPen);\r
1593                 return hPen;\r
1594         }\r
1595 \r
1596         inline LOGPEN CPen::GetLogPen() const\r
1597         {\r
1598                 // Retrieves the LOGPEN struct that specifies the pen's style, width, and color.\r
1599                 assert(m_pData);\r
1600                 assert(m_pData->hGDIObject != NULL);\r
1601 \r
1602                 LOGPEN LogPen = {0};\r
1603                 ::GetObject(m_pData->hGDIObject, sizeof(LOGPEN), &LogPen);\r
1604                 return LogPen;\r
1605         }\r
1606 \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
1610         {\r
1611                 assert(m_pData);\r
1612                 HPEN hPen = ::ExtCreatePen(nPenStyle, nWidth, pLogBrush, nStyleCount, lpStyle);\r
1613                 Attach(hPen);\r
1614                 return hPen;\r
1615         }\r
1616 \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
1619         {\r
1620                 assert(m_pData);\r
1621                 assert(m_pData->hGDIObject != NULL);\r
1622 \r
1623                 EXTLOGPEN ExLogPen = {0};\r
1624                 ::GetObject(m_pData->hGDIObject, sizeof(EXTLOGPEN), &ExLogPen);\r
1625                 return ExLogPen;\r
1626         }\r
1627 #endif // !_WIN32_WCE\r
1628 \r
1629 \r
1630         ///////////////////////////////////////////////\r
1631         // Definitions of the CRgn class\r
1632         //\r
1633         inline CRgn::CRgn()\r
1634         {\r
1635         }\r
1636 \r
1637         inline CRgn::CRgn(HRGN hRgn)\r
1638         {\r
1639                 assert(m_pData);\r
1640                 Attach(hRgn);\r
1641         }\r
1642 \r
1643         inline CRgn::operator HRGN() const\r
1644         {\r
1645                 assert(m_pData);\r
1646                 return (HRGN)m_pData->hGDIObject;\r
1647         }\r
1648 \r
1649         inline CRgn::~CRgn()\r
1650         {\r
1651         }\r
1652 \r
1653         inline HRGN CRgn::CreateRectRgn(int x1, int y1, int x2, int y2)\r
1654         // Creates a rectangular region.\r
1655         {\r
1656                 assert(m_pData);\r
1657                 HRGN hRgn = ::CreateRectRgn(x1, y1, x2, y2);\r
1658                 Attach(hRgn);\r
1659                 return hRgn;\r
1660         }\r
1661 \r
1662         inline HRGN CRgn::CreateRectRgnIndirect(const RECT& rc)\r
1663         // Creates a rectangular region.\r
1664         {\r
1665                 assert(m_pData);\r
1666                 HRGN hRgn = ::CreateRectRgnIndirect(&rc);\r
1667                 Attach(hRgn);\r
1668                 return hRgn;\r
1669         }\r
1670 \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
1674         {\r
1675                 assert(m_pData);\r
1676                 HRGN hRgn = ::CreateEllipticRgn(x1, y1, x2, y2);\r
1677                 Attach(hRgn);\r
1678                 return hRgn;\r
1679         }\r
1680 \r
1681         inline HRGN CRgn::CreateEllipticRgnIndirect(const RECT& rc)\r
1682         // Creates an elliptical region.\r
1683         {\r
1684                 assert(m_pData);\r
1685                 HRGN hRgn = ::CreateEllipticRgnIndirect(&rc);\r
1686                 Attach(hRgn);\r
1687                 return hRgn;\r
1688         }\r
1689 \r
1690         inline HRGN CRgn::CreatePolygonRgn(LPPOINT lpPoints, int nCount, int nMode)\r
1691         // Creates a polygonal region.\r
1692         {\r
1693                 assert(m_pData);\r
1694                 HRGN hRgn = ::CreatePolygonRgn(lpPoints, nCount, nMode);\r
1695                 Attach(hRgn);\r
1696                 return hRgn;\r
1697         }\r
1698 \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
1701         {\r
1702                 assert(m_pData);\r
1703                 HRGN hRgn = ::CreatePolyPolygonRgn(lpPoints, lpPolyCounts, nCount, nPolyFillMode);\r
1704                 Attach(hRgn);\r
1705                 return hRgn;\r
1706         }\r
1707 \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
1710         {\r
1711                 assert(m_pData);\r
1712                 HRGN hRgn = ::CreateRoundRectRgn(x1, y1, x2, y2, x3, y3);\r
1713                 Attach(hRgn);\r
1714                 return hRgn;\r
1715         }\r
1716 \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
1720         {\r
1721                 assert(m_pData);\r
1722                 assert(hDC != NULL);\r
1723                 HRGN hRgn = ::PathToRegion(hDC);\r
1724                 Attach(hRgn);\r
1725                 return hRgn;\r
1726         }\r
1727 \r
1728 #endif // !_WIN32_WCE\r
1729 \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
1732         {\r
1733                 assert(m_pData);\r
1734                 HRGN hRgn = ::ExtCreateRegion(lpXForm, nCount, pRgnData);\r
1735                 Attach(hRgn);\r
1736                 return hRgn;\r
1737         }\r
1738 \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
1741         {\r
1742                 assert(m_pData);\r
1743                 assert(m_pData->hGDIObject != NULL);\r
1744                 ::SetRectRgn((HRGN)m_pData->hGDIObject, x1, y1, x2, y2);\r
1745         }\r
1746 \r
1747         inline void CRgn::SetRectRgn(const RECT& rc)\r
1748         // converts the region into a rectangular region with the specified coordinates.\r
1749         {\r
1750                 assert(m_pData);\r
1751                 assert(m_pData->hGDIObject != NULL);\r
1752                 ::SetRectRgn((HRGN)m_pData->hGDIObject, rc.left, rc.top, rc.right, rc.bottom);\r
1753         }\r
1754 \r
1755         inline int CRgn::CombineRgn(CRgn* pRgnSrc1, CRgn* pRgnSrc2, int nCombineMode)\r
1756         // Combines two sepcified regions and stores the result.\r
1757         {\r
1758                 assert(m_pData);\r
1759                 assert(m_pData->hGDIObject != NULL);\r
1760                 assert(pRgnSrc1);\r
1761                 assert(pRgnSrc2);\r
1762                 return ::CombineRgn((HRGN)m_pData->hGDIObject, *pRgnSrc1, *pRgnSrc2, nCombineMode);\r
1763         }\r
1764 \r
1765         inline int CRgn::CombineRgn(CRgn* pRgnSrc, int nCombineMode)\r
1766         // Combines the sepcified region with the current region.\r
1767         {\r
1768                 assert(m_pData);\r
1769                 assert(m_pData->hGDIObject != NULL);\r
1770                 assert(pRgnSrc);\r
1771                 return ::CombineRgn((HRGN)m_pData->hGDIObject, (HRGN)m_pData->hGDIObject, *pRgnSrc, nCombineMode);\r
1772         }\r
1773 \r
1774         inline int CRgn::CopyRgn(CRgn* pRgnSrc)\r
1775         // Assigns the specified region to the current region.\r
1776         {\r
1777                 assert(m_pData);\r
1778                 assert(m_pData->hGDIObject == NULL);\r
1779                 assert(pRgnSrc);\r
1780                 return ::CombineRgn((HRGN)m_pData->hGDIObject, *pRgnSrc, NULL, RGN_COPY);\r
1781         }\r
1782 \r
1783         inline BOOL CRgn::EqualRgn(CRgn* pRgn) const\r
1784         // Checks the two specified regions to determine whether they are identical.\r
1785         {\r
1786                 assert(m_pData);\r
1787                 assert(m_pData->hGDIObject != NULL);\r
1788                 assert(pRgn);\r
1789                 return ::EqualRgn((HRGN)m_pData->hGDIObject, *pRgn);\r
1790         }\r
1791 \r
1792         inline int CRgn::OffsetRgn(int x, int y)\r
1793         // Moves a region by the specified offsets.\r
1794         {\r
1795                 assert(m_pData);\r
1796                 assert(m_pData->hGDIObject != NULL);\r
1797                 return ::OffsetRgn((HRGN)m_pData->hGDIObject, x, y);\r
1798         }\r
1799 \r
1800         inline int CRgn::OffsetRgn(POINT& pt)\r
1801         // Moves a region by the specified offsets.\r
1802         {\r
1803                 assert(m_pData);\r
1804                 assert(m_pData->hGDIObject != NULL);\r
1805                 return ::OffsetRgn((HRGN)m_pData->hGDIObject, pt.x, pt.y);\r
1806         }\r
1807 \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
1811         {\r
1812                 assert(m_pData);\r
1813                 assert(m_pData->hGDIObject != NULL);\r
1814                 return ::GetRgnBox((HRGN)m_pData->hGDIObject, &rc);\r
1815         }\r
1816 \r
1817         inline int CRgn::GetRegionData(LPRGNDATA lpRgnData, int nDataSize) const\r
1818         // Fills the specified buffer with data describing a region.\r
1819         {\r
1820                 assert(m_pData);\r
1821                 assert(m_pData->hGDIObject != NULL);\r
1822                 return (int)::GetRegionData((HRGN)m_pData->hGDIObject, nDataSize, lpRgnData);\r
1823         }\r
1824 \r
1825         inline BOOL CRgn::PtInRegion(int x, int y) const\r
1826         // Determines whether the specified point is inside the specified region.\r
1827         {\r
1828                 assert(m_pData);\r
1829                 assert(m_pData->hGDIObject != NULL);\r
1830                 return ::PtInRegion((HRGN)m_pData->hGDIObject, x, y);\r
1831         }\r
1832 \r
1833         inline BOOL CRgn::PtInRegion(POINT& pt) const\r
1834         // Determines whether the specified point is inside the specified region.\r
1835         {\r
1836                 assert(m_pData);\r
1837                 assert(m_pData->hGDIObject != NULL);\r
1838                 return ::PtInRegion((HRGN)m_pData->hGDIObject, pt.x, pt.y);\r
1839         }\r
1840 \r
1841         inline BOOL CRgn::RectInRegion(const RECT& rc) const\r
1842         // Determines whether the specified rect is inside the specified region.\r
1843         {\r
1844                 assert(m_pData);\r
1845                 assert(m_pData->hGDIObject != NULL);\r
1846                 return ::RectInRegion((HRGN)m_pData->hGDIObject, &rc);\r
1847         }\r
1848 \r
1849 \r
1850         ///////////////////////////////////////////////\r
1851         // Definitions of the CDC class\r
1852         //\r
1853         inline CDC::CDC()\r
1854         {\r
1855                 // Allocate memory for our data members\r
1856                 m_pData = new DataMembers;\r
1857 \r
1858                 // Assign values to our data members\r
1859                 m_pData->hDC = 0;\r
1860                 m_pData->Count = 1L;\r
1861                 m_pData->bRemoveHDC = TRUE;\r
1862                 m_pData->hWnd = 0;\r
1863         }\r
1864 \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
1870 \r
1871         // Note: this constructor permits a call like this:\r
1872         // CDC MyCDC = SomeHDC;\r
1873         //  or\r
1874         // CDC MyCDC = ::CreateCompatibleDC(SomeHDC);\r
1875         //  or\r
1876         // CDC MyCDC = ::GetDC(SomeHWND);\r
1877         {\r
1878                 UNREFERENCED_PARAMETER(hWnd);\r
1879                 assert(hDC);\r
1880 \r
1881                 CDC* pDC = GetApp()->GetCDCFromMap(hDC);\r
1882                 if (pDC)\r
1883                 {\r
1884                         m_pData = pDC->m_pData;\r
1885                         InterlockedIncrement(&m_pData->Count);\r
1886                 }\r
1887                 else\r
1888                 {\r
1889                         // Allocate memory for our data members\r
1890                         m_pData = new DataMembers;\r
1891 \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
1899 #else\r
1900                         m_pData->hWnd = hWnd;\r
1901 #endif\r
1902                         if (m_pData->hWnd == 0)\r
1903                                 AddToMap();\r
1904                 }\r
1905         }\r
1906 \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
1910         // CDC MyCDC;\r
1911         // MyCDC = SomeHDC;\r
1912         {\r
1913                 Attach(hDC);\r
1914         }\r
1915 #endif\r
1916 \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
1921         {\r
1922                 m_pData = rhs.m_pData;\r
1923                 InterlockedIncrement(&m_pData->Count);\r
1924         }\r
1925 \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
1929         {\r
1930                 if (this != &rhs)\r
1931                 {\r
1932                         InterlockedIncrement(&rhs.m_pData->Count);\r
1933                         Release();\r
1934                         m_pData = rhs.m_pData;\r
1935                 }\r
1936 \r
1937                 return *this;\r
1938         }\r
1939 \r
1940         inline CDC::~CDC ()\r
1941         {\r
1942                 Release();\r
1943         }\r
1944 \r
1945         inline void CDC::AddToMap()\r
1946         // Store the HDC and CDC pointer in the HDC map\r
1947         {\r
1948                 assert( GetApp() );\r
1949                 assert(m_pData->hDC);\r
1950                 GetApp()->m_csMapLock.Lock();\r
1951 \r
1952                 assert(m_pData->hDC);\r
1953                 assert(!GetApp()->GetCDCFromMap(m_pData->hDC));\r
1954 \r
1955                 GetApp()->m_mapHDC.insert(std::make_pair(m_pData->hDC, this));\r
1956                 GetApp()->m_csMapLock.Release();\r
1957         }\r
1958 \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
1964         {\r
1965                 UNREFERENCED_PARAMETER(hWnd);\r
1966                 assert(m_pData);\r
1967                 assert(0 == m_pData->hDC);\r
1968                 assert(hDC);\r
1969 \r
1970                 CDC* pDC = GetApp()->GetCDCFromMap(hDC);\r
1971                 if (pDC)\r
1972                 {\r
1973                         delete m_pData;\r
1974                         m_pData = pDC->m_pData;\r
1975                         InterlockedIncrement(&m_pData->Count);\r
1976                 }\r
1977                 else\r
1978                 {\r
1979                         m_pData->hDC = hDC;\r
1980 \r
1981 #ifndef _WIN32_WCE\r
1982                         m_pData->hWnd = ::WindowFromDC(hDC);\r
1983 #else\r
1984                         m_pData->hWnd = hWnd;\r
1985 #endif\r
1986 \r
1987                         if (m_pData->hWnd == 0)\r
1988                                 AddToMap();\r
1989                         m_pData->nSavedDCState = ::SaveDC(hDC);\r
1990                 }\r
1991         }\r
1992 \r
1993         inline HDC CDC::Detach()\r
1994         // Detaches the HDC from this object.\r
1995         {\r
1996                 assert(m_pData);\r
1997                 assert(m_pData->hDC);\r
1998 \r
1999                 GetApp()->m_csMapLock.Lock();\r
2000                 RemoveFromMap();\r
2001                 HDC hDC = m_pData->hDC;\r
2002                 m_pData->hDC = 0;\r
2003 \r
2004                 if (m_pData->Count)\r
2005                 {\r
2006                         if (InterlockedDecrement(&m_pData->Count) == 0)\r
2007                         {\r
2008                                 delete m_pData;\r
2009                         }\r
2010                 }\r
2011 \r
2012                 GetApp()->m_csMapLock.Release();\r
2013 \r
2014                 // Assign values to our data members\r
2015                 m_pData = new DataMembers;\r
2016                 m_pData->hDC = 0;\r
2017                 m_pData->Count = 1L;\r
2018                 m_pData->bRemoveHDC = TRUE;\r
2019                 m_pData->hWnd = 0;\r
2020 \r
2021                 return hDC;\r
2022         }\r
2023 \r
2024         // Initialization\r
2025         inline BOOL CDC::CreateCompatibleDC(CDC* pDC)\r
2026         // Returns a memory device context (DC) compatible with the specified device.\r
2027         {\r
2028                 assert(m_pData->hDC == NULL);\r
2029                 HDC hdcSource = (pDC == NULL)? NULL : pDC->GetHDC();\r
2030                 HDC hDC = ::CreateCompatibleDC(hdcSource);\r
2031                 if (hDC)\r
2032                 {\r
2033                         m_pData->hDC = hDC;\r
2034                         AddToMap();\r
2035                 }\r
2036                 return (hDC != NULL);   // boolean expression\r
2037         }\r
2038 \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
2041         {\r
2042                 assert(m_pData->hDC == NULL);\r
2043                 HDC hDC = ::CreateDC(lpszDriver, lpszDevice, lpszOutput, pInitData);\r
2044                 if (hDC)\r
2045                 {\r
2046                         m_pData->hDC = hDC;\r
2047                         AddToMap();\r
2048                 }\r
2049                 return (hDC != NULL);   // boolean expression\r
2050         }\r
2051 \r
2052 #ifndef _WIN32_WCE\r
2053         inline BOOL CDC::CreateIC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, LPCTSTR lpszOutput, const DEVMODE* pInitData)\r
2054         {\r
2055                 assert(m_pData->hDC == NULL);\r
2056                 HDC hDC = ::CreateIC(lpszDriver, lpszDevice, lpszOutput, pInitData);\r
2057                 if (hDC)\r
2058                 {\r
2059                         m_pData->hDC = hDC;\r
2060                         AddToMap();\r
2061                 }\r
2062                 return (hDC != NULL);   // boolean expression\r
2063         }\r
2064 #endif\r
2065 \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
2069         {\r
2070                 // Create the Image memory DC\r
2071                 CMemDC dcImage(this);\r
2072                 dcImage.SetBkColor(clrMask);\r
2073                 dcImage.SelectObject(&Bitmap);\r
2074 \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
2079 \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
2084         }\r
2085 \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
2089         {\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
2096                 return pDC;\r
2097         }\r
2098 \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
2101         {\r
2102                 int Width = rc.right - rc.left;\r
2103                 int Height = rc.bottom - rc.top;\r
2104 \r
2105                 int r1 = GetRValue(Color1);\r
2106                 int g1 = GetGValue(Color1);\r
2107                 int b1 = GetBValue(Color1);\r
2108 \r
2109                 int r2 = GetRValue(Color2);\r
2110                 int g2 = GetGValue(Color2);\r
2111                 int b2 = GetBValue(Color2);\r
2112 \r
2113                 COLORREF OldBkColor = GetBkColor();\r
2114 \r
2115                 if (bVertical)\r
2116                 {\r
2117                         for(int i=0; i < Width; ++i)\r
2118                         {\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
2125                         }\r
2126                 }\r
2127                 else\r
2128                 {\r
2129                         for(int i=0; i < Height; ++i)\r
2130                         {\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
2137                         }\r
2138                 }\r
2139 \r
2140                 SetBkColor(OldBkColor);\r
2141         }\r
2142 \r
2143         inline void CDC::Release()\r
2144         {\r
2145                 GetApp()->m_csMapLock.Lock();\r
2146 \r
2147                 if (m_pData->Count)\r
2148                 {\r
2149                         if (InterlockedDecrement(&m_pData->Count) == 0)\r
2150                         {\r
2151                                 Destroy();\r
2152                                 delete m_pData;\r
2153                                 m_pData = 0;\r
2154                         }\r
2155                 }\r
2156 \r
2157                 GetApp()->m_csMapLock.Release();\r
2158         }\r
2159 \r
2160         inline BOOL CDC::RemoveFromMap()\r
2161         {\r
2162                 BOOL Success = FALSE;\r
2163 \r
2164                 if( GetApp() )\r
2165                 {\r
2166                         // Allocate an iterator for our HDC map\r
2167                         std::map<HDC, CDC*, CompareHDC>::iterator m;\r
2168 \r
2169                         CWinApp* pApp = GetApp();\r
2170                         if (pApp)\r
2171                         {\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
2176                                 {\r
2177                                         pApp->m_mapHDC.erase(m);\r
2178                                         Success = TRUE;\r
2179                                 }\r
2180 \r
2181                                 pApp->m_csMapLock.Release();\r
2182                         }\r
2183                 }\r
2184                 return Success;\r
2185         }\r
2186 \r
2187         inline void CDC::SolidFill(COLORREF Color, const RECT& rc)\r
2188         // Fills a rectangle with a solid color\r
2189         {\r
2190                 COLORREF OldColor = SetBkColor(Color);\r
2191                 ExtTextOut(0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);\r
2192                 SetBkColor(OldColor);\r
2193         }\r
2194 \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
2198         {\r
2199                 assert(m_pData->hDC);\r
2200                 assert(pDC);\r
2201 \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
2206         }\r
2207 \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
2211         {\r
2212                 assert(m_pData->hDC);\r
2213 \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
2218         }\r
2219 \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
2224         {\r
2225                 assert(m_pData->hDC);\r
2226 \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
2231         }\r
2232 \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
2237         {\r
2238                 assert(m_pData->hDC);\r
2239                 assert(pDC);\r
2240 \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
2245         }\r
2246 #endif\r
2247 \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
2252         {\r
2253                 assert(m_pData->hDC);\r
2254                 assert(pDC);\r
2255 \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
2260         }\r
2261 \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
2266         {\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
2271                 \r
2272                 // Select our new stock bitmap into the device context\r
2273                 HBITMAP hBitmap = (HBITMAP)::SelectObject(*this, *pBitmap);\r
2274 \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
2278                 {\r
2279                         if((*it)->GetHandle() == hBitmap)\r
2280                                 (*it)->Detach();\r
2281                 }\r
2282 \r
2283                 // Create a local CBitmap. We can return this by value because it is reference counted\r
2284                 CBitmap Bitmap(hBitmap);\r
2285                 return Bitmap;\r
2286         }\r
2287 \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
2291         {\r
2292                 if (m_pData->hDC)\r
2293                 {\r
2294                         RemoveFromMap();\r
2295                         if (m_pData->bRemoveHDC)\r
2296                         {\r
2297                                 // Return the DC back to its initial state\r
2298                                 ::RestoreDC(m_pData->hDC, m_pData->nSavedDCState);\r
2299 \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
2303                                 else\r
2304                                         if (!::DeleteDC(m_pData->hDC))\r
2305                                                 ::ReleaseDC(NULL, m_pData->hDC);\r
2306 \r
2307                                 m_pData->hDC = 0;\r
2308                                 m_pData->hWnd = 0;\r
2309                                 m_pData->bRemoveHDC = TRUE;\r
2310                         }\r
2311                 }\r
2312         }\r
2313 \r
2314         inline BITMAP CDC::GetBitmapData() const\r
2315         // Retrieves the BITMAP information for the current HBITMAP.\r
2316         {\r
2317                 assert(m_pData->hDC);\r
2318 \r
2319                 HBITMAP hbm = (HBITMAP)::GetCurrentObject(m_pData->hDC, OBJ_BITMAP);\r
2320                 BITMAP bm = {0};\r
2321                 ::GetObject(hbm, sizeof(bm), &bm);\r
2322                 return bm;\r
2323         }\r
2324 \r
2325         inline BOOL CDC::LoadBitmap(UINT nID)\r
2326         // Loads a bitmap from the resource and selects it into the device context\r
2327         {\r
2328                 return LoadBitmap(MAKEINTRESOURCE(nID));\r
2329         }\r
2330 \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
2334         {\r
2335                 assert(m_pData->hDC);\r
2336 \r
2337                 CBitmap* pBitmap = new CBitmap;\r
2338                 BOOL bResult = pBitmap->LoadBitmap(lpszName);\r
2339                 m_pData->m_vGDIObjects.push_back(pBitmap);\r
2340         \r
2341                 if (bResult)\r
2342                         ::SelectObject(*this, *pBitmap);\r
2343 \r
2344                 return bResult;\r
2345         }\r
2346 \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
2350         {\r
2351                 return LoadImage(nID, cxDesired, cyDesired, fuLoad);\r
2352         }\r
2353 \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
2357         {\r
2358                 assert(m_pData->hDC);\r
2359 \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
2363 \r
2364                 if (bResult)\r
2365                         ::SelectObject(*this, *pBitmap);\r
2366 \r
2367                 return bResult;\r
2368         }\r
2369 \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
2373         {\r
2374                 assert(m_pData->hDC);\r
2375 \r
2376                 CBitmap* pBitmap = new CBitmap;\r
2377                 BOOL bResult = pBitmap->LoadOEMBitmap(nIDBitmap);\r
2378                 m_pData->m_vGDIObjects.push_back(pBitmap);\r
2379                 \r
2380                 if (bResult)\r
2381                         ::SelectObject(*this, *pBitmap);\r
2382 \r
2383                 return bResult;\r
2384         }\r
2385 \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
2390         {\r
2391                 assert(m_pData->hDC);\r
2392 \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
2397         }\r
2398 #endif // !_WIN32_WCE\r
2399 \r
2400 \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
2406         {\r
2407                 assert(m_pData->hDC);\r
2408 \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
2413         }\r
2414 \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
2418         {\r
2419                 assert(m_pData->hDC);\r
2420 \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
2425         }\r
2426 \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
2430         {\r
2431                 assert(m_pData->hDC);\r
2432 \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
2437         }\r
2438         \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
2442         {\r
2443                 assert(m_pData->hDC);\r
2444 \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
2449         }\r
2450 #endif\r
2451 \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
2455         {\r
2456                 assert(m_pData->hDC);\r
2457                 assert(pBitmap);\r
2458 \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
2463         }\r
2464 \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
2468         {\r
2469                 assert(m_pData->hDC);\r
2470 \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
2475         }\r
2476 \r
2477         inline LOGBRUSH CDC::GetLogBrush() const\r
2478         // Retrieves the current brush information\r
2479         {\r
2480                 assert(m_pData->hDC);\r
2481 \r
2482                 HBRUSH hBrush = (HBRUSH)::GetCurrentObject(m_pData->hDC, OBJ_BRUSH);\r
2483                 LOGBRUSH lBrush = {0};\r
2484                 ::GetObject(hBrush, sizeof(lBrush), &lBrush);\r
2485                 return lBrush;\r
2486         }\r
2487 \r
2488 \r
2489         // Font functions\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
2506                                         )\r
2507 \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
2510         {\r
2511                 assert(m_pData->hDC);\r
2512 \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
2520         }\r
2521 #endif\r
2522 \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
2526         {\r
2527                 assert(m_pData->hDC);\r
2528 \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
2533         }\r
2534 \r
2535         inline LOGFONT CDC::GetLogFont() const\r
2536         // Retrieves the current font information.\r
2537         {\r
2538                 assert(m_pData->hDC);\r
2539 \r
2540                 HFONT hFont = (HFONT)::GetCurrentObject(m_pData->hDC, OBJ_FONT);\r
2541                 LOGFONT lFont = {0};\r
2542                 ::GetObject(hFont, sizeof(lFont), &lFont);\r
2543                 return lFont;\r
2544         }\r
2545 \r
2546         // Pen functions\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
2550         {\r
2551                 assert(m_pData->hDC);\r
2552 \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
2557         }\r
2558 \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
2562         {\r
2563                 assert(m_pData->hDC);\r
2564 \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
2569         }\r
2570 \r
2571         inline LOGPEN CDC::GetLogPen() const\r
2572         // Retrieves the current pen information as a LOGPEN\r
2573         {\r
2574                 assert(m_pData->hDC);\r
2575 \r
2576                 HPEN hPen = (HPEN)::GetCurrentObject(m_pData->hDC, OBJ_PEN);\r
2577                 LOGPEN lPen = {0};\r
2578                 ::GetObject(hPen, sizeof(lPen), &lPen);\r
2579                 return lPen;\r
2580         }\r
2581 \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
2586         {\r
2587                 assert(m_pData->hDC);\r
2588 \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
2593         }\r
2594 \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
2598         {\r
2599                 assert(m_pData->hDC);\r
2600 \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
2605         }\r
2606 \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
2612         {\r
2613                 assert(m_pData->hDC);\r
2614 \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
2619         }\r
2620 \r
2621 \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
2627         {\r
2628                 assert(m_pData->hDC);\r
2629 \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
2634         }\r
2635 \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
2640         {\r
2641                 assert(m_pData->hDC);\r
2642 \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
2647         }\r
2648 \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
2653         {\r
2654                 assert(m_pData->hDC);\r
2655 \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
2660         }\r
2661 \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
2665         {\r
2666                 assert(m_pData->hDC);\r
2667 \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
2672         }\r
2673 #endif\r
2674 \r
2675 \r
2676         // Wrappers for WinAPI functions\r
2677 \r
2678         inline int CDC::GetDeviceCaps (int nIndex) const\r
2679         // Retrieves device-specific information for the specified device.\r
2680         {\r
2681                 assert(m_pData->hDC);\r
2682                 return ::GetDeviceCaps(m_pData->hDC, nIndex);\r
2683         }\r
2684 \r
2685         // Brush Functions\r
2686 #ifdef GetDCBrushColor\r
2687         inline COLORREF CDC::GetDCBrushColor() const\r
2688         {\r
2689                 assert(m_pData->hDC);\r
2690                 return ::GetDCBrushColor(m_pData->hDC);\r
2691         }\r
2692 \r
2693         inline COLORREF CDC::SetDCBrushColor(COLORREF crColor) const\r
2694         {\r
2695                 assert(m_pData->hDC);\r
2696                 return ::SetDCBrushColor(m_pData->hDC, crColor);\r
2697         }\r
2698 #endif\r
2699 \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
2703         {\r
2704                 assert(m_pData->hDC);\r
2705                 return ::ExcludeClipRect(m_pData->hDC, Left, Top, Right, BottomRect);\r
2706         }\r
2707 \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
2710         {\r
2711                 assert(m_pData->hDC);\r
2712                 return ::ExcludeClipRect(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);\r
2713         }\r
2714 \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
2717         {\r
2718                 assert(m_pData->hDC);\r
2719                 return ::GetClipBox(m_pData->hDC, &rc);\r
2720         }\r
2721 \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
2726         {\r
2727                 assert(m_pData->hDC);\r
2728                 return ::GetClipRgn(m_pData->hDC, hrgn);\r
2729         }\r
2730 \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
2733         {\r
2734                 assert(m_pData->hDC);\r
2735                 return ::IntersectClipRect(m_pData->hDC, Left, Top, Right, Bottom);\r
2736         }\r
2737 \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
2740         {\r
2741                 assert(m_pData->hDC);\r
2742                 return ::IntersectClipRect(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);\r
2743         }\r
2744 \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
2747         {\r
2748                 assert(m_pData->hDC);\r
2749                 return ::RectVisible (m_pData->hDC, &rc);\r
2750         }\r
2751 \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
2756         {\r
2757                 assert(m_pData->hDC);\r
2758                 return ::SelectClipRgn(m_pData->hDC, pRgn? (HRGN)pRgn->GetHandle() : 0);\r
2759         }\r
2760 \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
2764         {\r
2765                 assert(m_pData->hDC);\r
2766                 assert(pRgn);\r
2767                 return ::ExtSelectClipRgn(m_pData->hDC, *pRgn, fnMode);\r
2768         }\r
2769 #endif\r
2770 \r
2771         inline CBitmap* CDC::SelectObject(const CBitmap* pBitmap)\r
2772         // Use this to attach an existing bitmap.\r
2773         {\r
2774                 assert(m_pData->hDC);\r
2775                 assert(pBitmap);\r
2776 \r
2777                 return FromHandle( (HBITMAP)::SelectObject(m_pData->hDC, *pBitmap) );\r
2778         }\r
2779 \r
2780         inline CBrush* CDC::SelectObject(const CBrush* pBrush)\r
2781         // Use this to attach an existing brush.\r
2782         {\r
2783                 assert(m_pData->hDC);\r
2784                 assert(pBrush);\r
2785 \r
2786                 return FromHandle( (HBRUSH)::SelectObject(m_pData->hDC, *pBrush) );\r
2787         }\r
2788 \r
2789         inline CFont* CDC::SelectObject(const CFont* pFont)\r
2790         // Use this to attach an existing font.\r
2791         {\r
2792                 assert(m_pData->hDC);\r
2793                 assert(pFont);\r
2794 \r
2795                 return FromHandle( (HFONT)::SelectObject(m_pData->hDC, *pFont) );\r
2796         }\r
2797 \r
2798         inline CPalette* CDC::SelectObject(const CPalette* pPalette)\r
2799         // Use this to attach an existing Palette.\r
2800         {\r
2801                 assert(m_pData->hDC);\r
2802                 assert(pPalette);\r
2803 \r
2804                 return FromHandle( (HPALETTE)::SelectObject(m_pData->hDC, *pPalette) );\r
2805         }\r
2806 \r
2807         inline CPen* CDC::SelectObject(const CPen* pPen)\r
2808         // Use this to attach an existing pen.\r
2809         {\r
2810                 assert(m_pData->hDC);\r
2811                 assert(pPen);\r
2812 \r
2813                 return FromHandle( (HPEN)::SelectObject(m_pData->hDC, *pPen) );\r
2814         }\r
2815 \r
2816         inline CPalette* CDC::SelectPalette(const CPalette* pPalette, BOOL bForceBkgnd)\r
2817         // Use this to attach an existing palette.\r
2818         {\r
2819                 assert(m_pData->hDC);\r
2820                 assert(pPalette);\r
2821 \r
2822                 return FromHandle( (HPALETTE)::SelectPalette(m_pData->hDC, *pPalette, bForceBkgnd) );\r
2823         }\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
2827         {\r
2828                 assert(m_pData->hDC);\r
2829                 return ::PtVisible (m_pData->hDC, X, Y);\r
2830         }\r
2831 \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
2834         {\r
2835                 assert(m_pData->hDC);\r
2836                 return ::OffsetClipRgn (m_pData->hDC, nXOffset, nYOffset);\r
2837         }\r
2838 #endif\r
2839 \r
2840         // Point and Line Drawing Functions\r
2841         inline CPoint CDC::GetCurrentPosition() const\r
2842         // Returns the current "MoveToEx" position.\r
2843         {\r
2844                 assert(m_pData->hDC);\r
2845                 CPoint pt;\r
2846                 ::MoveToEx(m_pData->hDC, 0, 0, &pt);\r
2847                 ::MoveToEx(m_pData->hDC, pt.x, pt.y, NULL);\r
2848                 return pt;\r
2849         }\r
2850 \r
2851         inline CPoint CDC::MoveTo(int x, int y) const\r
2852         // Updates the current position to the specified point.\r
2853         {\r
2854                 assert(m_pData->hDC);\r
2855                 return ::MoveToEx(m_pData->hDC, x, y, NULL);\r
2856         }\r
2857 \r
2858         inline CPoint CDC::MoveTo(POINT pt) const\r
2859         // Updates the current position to the specified point\r
2860         {\r
2861                 assert(m_pData->hDC);\r
2862                 return ::MoveToEx(m_pData->hDC, pt.x, pt.y, NULL);\r
2863         }\r
2864 \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
2867         {\r
2868                 assert(m_pData->hDC);\r
2869                 return ::LineTo(m_pData->hDC, x, y);\r
2870         }\r
2871 \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
2874         {\r
2875                 assert(m_pData->hDC);\r
2876                 return ::LineTo(m_pData->hDC, pt.x, pt.y);\r
2877         }\r
2878 \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
2882         {\r
2883                 assert(m_pData->hDC);\r
2884                 return ::Arc(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);\r
2885         }\r
2886 \r
2887         inline BOOL CDC::Arc(RECT& rc, POINT ptStart, POINT ptEnd) const\r
2888         // Draws an elliptical arc.\r
2889         {\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
2893         }\r
2894 \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
2897         {\r
2898                 assert(m_pData->hDC);\r
2899                 return ::ArcTo(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);\r
2900         }\r
2901 \r
2902         inline BOOL CDC::ArcTo(RECT& rc, POINT ptStart, POINT ptEnd) const\r
2903         // Draws an elliptical arc.\r
2904         {\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
2908         }\r
2909 \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
2912         {\r
2913                 assert(m_pData->hDC);\r
2914                 return ::AngleArc(m_pData->hDC, x, y, nRadius, fStartAngle, fSweepAngle);\r
2915         }\r
2916 \r
2917         inline int CDC::GetArcDirection() const\r
2918         // Retrieves the current arc direction ( AD_COUNTERCLOCKWISE or AD_CLOCKWISE ).\r
2919         {\r
2920                 assert(m_pData->hDC);\r
2921                 return ::GetArcDirection(m_pData->hDC);\r
2922         }\r
2923 \r
2924         inline int CDC::SetArcDirection(int nArcDirection) const\r
2925         // Sets the current arc direction ( AD_COUNTERCLOCKWISE or AD_CLOCKWISE ).\r
2926         {\r
2927                 assert(m_pData->hDC);\r
2928                 return ::SetArcDirection(m_pData->hDC, nArcDirection);\r
2929         }\r
2930 \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
2933         {\r
2934                 assert(m_pData->hDC);\r
2935                 return ::PolyDraw(m_pData->hDC, lpPoints, lpTypes, nCount);\r
2936         }\r
2937 \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
2940         {\r
2941                 assert(m_pData->hDC);\r
2942                 return ::Polyline(m_pData->hDC, lpPoints, nCount);\r
2943         }\r
2944 \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
2947         {\r
2948                 assert(m_pData->hDC);\r
2949                 return ::PolyPolyline(m_pData->hDC, lpPoints, lpPolyPoints, nCount);\r
2950         }\r
2951 \r
2952         inline BOOL CDC::PolylineTo(const POINT* lpPoints, int nCount) const\r
2953         // Draws one or more straight lines.\r
2954         {\r
2955                 assert(m_pData->hDC);\r
2956                 return ::PolylineTo(m_pData->hDC, lpPoints, nCount);\r
2957         }\r
2958         inline BOOL CDC::PolyBezier(const POINT* lpPoints, int nCount) const\r
2959         // Draws one or more Bzier curves.\r
2960         {\r
2961                 assert(m_pData->hDC);\r
2962                 return ::PolyBezier(m_pData->hDC, lpPoints, nCount);\r
2963         }\r
2964 \r
2965         inline BOOL CDC::PolyBezierTo(const POINT* lpPoints, int nCount) const\r
2966         // Draws one or more Bzier curves.\r
2967         {\r
2968                 assert(m_pData->hDC);\r
2969                 return ::PolyBezierTo(m_pData->hDC, lpPoints, nCount );\r
2970         }\r
2971 \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
2974         {\r
2975                 assert(m_pData->hDC);\r
2976                 return ::GetPixel(m_pData->hDC, x, y);\r
2977         }\r
2978 \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
2981         {\r
2982                 assert(m_pData->hDC);\r
2983                 return ::GetPixel(m_pData->hDC, pt.x, pt.y);\r
2984         }\r
2985 \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
2988         {\r
2989                 assert(m_pData->hDC);\r
2990                 return ::SetPixel(m_pData->hDC, x, y, crColor);\r
2991         }\r
2992 \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
2995         {\r
2996                 assert(m_pData->hDC);\r
2997                 return ::SetPixel(m_pData->hDC, pt.x, pt.y, crColor);\r
2998         }\r
2999 \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
3002         {\r
3003                 assert(m_pData->hDC);\r
3004                 return ::SetPixelV(m_pData->hDC, x, y, crColor);\r
3005         }\r
3006 \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
3009         {\r
3010                 assert(m_pData->hDC);\r
3011                 return ::SetPixelV(m_pData->hDC, pt.x, pt.y, crColor);\r
3012         }\r
3013 #endif\r
3014 \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
3018         {\r
3019                 assert(m_pData->hDC);\r
3020                 ::DrawFocusRect(m_pData->hDC, &rc);\r
3021         }\r
3022 \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
3025         {\r
3026                 assert(m_pData->hDC);\r
3027                 return ::Ellipse(m_pData->hDC, x1, y1, x2, y2);\r
3028         }\r
3029 \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
3032         {\r
3033                 assert(m_pData->hDC);\r
3034                 return ::Ellipse(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);\r
3035         }\r
3036 \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
3039         {\r
3040                 assert(m_pData->hDC);\r
3041                 return ::Polygon(m_pData->hDC, lpPoints, nCount);\r
3042         }\r
3043 \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
3046         {\r
3047                 assert(m_pData->hDC);\r
3048                 return ::Rectangle(m_pData->hDC, x1, y1, x2, y2);\r
3049         }\r
3050 \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
3053         {\r
3054                 assert(m_pData->hDC);\r
3055                 return ::Rectangle(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom);\r
3056         }\r
3057 \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
3060         {\r
3061                 assert(m_pData->hDC);\r
3062                 return ::RoundRect(m_pData->hDC, x1, y1, x2, y2, nWidth, nHeight);\r
3063         }\r
3064         inline BOOL CDC::RoundRect(const RECT& rc, int nWidth, int nHeight) const\r
3065         // Draws a rectangle with rounded corners.\r
3066         {\r
3067                 assert(m_pData->hDC);\r
3068                 return ::RoundRect(m_pData->hDC, rc.left, rc.top, rc.right, rc.bottom, nWidth, nHeight );\r
3069         }\r
3070 \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
3074         {\r
3075                 assert(m_pData->hDC);\r
3076                 return ::Chord(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);\r
3077         }\r
3078 \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
3081         {\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
3085         }\r
3086 \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
3089         {\r
3090                 assert(m_pData->hDC);\r
3091                 return ::Pie(m_pData->hDC, x1, y1, x2, y2, x3, y3, x4, y4);\r
3092         }\r
3093 \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
3096         {\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
3100         }\r
3101 \r
3102         inline BOOL CDC::PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount) const\r
3103         // Draws a series of closed polygons.\r
3104         {\r
3105                 assert(m_pData->hDC);\r
3106                 return ::PolyPolygon(m_pData->hDC, lpPoints, lpPolyCounts, nCount);\r
3107         }\r
3108 #endif\r
3109 \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
3113         {\r
3114                 assert(m_pData->hDC);\r
3115                 assert(pBrush);\r
3116                 return (BOOL)::FillRect(m_pData->hDC, &rc, *pBrush);\r
3117         }\r
3118 \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
3121         {\r
3122                 assert(m_pData->hDC);\r
3123                 return ::InvertRect( m_pData->hDC, &rc);\r
3124         }\r
3125 \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
3128         {\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
3132         }\r
3133 \r
3134         inline BOOL CDC::DrawEdge(const RECT& rc, UINT nEdge, UINT nFlags) const\r
3135         // Draws one or more edges of rectangle.\r
3136         {\r
3137                 assert(m_pData->hDC);\r
3138                 return ::DrawEdge(m_pData->hDC, (LPRECT)&rc, nEdge, nFlags);\r
3139         }\r
3140 \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
3143         {\r
3144                 assert(m_pData->hDC);\r
3145                 return ::DrawFrameControl(m_pData->hDC, (LPRECT)&rc, nType, nState);\r
3146         }\r
3147 \r
3148         inline BOOL CDC::FillRgn(CRgn* pRgn, CBrush* pBrush) const\r
3149         // Fills a region by using the specified brush.\r
3150         {\r
3151                 assert(m_pData->hDC);\r
3152                 assert(pRgn);\r
3153                 assert(pBrush);\r
3154                 return ::FillRgn(m_pData->hDC, *pRgn, *pBrush);\r
3155         }\r
3156 \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
3160         {\r
3161                 assert(m_pData->hDC);\r
3162                 return ::DrawIcon(m_pData->hDC, x, y, hIcon);\r
3163         }\r
3164 \r
3165         inline BOOL CDC::DrawIcon(POINT pt, HICON hIcon) const\r
3166         // Draws an icon or cursor.\r
3167         {\r
3168                 assert(m_pData->hDC);\r
3169                 return ::DrawIcon(m_pData->hDC, pt.x, pt.y, hIcon);\r
3170         }\r
3171 \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
3174         {\r
3175                 assert(m_pData->hDC);\r
3176                 assert(pBrush);\r
3177                 return (BOOL)::FrameRect(m_pData->hDC, &rc, *pBrush);\r
3178         }\r
3179 \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
3182         {\r
3183                 assert(m_pData->hDC);\r
3184                 assert(pRgn);\r
3185                 return ::PaintRgn(m_pData->hDC, *pRgn);\r
3186         }\r
3187 #endif\r
3188 \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
3193         {\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
3196         }\r
3197 \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
3200         {\r
3201                 assert(m_pData->hDC);\r
3202                 return ::PatBlt(m_pData->hDC, x, y, nWidth, nHeight, dwRop);\r
3203         }\r
3204 \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
3207         {\r
3208                 assert(m_pData->hDC);\r
3209                 assert(pSrcDC);\r
3210                 return ::BitBlt(m_pData->hDC, x, y, nWidth, nHeight, pSrcDC->GetHDC(), xSrc, ySrc, dwRop);\r
3211         }\r
3212 \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
3215         {\r
3216                 assert(m_pData->hDC);\r
3217                 assert(pSrcDC);\r
3218                 return ::StretchBlt(m_pData->hDC, x, y, nWidth, nHeight, pSrcDC->GetHDC(), xSrc, ySrc, nSrcWidth, nSrcHeight, dwRop);\r
3219         }\r
3220 \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
3224         {\r
3225                 assert(m_pData->hDC);\r
3226                 assert(pBitmap);\r
3227                 return ::GetDIBits(m_pData->hDC, *pBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage);\r
3228         }\r
3229 \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
3232         {\r
3233                 assert(m_pData->hDC);\r
3234                 return ::SetDIBits(m_pData->hDC, *pBitmap, uStartScan, cScanLines, lpvBits, lpbi, fuColorUse);\r
3235         }\r
3236 \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
3240         {\r
3241                 assert(m_pData->hDC);\r
3242                 return ::GetStretchBltMode(m_pData->hDC);\r
3243         }\r
3244 \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
3248         {\r
3249                 assert(m_pData->hDC);\r
3250                 return ::SetStretchBltMode(m_pData->hDC, iStretchMode);\r
3251         }\r
3252 \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
3255         {\r
3256                 assert(m_pData->hDC);\r
3257                 return ::FloodFill(m_pData->hDC, x, y, crColor);\r
3258         }\r
3259 \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
3263         {\r
3264                 assert(m_pData->hDC);\r
3265                 return ::ExtFloodFill(m_pData->hDC, x, y, crColor, nFillType );\r
3266         }\r
3267 \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
3271         {\r
3272                 assert(m_pData->hDC);\r
3273                 return ::DPtoLP(m_pData->hDC, lpPoints, nCount);\r
3274         }\r
3275 \r
3276         inline BOOL CDC::DPtoLP(RECT& rc) const\r
3277         // Converts device coordinates into logical coordinates.\r
3278         {\r
3279                 assert(m_pData->hDC);\r
3280                 return ::DPtoLP(m_pData->hDC, (LPPOINT)&rc, 2);\r
3281         }\r
3282 \r
3283         inline BOOL CDC::LPtoDP(LPPOINT lpPoints, int nCount) const\r
3284         // Converts logical coordinates into device coordinates.\r
3285         {\r
3286                 assert(m_pData->hDC);\r
3287                 return ::LPtoDP(m_pData->hDC, lpPoints, nCount);\r
3288         }\r
3289 \r
3290         inline BOOL CDC::LPtoDP(RECT& rc) const\r
3291         // Converts logical coordinates into device coordinates.\r
3292         {\r
3293                 assert(m_pData->hDC);\r
3294                 return ::LPtoDP(m_pData->hDC, (LPPOINT)&rc, 2);\r
3295         }\r
3296 \r
3297 #endif\r
3298 \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
3302         {\r
3303 #if defined(WINVER) && defined(GetLayout) && (WINVER >= 0x0500)\r
3304                 return ::GetLayout(m_pData->hDC);\r
3305 #else\r
3306                 return 0;\r
3307 #endif\r
3308         }\r
3309 \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
3313         {\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
3317 #else\r
3318                 UNREFERENCED_PARAMETER(dwLayout); // no-op\r
3319                 return 0;\r
3320 #endif\r
3321         }\r
3322 \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
3328         {\r
3329                 assert(m_pData->hDC);\r
3330                 return ::GetMapMode(m_pData->hDC);\r
3331         }\r
3332 \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
3335         {\r
3336                 assert(m_pData->hDC);\r
3337                 return ::GetViewportOrgEx(m_pData->hDC, lpPoint);\r
3338         }\r
3339 \r
3340         inline int CDC::SetMapMode(int nMapMode) const\r
3341         // Sets the mapping mode of the specified device context.\r
3342         {\r
3343                 assert(m_pData->hDC);\r
3344                 return ::SetMapMode(m_pData->hDC, nMapMode);\r
3345         }\r
3346 \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
3349         {\r
3350                 assert(m_pData->hDC);\r
3351                 return ::SetViewportOrgEx(m_pData->hDC, x, y, lpPoint);\r
3352         }\r
3353 \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
3356         {\r
3357                 assert(m_pData->hDC);\r
3358                 return SetViewportOrgEx(point.x, point.y, lpPointRet);\r
3359         }\r
3360 \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
3363         {\r
3364                 assert(m_pData->hDC);\r
3365                 return ::OffsetViewportOrgEx(m_pData->hDC, nWidth, nHeight, lpPoint);\r
3366         }\r
3367 \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
3370         {\r
3371                 assert(m_pData->hDC);\r
3372                 return ::GetViewportExtEx(m_pData->hDC, lpSize);\r
3373         }\r
3374 \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
3377         {\r
3378                 assert(m_pData->hDC);\r
3379                 return ::SetViewportExtEx(m_pData->hDC, x, y, lpSize);\r
3380         }\r
3381 \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
3384         {\r
3385                 assert(m_pData->hDC);\r
3386                 return SetViewportExtEx(size.cx, size.cy, lpSizeRet);\r
3387         }\r
3388 \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
3391         {\r
3392                 assert(m_pData->hDC);\r
3393                 return ::ScaleViewportExtEx(m_pData->hDC, xNum, xDenom, yNum, yDenom, lpSize);\r
3394         }\r
3395 \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
3398         {\r
3399                 assert(m_pData->hDC);\r
3400                 return ::GetWindowOrgEx(m_pData->hDC, lpPoint);\r
3401         }\r
3402 \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
3405         {\r
3406                 assert(m_pData->hDC);\r
3407                 return ::SetWindowOrgEx(m_pData->hDC, x, y, lpPoint);\r
3408         }\r
3409 \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
3412         {\r
3413                 assert(m_pData->hDC);\r
3414                 return SetWindowOrgEx(point.x, point.y, lpPointRet);\r
3415         }\r
3416 \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
3419         {\r
3420                 assert(m_pData->hDC);\r
3421                 return ::OffsetWindowOrgEx(m_pData->hDC, nWidth, nHeight, lpPoint);\r
3422         }\r
3423 \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
3426         {\r
3427                 assert(m_pData->hDC);\r
3428                 return ::GetWindowExtEx(m_pData->hDC, lpSize);\r
3429         }\r
3430 \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
3433         {\r
3434                 assert(m_pData->hDC);\r
3435                 return ::SetWindowExtEx(m_pData->hDC, x, y, lpSize);\r
3436         }\r
3437 \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
3440         {\r
3441                 assert(m_pData->hDC);\r
3442                 return SetWindowExtEx(size.cx, size.cy, lpSizeRet);\r
3443         }\r
3444 \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
3447         {\r
3448                 assert(m_pData->hDC);\r
3449                 return ::ScaleWindowExtEx(m_pData->hDC, xNum, xDenom, yNum, yDenom, lpSize);\r
3450         }\r
3451 #endif\r
3452 \r
3453         // Printer Functions\r
3454         inline int CDC::StartDoc(LPDOCINFO lpDocInfo) const\r
3455         // Starts a print job.\r
3456         {\r
3457                 assert(m_pData->hDC);\r
3458                 return ::StartDoc(m_pData->hDC, lpDocInfo);\r
3459         }\r
3460 \r
3461         inline int CDC::EndDoc() const\r
3462         // Ends a print job.\r
3463         {\r
3464                 assert(m_pData->hDC);\r
3465                 return ::EndDoc(m_pData->hDC);\r
3466         }\r
3467 \r
3468         inline int CDC::StartPage() const\r
3469         // Prepares the printer driver to accept data.\r
3470         {\r
3471                 assert(m_pData->hDC);\r
3472                 return ::StartPage(m_pData->hDC);\r
3473         }\r
3474 \r
3475         inline int CDC::EndPage() const\r
3476         // Notifies the device that the application has finished writing to a page.\r
3477         {\r
3478                 assert(m_pData->hDC);\r
3479                 return ::EndPage(m_pData->hDC);\r
3480         }\r
3481 \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
3484         {\r
3485                 assert(m_pData->hDC);\r
3486                 return ::AbortDoc(m_pData->hDC);\r
3487         }\r
3488 \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
3491         {\r
3492                 assert(m_pData->hDC);\r
3493                 return ::SetAbortProc(m_pData->hDC, lpfn);\r
3494         }\r
3495 \r
3496         // Text Functions\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
3499         {\r
3500                 assert(m_pData->hDC);\r
3501 \r
3502                 if (nCount == -1)\r
3503                         nCount = lstrlen (lpszString);\r
3504 \r
3505                 return ::ExtTextOut(m_pData->hDC, x, y, nOptions, lprc, lpszString, nCount, lpDxWidths );\r
3506         }\r
3507 \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
3510         {\r
3511                 assert(m_pData->hDC);\r
3512                 return ::DrawText(m_pData->hDC, lpszString, nCount, lprc, nFormat );\r
3513         }\r
3514 \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
3518         {\r
3519                 assert(m_pData->hDC);\r
3520                 return ::GetTextAlign(m_pData->hDC);\r
3521         }\r
3522 \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
3526         {\r
3527                 assert(m_pData->hDC);\r
3528                 return ::SetTextAlign(m_pData->hDC, nFlags);\r
3529         }\r
3530 \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
3533         {\r
3534                 assert(m_pData->hDC);\r
3535                 return ::GetTextFace(m_pData->hDC, nCount, lpszFacename);\r
3536         }\r
3537 \r
3538         inline BOOL CDC::GetTextMetrics(TEXTMETRIC& Metrics) const\r
3539         // Fills the specified buffer with the metrics for the currently selected font\r
3540         {\r
3541                 assert(m_pData->hDC);\r
3542                 return ::GetTextMetrics(m_pData->hDC, &Metrics);\r
3543         }\r
3544 \r
3545         inline COLORREF CDC::GetBkColor() const\r
3546         // Returns the current background color\r
3547         {\r
3548                 assert(m_pData->hDC);\r
3549                 return ::GetBkColor(m_pData->hDC);\r
3550         }\r
3551 \r
3552         inline COLORREF CDC::SetBkColor(COLORREF crColor) const\r
3553         // Sets the current background color to the specified color value\r
3554         {\r
3555                 assert(m_pData->hDC);\r
3556                 return ::SetBkColor(m_pData->hDC, crColor);\r
3557         }\r
3558 \r
3559         inline COLORREF CDC::GetTextColor() const\r
3560         // Retrieves the current text color\r
3561         {\r
3562                 assert(m_pData->hDC);\r
3563                 return ::GetTextColor(m_pData->hDC);\r
3564         }\r
3565 \r
3566         inline COLORREF CDC::SetTextColor(COLORREF crColor) const\r
3567         // Sets the current text color\r
3568         {\r
3569                 assert(m_pData->hDC);\r
3570                 return ::SetTextColor(m_pData->hDC, crColor);\r
3571         }\r
3572 \r
3573         inline int CDC::GetBkMode() const\r
3574         // returns the current background mix mode (OPAQUE or TRANSPARENT)\r
3575         {\r
3576                 assert(m_pData->hDC);\r
3577                 return ::GetBkMode(m_pData->hDC);\r
3578         }\r
3579 \r
3580         inline int CDC::SetBkMode(int iBkMode) const\r
3581         // Sets the current background mix mode (OPAQUE or TRANSPARENT)\r
3582         {\r
3583                 assert(m_pData->hDC);\r
3584                 return ::SetBkMode(m_pData->hDC, iBkMode);\r
3585         }\r
3586 \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
3590         {\r
3591                 assert(m_pData->hDC);\r
3592                 return ::DrawTextEx(m_pData->hDC, lpszString, nCount, lprc, nFormat, lpDTParams);\r
3593         }\r
3594 \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
3597         {\r
3598                 assert(m_pData->hDC);\r
3599                 CSize sz;\r
3600                 ::GetTextExtentPoint32(m_pData->hDC, lpszString, nCount, &sz);\r
3601                 return sz;\r
3602         }\r
3603 \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
3606         {\r
3607                 assert(m_pData->hDC);\r
3608                 DWORD dwSize = ::GetTabbedTextExtent(m_pData->hDC, lpszString, nCount, nTabPositions, lpnTabStopPositions );\r
3609                 CSize sz(dwSize);\r
3610                 return sz;\r
3611         }\r
3612 \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
3615         {\r
3616                 assert(m_pData->hDC);\r
3617                 assert(pBrush);\r
3618                 return ::GrayString(m_pData->hDC, *pBrush, lpOutputFunc, lpData, nCount, x, y, nWidth, nHeight);\r
3619         }\r
3620 \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
3623         {\r
3624                 assert(m_pData->hDC);\r
3625                 return ::SetTextJustification(m_pData->hDC, nBreakExtra, nBreakCount);\r
3626         }\r
3627 \r
3628         inline int CDC::GetTextCharacterExtra() const\r
3629         // Retrieves the current intercharacter spacing for the device context\r
3630         {\r
3631                 assert(m_pData->hDC);\r
3632                 return ::GetTextCharacterExtra(m_pData->hDC);\r
3633         }\r
3634 \r
3635         inline int CDC::SetTextCharacterExtra(int nCharExtra) const\r
3636         // Sets the intercharacter spacing\r
3637         {\r
3638                 assert(m_pData->hDC);\r
3639                 return ::SetTextCharacterExtra(m_pData->hDC, nCharExtra);\r
3640         }\r
3641 \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
3644         {\r
3645                 assert(m_pData->hDC);\r
3646                 DWORD dwSize = ::TabbedTextOut(m_pData->hDC, x, y, lpszString, nCount, nTabPositions, lpnTabStopPositions, nTabOrigin );\r
3647                 CSize sz(dwSize);\r
3648                 return sz;\r
3649         }\r
3650 \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
3653         {\r
3654                 assert(m_pData->hDC);\r
3655                 if (nCount == -1)\r
3656                         nCount = lstrlen (lpszString);\r
3657 \r
3658                 return ::TextOut(m_pData->hDC, x, y, lpszString, nCount);\r
3659         }\r
3660 \r
3661 #endif\r
3662 \r
3663 \r
3664 \r
3665         /////////////////////////////////////////////////////////////////\r
3666         // Definitions for some global functions in the Win32xx namespace\r
3667         //\r
3668 \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
3675         {\r
3676                 // Create our LPBITMAPINFO object\r
3677                 CBitmapInfoPtr pbmi(pbmSource);\r
3678                 pbmi->bmiHeader.biBitCount = 24;\r
3679 \r
3680                 // Create the reference DC for GetDIBits to use\r
3681                 CMemDC MemDC(NULL);\r
3682 \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
3687 \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
3690 \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
3698 \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
3703 \r
3704                 int b2 = 256 + cBlue;\r
3705                 int g2 = 256 + cGreen;\r
3706                 int r2 = 256 + cRed;\r
3707 \r
3708                 // Modify the colour\r
3709                 int yOffset = 0;\r
3710                 int xOffset;\r
3711                 int Index;\r
3712                 for (int Row=0; Row < pbmi->bmiHeader.biHeight; Row++)\r
3713                 {\r
3714                         xOffset = 0;\r
3715 \r
3716                         for (int Column=0; Column < pbmi->bmiHeader.biWidth; Column++)\r
3717                         {\r
3718                                 // Calculate Index\r
3719                                 Index = yOffset + xOffset;\r
3720 \r
3721                                 // Adjust the colour values\r
3722                                 if (cBlue > 0)\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
3726 \r
3727                                 if (cGreen > 0)\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
3731 \r
3732                                 if (cRed > 0)\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
3736 \r
3737                                 // Increment the horizontal offset\r
3738                                 xOffset += pbmi->bmiHeader.biBitCount >> 3;\r
3739                         }\r
3740 \r
3741                         // Increment vertical offset\r
3742                         yOffset += nWidthBytes;\r
3743                 }\r
3744 \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
3747         }\r
3748 \r
3749         inline void GrayScaleBitmap(CBitmap* pbmSource)\r
3750         {\r
3751                 // Create our LPBITMAPINFO object\r
3752                 CBitmapInfoPtr pbmi(pbmSource);\r
3753 \r
3754                 // Create the reference DC for GetDIBits to use\r
3755                 CMemDC MemDC(NULL);\r
3756 \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
3761 \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
3764 \r
3765                 int yOffset = 0;\r
3766                 int xOffset;\r
3767                 int Index;\r
3768 \r
3769                 for (int Row=0; Row < pbmi->bmiHeader.biHeight; Row++)\r
3770                 {\r
3771                         xOffset = 0;\r
3772 \r
3773                         for (int Column=0; Column < pbmi->bmiHeader.biWidth; Column++)\r
3774                         {\r
3775                                 // Calculate Index\r
3776                                 Index = yOffset + xOffset;\r
3777 \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
3782 \r
3783                                 // Increment the horizontal offset\r
3784                                 xOffset += pbmi->bmiHeader.biBitCount >> 3;\r
3785                         }\r
3786 \r
3787                         // Increment vertical offset\r
3788                         yOffset += nWidthBytes;\r
3789                 }\r
3790 \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
3793         }\r
3794 \r
3795         inline HIMAGELIST CreateDisabledImageList(HIMAGELIST himlNormal)\r
3796         // Returns a greyed image list, created from hImageList\r
3797         {\r
3798                 int cx, cy;\r
3799                 int nCount = ImageList_GetImageCount(himlNormal);\r
3800                 if (0 == nCount)\r
3801                         return NULL;\r
3802 \r
3803                 ImageList_GetIconSize(himlNormal, &cx, &cy);\r
3804 \r
3805                 // Create the disabled ImageList\r
3806                 HIMAGELIST himlDisabled = ImageList_Create(cx, cy, ILC_COLOR24 | ILC_MASK, nCount, 0);\r
3807 \r
3808                 // Process each image in the ImageList\r
3809                 for (int i = 0 ; i < nCount; ++i)\r
3810                 {\r
3811                         CClientDC DesktopDC(NULL);\r
3812                         CMemDC MemDC(NULL);\r
3813                         MemDC.CreateCompatibleBitmap(&DesktopDC, cx, cx);\r
3814                         CRect rc;\r
3815                         rc.SetRect(0, 0, cx, cx);\r
3816 \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
3820                         {\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
3824                         }\r
3825 \r
3826                         MemDC.SolidFill(crMask, rc);\r
3827 \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
3831 \r
3832                         // Convert colored pixels to gray\r
3833                         for (int x = 0 ; x < cx; ++x)\r
3834                         {\r
3835                                 for (int y = 0; y < cy; ++y)\r
3836                                 {\r
3837                                         COLORREF clr = ::GetPixel(MemDC, x, y);\r
3838 \r
3839                                         if (clr != crMask)\r
3840                                         {\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
3843                                         }\r
3844 \r
3845                                 }\r
3846                         }\r
3847 \r
3848                         // Detach the bitmap so we can use it.\r
3849                         CBitmap Bitmap = MemDC.DetachBitmap();\r
3850                         ImageList_AddMasked(himlDisabled, Bitmap, crMask);\r
3851                 }\r
3852 \r
3853                 return himlDisabled;\r
3854         }\r
3855 #endif\r
3856 \r
3857         ////////////////////////////////////////////\r
3858         // Global Function Definitions\r
3859         //\r
3860 \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
3866         {\r
3867                 assert( GetApp() );\r
3868                 CDC* pDC = GetApp()->GetCDCFromMap(hDC);\r
3869                 if (hDC != 0 && pDC == 0)\r
3870                 {\r
3871                         pDC = new CDC;\r
3872                         GetApp()->AddTmpDC(pDC);\r
3873                         pDC->m_pData->hDC = hDC;\r
3874                         pDC->m_pData->bRemoveHDC = FALSE;\r
3875                 }\r
3876                 return pDC;\r
3877         }\r
3878 \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
3884         {\r
3885                 assert( GetApp() );\r
3886                 CBitmap* pBitmap = (CBitmap*)GetApp()->GetCGDIObjectFromMap(hBitmap);\r
3887                 if (hBitmap != 0 && pBitmap == 0)\r
3888                 {\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
3893                 }\r
3894                 return pBitmap;\r
3895         }\r
3896 \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
3902         {\r
3903                 assert( GetApp() );\r
3904                 CBrush* pBrush = (CBrush*)GetApp()->GetCGDIObjectFromMap(hBrush);\r
3905                 if (hBrush != 0 && pBrush == 0)\r
3906                 {\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
3911                 }\r
3912                 return pBrush;\r
3913         }\r
3914 \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
3920         {\r
3921                 assert( GetApp() );\r
3922                 CFont* pFont = (CFont*)GetApp()->GetCGDIObjectFromMap(hFont);\r
3923                 if (hFont != 0 && pFont == 0)\r
3924                 {\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
3929                 }\r
3930                 return pFont;\r
3931         }\r
3932 \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
3938         {\r
3939                 assert( GetApp() );\r
3940                 CPalette* pPalette = (CPalette*)GetApp()->GetCGDIObjectFromMap(hPalette);\r
3941                 if (hPalette != 0 && pPalette == 0)\r
3942                 {\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
3947                 }\r
3948                 return pPalette;\r
3949         }\r
3950 \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
3956         {\r
3957                 assert( GetApp() );\r
3958                 CPen* pPen = (CPen*)GetApp()->GetCGDIObjectFromMap(hPen);\r
3959                 if (hPen != 0 && pPen == 0)\r
3960                 {\r
3961                         pPen = new CPen;\r
3962                         GetApp()->AddTmpGDI(pPen);\r
3963                         pPen->m_pData->hGDIObject = hPen;\r
3964                         pPen->m_pData->bRemoveObject = FALSE;\r
3965                 }\r
3966                 return pPen;\r
3967         }\r
3968 \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
3974         {\r
3975                 assert( GetApp() );\r
3976                 CRgn* pRgn = (CRgn*)GetApp()->GetCGDIObjectFromMap(hRgn);\r
3977                 if (hRgn != 0 && pRgn == 0)\r
3978                 {\r
3979                         pRgn = new CRgn;\r
3980                         GetApp()->AddTmpGDI(pRgn);\r
3981                         pRgn->m_pData->hGDIObject = hRgn;\r
3982                         pRgn->m_pData->bRemoveObject = FALSE;\r
3983                 }\r
3984                 return pRgn;\r
3985         }\r
3986 \r
3987 \r
3988 \r
3989 } // namespace Win32xx\r
3990 \r
3991 #endif // _WIN32XX_GDI_H_\r
3992 \r

UCC git Repository :: git.ucc.asn.au