Merge branch 'master' of git.ucc.asn.au:/matches/honours
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / include / wincore.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 // wincore.h\r
40 //  Declaration of the following classes:\r
41 //  CWinApp, CWnd, CWinException, CCriticalSection,\r
42 //  CPoint, CRect, and CSize\r
43 //\r
44 // This file contains the declarations for the core set of classes required to\r
45 // create simple windows using Win32++.\r
46 //\r
47 // 1) CCriticalSection: This class is used internally to manage thread access\r
48 //            to shared resources. You can also use this class to lock and\r
49 //            release your own critical sections.\r
50 //\r
51 // 2) CWinException: This class is used internally by Win32++ to handle\r
52 //            exceptions. You can also use it to throw and catch exceptions.\r
53 //\r
54 // 3) WinApp: This class is used start Win32++ and run the message loop. You\r
55 //            should inherit from this class to start Win32++ in your own\r
56 //            application.\r
57 //\r
58 // 4) CWnd:   This class is used to represent a window. It provides a means\r
59 //            of creating the window, and handling its messages. Inherit\r
60 //            from this class to define and control windows.\r
61 //\r
62 //\r
63 // Note: This header file (or another Win32++ header file which includes it)\r
64 //       should be included before all other header files. It sets some\r
65 //       important macros which need to be set before including Windows.h\r
66 //       Including this file first also allows it to disable some pointless\r
67 //       warning messages (see below).\r
68 \r
69 \r
70 \r
71 #ifndef _WIN32XX_WINCORE_H_\r
72 #define _WIN32XX_WINCORE_H_\r
73 \r
74 \r
75 // Remove pointless warning messages\r
76 #ifdef _MSC_VER\r
77   #pragma warning (disable : 4996) // function or variable may be unsafe (deprecated)\r
78   #ifndef _CRT_SECURE_NO_WARNINGS\r
79     #define _CRT_SECURE_NO_WARNINGS // eliminate deprecation warnings for VS2005/VS2010\r
80   #endif\r
81   #if _MSC_VER < 1500\r
82     #pragma warning (disable : 4511) // copy operator could not be generated\r
83     #pragma warning (disable : 4512) // assignment operator could not be generated\r
84     #pragma warning (disable : 4702) // unreachable code (bugs in Microsoft's STL)\r
85     #pragma warning (disable : 4786) // identifier was truncated\r
86   #endif\r
87 #endif\r
88 \r
89 #ifdef __BORLANDC__\r
90   #pragma option -w-8019                        // code has no effect\r
91   #pragma option -w-8026            // functions with exception specifiations are not expanded inline\r
92   #pragma option -w-8027                    // function not expanded inline\r
93   #pragma option -w-8030                        // Temporary used for 'rhs'     \r
94   #define STRICT 1\r
95 #endif\r
96 \r
97 #ifdef __GNUC__\r
98   #pragma GCC diagnostic ignored "-Wmissing-braces"\r
99   #pragma GCC diagnostic ignored "-Wunused-value"\r
100 #endif\r
101 \r
102 #ifdef _WIN32_WCE\r
103   #include "wcestddef.h"\r
104 #endif\r
105 \r
106 #define _WINSOCKAPI_            // Prevent winsock.h #include's.\r
107 \r
108 #include <assert.h>\r
109 #include <vector>\r
110 #include <algorithm>\r
111 #include <string>\r
112 #include <map>\r
113 #include <windows.h>\r
114 #include <commctrl.h>\r
115 #include <stdio.h>\r
116 #include <tchar.h>\r
117 #include <shlwapi.h>\r
118 #include "shared_ptr.h"\r
119 //#include "winutils.h"                 // included later in this file\r
120 //#include "cstring.h"                  // included later in this file\r
121 //#include "gdi.h"                              // included later in this file\r
122 //#include "menu.h"                             // included later in this file\r
123 \r
124 // For compilers lacking Win64 support\r
125 #ifndef  GetWindowLongPtr\r
126   #define GetWindowLongPtr   GetWindowLong\r
127   #define SetWindowLongPtr   SetWindowLong\r
128   #define GWLP_WNDPROC       GWL_WNDPROC\r
129   #define GWLP_HINSTANCE     GWL_HINSTANCE\r
130   #define GWLP_ID            GWL_ID\r
131   #define GWLP_USERDATA      GWL_USERDATA\r
132   #define DWLP_DLGPROC       DWL_DLGPROC\r
133   #define DWLP_MSGRESULT     DWL_MSGRESULT\r
134   #define DWLP_USER          DWL_USER\r
135   #define DWORD_PTR          DWORD\r
136   #define LONG_PTR           LONG\r
137   #define ULONG_PTR          LONG\r
138 #endif\r
139 #ifndef GetClassLongPtr\r
140   #define GetClassLongPtr    GetClassLong\r
141   #define SetClassLongPtr    SetClassLong\r
142   #define GCLP_HBRBACKGROUND GCL_HBRBACKGROUND\r
143   #define GCLP_HCURSOR       GCL_HCURSOR\r
144   #define GCLP_HICON         GCL_HICON\r
145   #define GCLP_HICONSM       GCL_HICONSM\r
146   #define GCLP_HMODULE       GCL_HMODULE\r
147   #define GCLP_MENUNAME      GCL_MENUNAME\r
148   #define GCLP_WNDPROC       GCL_WNDPROC\r
149 #endif\r
150 \r
151 \r
152 // Messages defined by Win32++\r
153 #define UWM_POPUPMENU           (WM_APP + 1)    // Message - creates the menubar popup menu\r
154 #define UWM_DOCK_START          (WM_APP + 2)    // Notification - about to start undocking\r
155 #define UWM_DOCK_MOVE           (WM_APP + 3)    // Notification - undocked docker is being moved\r
156 #define UWM_DOCK_END            (WM_APP + 4)    // Notification - docker has been docked\r
157 #define UWM_BAR_START           (WM_APP + 5)    // Notification - docker bar selected for move\r
158 #define UWM_BAR_MOVE            (WM_APP + 6)    // Notification - docker bar moved\r
159 #define UWM_BAR_END                     (WM_APP + 7)    // Notification - end of docker bar move\r
160 #define UWM_UNDOCKED            (WM_APP + 8)    // Notification - sent by docker when undocked\r
161 #define UWM_FRAMELOSTFOCUS      (WM_APP + 9)    // Notification - sent by frame to view window when focus lost\r
162 #define UWM_FRAMEGOTFOCUS       (WM_APP + 10)   // Notification - sent by frame to view window when focus acquired\r
163 #define UWM_DOCK_DESTROYED      (WM_APP + 11)   // Message - posted when docker is destroyed\r
164 #define UWM_TAB_CHANGED     (WM_APP + 12)       // Notification - tab layout changed\r
165 #define UWM_TOOLBAR_RESIZE  (WM_APP + 13)   // Message - sent by toolbar to parent. Used by the rebar\r
166 #define UWM_UPDATE_COMMAND  (WM_APP + 14)   // Message - sent before a menu is displayed. Used by OnUpdate\r
167 #define UWM_DOCK_ACTIVATED  (WM_APP + 15)   // Message - sent to dock ancestor when a docker is activated or deactivated.\r
168 #define UWM_GETMENUTHEME    (WM_APP + 16)       // Message - returns a pointer to MenuTheme\r
169 #define UWM_GETREBARTHEME   (WM_APP + 17)       // Message - returns a pointer to CToolBar\r
170 #define UWM_GETTOOLBARTHEME (WM_APP + 18)   // Message - returns a pointer to ToolBarTheme\r
171 #define UWM_CLEANUPTEMPS        (WM_APP + 19)   // Message - posted to cleanup temporary CDCs\r
172 \r
173 \r
174 // Automatically include the Win32xx namespace\r
175 // define NO_USING_NAMESPACE to skip this step\r
176 namespace Win32xx {}\r
177 #ifndef NO_USING_NAMESPACE\r
178   using namespace Win32xx;\r
179 #endif\r
180 \r
181 // Required for WinCE\r
182 #ifndef TLS_OUT_OF_INDEXES\r
183   #define TLS_OUT_OF_INDEXES ((DWORD_PTR) -1)\r
184 #endif\r
185 #ifndef WM_PARENTNOTIFY\r
186   #define WM_PARENTNOTIFY 0x0210\r
187 #endif\r
188 \r
189 \r
190 namespace Win32xx\r
191 {\r
192 \r
193         ////////////////////////////////////////////////\r
194         // Forward declarations.\r
195         //  These classes are defined later or elsewhere\r
196         class CDC;\r
197         class CGDIObject;\r
198         class CMenu;\r
199         class CWinApp;\r
200         class CWnd;\r
201         class CBitmap;\r
202         class CBrush;\r
203         class CFont;\r
204         class CPalette;\r
205         class CPen;\r
206         class CRgn;\r
207 \r
208         // tString is a TCHAR std::string\r
209         typedef std::basic_string<TCHAR> tString;\r
210 \r
211         // tStringStream is a TCHAR std::stringstream\r
212         typedef std::basic_stringstream<TCHAR> tStringStream;\r
213 \r
214         // Some useful smart pointers\r
215         typedef Shared_Ptr<CDC> DCPtr;\r
216         typedef Shared_Ptr<CGDIObject> GDIPtr;\r
217         typedef Shared_Ptr<CMenu> MenuPtr;\r
218         typedef Shared_Ptr<CWnd> WndPtr;\r
219         typedef Shared_Ptr<CBitmap> BitmapPtr;\r
220         typedef Shared_Ptr<CBrush> BrushPtr;\r
221         typedef Shared_Ptr<CFont> FontPtr;\r
222         typedef Shared_Ptr<CPalette> PalettePtr;\r
223         typedef Shared_Ptr<CPen> PenPtr;\r
224         typedef Shared_Ptr<CRgn> RgnPtr;\r
225 \r
226         enum Constants                  // Defines the maximum size for TCHAR strings\r
227         {\r
228                 MAX_MENU_STRING = 80,\r
229                 MAX_STRING_SIZE = 255,\r
230         };\r
231 \r
232         struct CompareHDC               // The comparison function object used by CWinApp::m_mapHDC\r
233         {\r
234                 bool operator()(HDC const a, const HDC b) const\r
235                         {return ((DWORD_PTR)a < (DWORD_PTR)b);}\r
236         };\r
237 \r
238         struct CompareGDI               // The comparison function object used by CWinApp::m_mapGDI\r
239         {\r
240                 bool operator()(HGDIOBJ const a, const HGDIOBJ b) const\r
241                         {return ((DWORD_PTR)a < (DWORD_PTR)b);}\r
242         };\r
243 \r
244         struct CompareHMENU             // The comparison function object used by CWinApp::m_mapHMENU\r
245         {\r
246                 bool operator()(HMENU const a, const HMENU b) const\r
247                         {return ((DWORD_PTR)a < (DWORD_PTR)b);}\r
248         };\r
249 \r
250         struct CompareHWND              // The comparison function object used by CWinApp::m_mapHWND\r
251         {\r
252                 bool operator()(HWND const a, const HWND b) const\r
253                         {return ((DWORD_PTR)a < (DWORD_PTR)b);}\r
254         };\r
255 \r
256         struct TLSData                  // Used for Thread Local Storage (TLS)\r
257         {\r
258                 CWnd* pCWnd;            // pointer to CWnd object for Window creation\r
259                 CWnd* pMenuBar;         // pointer to CMenuBar object used for the WH_MSGFILTER hook\r
260                 HHOOK hHook;            // WH_MSGFILTER hook for CMenuBar and Modeless Dialogs\r
261 \r
262                 std::vector<DCPtr> vTmpDCs;             // A vector of temporary CDC pointers\r
263                 std::vector<GDIPtr> vTmpGDIs;   // A vector of temporary CGDIObject pointers\r
264                 std::vector<WndPtr> vTmpWnds;   // A vector of temporary CWnd pointers\r
265                 TLSData() : pCWnd(0), pMenuBar(0), hHook(0) {}\r
266 \r
267 #ifndef _WIN32_WCE\r
268                 std::vector<MenuPtr> vTmpMenus; // A vector of temporary CMenu pointers\r
269 #endif\r
270         };\r
271 \r
272 \r
273         /////////////////////////////////////////\r
274         // Declarations for the CCriticalSection class\r
275         // This class is used for thread synchronisation\r
276         class CCriticalSection\r
277         {\r
278         public:\r
279                 CCriticalSection()      { ::InitializeCriticalSection(&m_cs); }\r
280                 ~CCriticalSection()     { ::DeleteCriticalSection(&m_cs); }\r
281 \r
282                 void Lock()     { ::EnterCriticalSection(&m_cs); }\r
283                 void Release()  { ::LeaveCriticalSection(&m_cs); }\r
284 \r
285         private:\r
286                 CCriticalSection ( const CCriticalSection& );\r
287                 CCriticalSection& operator = ( const CCriticalSection& );\r
288 \r
289                 CRITICAL_SECTION m_cs;\r
290         };\r
291 \r
292 \r
293         ////////////////////////////////////////\r
294         // Declaration of the CWinException class\r
295         //\r
296         // Note: Each function guarantees not to throw an exception\r
297 \r
298         class CWinException : public std::exception\r
299         {\r
300         public:\r
301                 CWinException(LPCTSTR pszText) throw ();\r
302                 ~CWinException() throw() {}\r
303                 DWORD GetError() const throw ();\r
304                 LPCTSTR GetErrorString() const throw ();\r
305                 const char * what () const throw ();\r
306 \r
307         private:\r
308                 DWORD  m_Error;\r
309                 LPCTSTR m_pszText;\r
310                 TCHAR m_szErrorString[MAX_STRING_SIZE];\r
311         };\r
312 \r
313 \r
314         ///////////////////////////////////\r
315         // Declaration of the CWinApp class\r
316         //\r
317         class CWinApp\r
318         {\r
319                 // Provide these access to CWinApp's private members:\r
320                 friend class CDC;\r
321                 friend class CDialog;\r
322                 friend class CGDIObject;\r
323                 friend class CMenu;\r
324                 friend class CMenuBar;\r
325                 friend class CPropertyPage;\r
326                 friend class CPropertySheet;\r
327                 friend class CTaskDialog;\r
328                 friend class CWnd;\r
329                 friend CWinApp* GetApp();\r
330                 friend CGDIObject* FromHandle(HGDIOBJ hObject);\r
331                 friend CBitmap* FromHandle(HBITMAP hBitmap);\r
332                 friend CBrush* FromHandle(HBRUSH hBrush);\r
333                 friend CFont* FromHandle(HFONT hFont);\r
334                 friend CPalette* FromHandle(HPALETTE hPalette);\r
335                 friend CPen* FromHandle(HPEN hPen);\r
336                 friend CRgn* FromHandle(HRGN hRgn);\r
337                 friend CDC* FromHandle(HDC hDC);\r
338                 friend CWnd* FromHandle(HWND hWnd);\r
339 #ifndef _WIN32_WCE\r
340                 friend CMenu* FromHandle(HMENU hMenu);\r
341 #endif\r
342 \r
343                 typedef Shared_Ptr<TLSData> TLSDataPtr;\r
344 \r
345         public:\r
346                 CWinApp();\r
347                 virtual ~CWinApp();\r
348 \r
349                 HACCEL GetAccelerators() const { return m_hAccel; }\r
350                 HINSTANCE GetInstanceHandle() const { return m_hInstance; }\r
351                 HINSTANCE GetResourceHandle() const { return (m_hResource ? m_hResource : m_hInstance); }\r
352                 void SetAccelerators(HACCEL hAccel, CWnd* pWndAccel);\r
353                 void SetResourceHandle(HINSTANCE hResource);\r
354 \r
355                 // These are the functions you might wish to override\r
356                 virtual BOOL InitInstance();\r
357                 virtual int  MessageLoop();\r
358                 virtual BOOL OnIdle(LONG lCount);\r
359                 virtual BOOL PreTranslateMessage(MSG Msg);\r
360                 virtual int Run();\r
361 \r
362         private:\r
363                 CWinApp(const CWinApp&);                                // Disable copy construction\r
364                 CWinApp& operator = (const CWinApp&);   // Disable assignment operator\r
365                 CDC* GetCDCFromMap(HDC hDC);\r
366                 CGDIObject* GetCGDIObjectFromMap(HGDIOBJ hObject);\r
367                 CMenu* GetCMenuFromMap(HMENU hMenu);\r
368                 CWnd* GetCWndFromMap(HWND hWnd);\r
369 \r
370                 void    AddTmpDC(CDC* pDC);\r
371                 void    AddTmpGDI(CGDIObject* pObject);\r
372                 CMenu*  AddTmpMenu(HMENU hMenu);\r
373                 CWnd*   AddTmpWnd(HWND hWnd);\r
374                 void    CleanupTemps();\r
375                 DWORD   GetTlsIndex() const {return m_dwTlsIndex;}\r
376                 void    SetCallback();\r
377                 TLSData* SetTlsIndex();\r
378                 static CWinApp* SetnGetThis(CWinApp* pThis = 0);\r
379 \r
380                 std::map<HDC, CDC*, CompareHDC> m_mapHDC;                       // maps device context handles to CDC objects\r
381                 std::map<HGDIOBJ, CGDIObject*, CompareGDI> m_mapGDI;    // maps GDI handles to CGDIObjects.\r
382                 std::map<HMENU, CMenu*, CompareHMENU> m_mapHMENU;       // maps menu handles to CMenu objects\r
383                 std::map<HWND, CWnd*, CompareHWND> m_mapHWND;           // maps window handles to CWnd objects\r
384                 std::vector<TLSDataPtr> m_vTLSData;             // vector of TLSData smart pointers, one for each thread\r
385                 CCriticalSection m_csMapLock;   // thread synchronisation for m_mapHWND\r
386                 CCriticalSection m_csTLSLock;   // thread synchronisation for m_vTLSData\r
387                 CCriticalSection m_csAppStart;  // thread synchronisation for application startup\r
388                 HINSTANCE m_hInstance;                  // handle to the applications instance\r
389                 HINSTANCE m_hResource;                  // handle to the applications resources\r
390                 DWORD m_dwTlsIndex;                             // Thread Local Storage index\r
391                 WNDPROC m_Callback;                             // callback address of CWnd::StaticWndowProc\r
392                 HACCEL m_hAccel;                                // handle to the accelerator table\r
393                 CWnd* m_pWndAccel;                              // handle to the window for accelerator keys\r
394 \r
395         };\r
396 \r
397 }\r
398 \r
399 #include "winutils.h"\r
400 #include "cstring.h"\r
401 \r
402 \r
403 namespace Win32xx\r
404 {\r
405         ////////////////////////////////\r
406         // Declaration of the CWnd class\r
407         //\r
408         class CWnd\r
409         {\r
410         friend class CMDIChild;\r
411         friend class CDialog;\r
412         friend class CPropertyPage;\r
413         friend class CTaskDialog;\r
414         friend class CWinApp;\r
415 \r
416         public:\r
417                 CWnd();                         // Constructor\r
418                 CWnd(HWND hWnd)         // Constructor\r
419                 {\r
420                         if (hWnd == HWND_TOP || hWnd == HWND_TOPMOST || hWnd == HWND_BOTTOM || hWnd == HWND_NOTOPMOST)\r
421                         {\r
422                                 m_hWnd = hWnd;\r
423                         }\r
424                         else\r
425                                 Attach(hWnd);\r
426                 }\r
427                 virtual ~CWnd();        // Destructor\r
428 \r
429                 // These virtual functions can be overridden\r
430                 virtual BOOL Attach(HWND hWnd);\r
431                 virtual BOOL AttachDlgItem(UINT nID, CWnd* pParent);\r
432                 virtual void CenterWindow() const;\r
433                 virtual HWND Create(CWnd* pParent = NULL);\r
434                 virtual HWND CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, CWnd* pParent, CMenu* pMenu, LPVOID lpParam = NULL);\r
435                 virtual HWND CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rc, CWnd* pParent, CMenu* pMenu, LPVOID lpParam = NULL);\r
436                 virtual void Destroy();\r
437                 virtual HWND Detach();\r
438                 virtual HICON SetIconLarge(int nIcon);\r
439                 virtual HICON SetIconSmall(int nIcon);\r
440 \r
441                 // Attributes\r
442                 HWND GetHwnd() const                            { return m_hWnd; }\r
443                 WNDPROC GetPrevWindowProc() const       { return m_PrevWindowProc; }\r
444 \r
445                 // Wrappers for Win32 API functions\r
446                 // These functions aren't virtual, and shouldn't be overridden\r
447                 CDC*  BeginPaint(PAINTSTRUCT& ps) const;\r
448                 BOOL  BringWindowToTop() const;\r
449                 LRESULT CallWindowProc(WNDPROC lpPrevWndFunc, UINT Msg, WPARAM wParam, LPARAM lParam) const;\r
450                 BOOL  CheckDlgButton(int nIDButton, UINT uCheck) const;\r
451                 BOOL  CheckRadioButton(int nIDFirstButton, int nIDLastButton, int nIDCheckButton) const;\r
452                 CWnd* ChildWindowFromPoint(POINT pt) const;\r
453                 BOOL  ClientToScreen(POINT& pt) const;\r
454                 BOOL  ClientToScreen(RECT& rc) const;\r
455                 LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) const;\r
456                 HDWP  DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const;\r
457                 HDWP  DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, const RECT& rc, UINT uFlags) const;\r
458                 BOOL  DrawMenuBar() const;\r
459                 BOOL  EnableWindow(BOOL bEnable = TRUE) const;\r
460                 BOOL  EndPaint(PAINTSTRUCT& ps) const;\r
461                 CWnd* GetActiveWindow() const;\r
462                 CWnd* GetAncestor(UINT gaFlag = 3 /*= GA_ROOTOWNER*/) const;\r
463                 CWnd* GetCapture() const;\r
464                 ULONG_PTR GetClassLongPtr(int nIndex) const;\r
465                 CString GetClassName() const;\r
466                 CRect GetClientRect() const;\r
467                 CDC*  GetDC() const;\r
468                 CDC*  GetDCEx(HRGN hrgnClip, DWORD flags) const;\r
469                 CWnd* GetDesktopWindow() const;\r
470                 CWnd* GetDlgItem(int nIDDlgItem) const;\r
471                 UINT  GetDlgItemInt(int nIDDlgItem, BOOL* lpTranslated, BOOL bSigned) const;\r
472                 CString GetDlgItemText(int nIDDlgItem) const;\r
473                 CWnd* GetFocus() const;\r
474                 CFont* GetFont() const;\r
475                 HICON GetIcon(BOOL bBigIcon) const;\r
476                 CWnd* GetNextDlgGroupItem(CWnd* pCtl, BOOL bPrevious) const;\r
477                 CWnd* GetNextDlgTabItem(CWnd* pCtl, BOOL bPrevious) const;\r
478                 CWnd* GetParent() const;\r
479                 BOOL  GetScrollInfo(int fnBar, SCROLLINFO& si) const;\r
480                 CRect GetUpdateRect(BOOL bErase) const;\r
481                 int GetUpdateRgn(CRgn* pRgn, BOOL bErase) const;\r
482                 CWnd* GetWindow(UINT uCmd) const;\r
483                 CDC*  GetWindowDC() const;\r
484                 LONG_PTR GetWindowLongPtr(int nIndex) const;\r
485                 CRect GetWindowRect() const;\r
486                 CString GetWindowText() const;\r
487                 int   GetWindowTextLength() const;\r
488                 void  Invalidate(BOOL bErase = TRUE) const;\r
489                 BOOL  InvalidateRect(LPCRECT lpRect, BOOL bErase = TRUE) const;\r
490                 BOOL  InvalidateRgn(CRgn* pRgn, BOOL bErase = TRUE) const;\r
491                 BOOL  IsChild(CWnd* pChild) const;\r
492                 BOOL  IsDialogMessage(LPMSG lpMsg) const;\r
493                 UINT  IsDlgButtonChecked(int nIDButton) const;\r
494                 BOOL  IsWindow() const;\r
495                 BOOL  IsWindowEnabled() const;\r
496                 BOOL  IsWindowVisible() const;\r
497                 BOOL  KillTimer(UINT_PTR uIDEvent) const;\r
498                 int   MessageBox(LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) const;\r
499                 void  MapWindowPoints(CWnd* pWndTo, POINT& pt) const;\r
500                 void  MapWindowPoints(CWnd* pWndTo, RECT& rc) const;\r
501                 void  MapWindowPoints(CWnd* pWndTo, LPPOINT ptArray, UINT nCount) const;\r
502                 BOOL  MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE) const;\r
503                 BOOL  MoveWindow(const RECT& rc, BOOL bRepaint = TRUE) const;\r
504                 BOOL  PostMessage(UINT uMsg, WPARAM wParam = 0L, LPARAM lParam = 0L) const;\r
505                 BOOL  PostMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const;\r
506                 BOOL  RedrawWindow(LPCRECT lpRectUpdate = NULL, CRgn* pRgn = NULL, UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN) const;\r
507                 int   ReleaseDC(CDC* pDC) const;\r
508                 BOOL  ScreenToClient(POINT& Point) const;\r
509                 BOOL  ScreenToClient(RECT& rc) const;\r
510                 LRESULT SendDlgItemMessage(int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam) const;\r
511                 LRESULT SendMessage(UINT uMsg, WPARAM wParam = 0L, LPARAM lParam = 0L) const;\r
512                 LRESULT SendMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const;\r
513                 BOOL  SendNotifyMessage(UINT Msg, WPARAM wParam, LPARAM lParam) const;\r
514                 CWnd* SetActiveWindow() const;\r
515                 CWnd* SetCapture() const;\r
516                 ULONG_PTR SetClassLongPtr(int nIndex, LONG_PTR dwNewLong) const;\r
517                 BOOL  SetDlgItemInt(int nIDDlgItem, UINT uValue, BOOL bSigned) const;\r
518                 BOOL  SetDlgItemText(int nIDDlgItem, LPCTSTR lpString) const;\r
519                 CWnd* SetFocus() const;\r
520                 void  SetFont(CFont* pFont, BOOL bRedraw = TRUE) const;\r
521                 BOOL  SetForegroundWindow() const;\r
522                 HICON SetIcon(HICON hIcon, BOOL bBigIcon) const;\r
523                 CWnd* SetParent(CWnd* pWndParent) const;\r
524                 BOOL  SetRedraw(BOOL bRedraw = TRUE) const;\r
525                 int   SetScrollInfo(int fnBar, const SCROLLINFO& si, BOOL fRedraw) const;\r
526                 UINT_PTR SetTimer(UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc) const;\r
527                 LONG_PTR SetWindowLongPtr(int nIndex, LONG_PTR dwNewLong) const;\r
528                 BOOL  SetWindowPos(const CWnd* pInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const;\r
529                 BOOL  SetWindowPos(const CWnd* pInsertAfter, const RECT& rc, UINT uFlags) const;\r
530                 int   SetWindowRgn(CRgn* pRgn, BOOL bRedraw = TRUE) const;\r
531                 BOOL  SetWindowText(LPCTSTR lpString) const;\r
532                 HRESULT SetWindowTheme(LPCWSTR pszSubAppName, LPCWSTR pszSubIdList) const;\r
533                 BOOL  ShowWindow(int nCmdShow = SW_SHOWNORMAL) const;\r
534                 BOOL  UpdateWindow() const;\r
535                 BOOL  ValidateRect(LPCRECT prc) const;\r
536                 BOOL  ValidateRgn(CRgn* pRgn) const;\r
537                 static CWnd* WindowFromPoint(POINT pt);\r
538 \r
539   #ifndef _WIN32_WCE\r
540                 BOOL  CloseWindow() const;\r
541                 int   DlgDirList(LPTSTR lpPathSpec, int nIDListBox, int nIDStaticPath, UINT uFileType) const;\r
542                 int   DlgDirListComboBox(LPTSTR lpPathSpec, int nIDComboBox, int nIDStaticPath, UINT uFiletype) const;\r
543                 BOOL  DlgDirSelectEx(LPTSTR lpString, int nCount, int nIDListBox) const;\r
544                 BOOL  DlgDirSelectComboBoxEx(LPTSTR lpString, int nCount, int nIDComboBox) const;\r
545                 BOOL  DrawAnimatedRects(int idAni, RECT& rcFrom, RECT& rcTo) const;\r
546                 BOOL  DrawCaption(CDC* pDC, RECT& rc, UINT uFlags) const;\r
547                 BOOL  EnableScrollBar(UINT uSBflags, UINT uArrows) const;\r
548                 CWnd* GetLastActivePopup() const;\r
549                 CMenu* GetMenu() const;\r
550                 int   GetScrollPos(int nBar) const;\r
551                 BOOL  GetScrollRange(int nBar, int& MinPos, int& MaxPos) const;\r
552                 CMenu* GetSystemMenu(BOOL bRevert) const;\r
553                 CWnd* GetTopWindow() const;\r
554                 BOOL  GetWindowPlacement(WINDOWPLACEMENT& pWndpl) const;\r
555                 BOOL  HiliteMenuItem(CMenu* pMenu, UINT uItemHilite, UINT uHilite) const;\r
556                 BOOL  IsIconic() const;\r
557                 BOOL  IsZoomed() const;\r
558                 BOOL  LockWindowUpdate() const;\r
559                 BOOL  OpenIcon() const;\r
560                 void  Print(CDC* pDC, DWORD dwFlags) const;\r
561                 BOOL  SetMenu(CMenu* pMenu) const;\r
562                 BOOL  ScrollWindow(int XAmount, int YAmount, LPCRECT lprcScroll, LPCRECT lprcClip) const;\r
563                 int   ScrollWindowEx(int dx, int dy, LPCRECT lprcScroll, LPCRECT lprcClip, CRgn* prgnUpdate, LPRECT lprcUpdate, UINT flags) const;\r
564                 int   SetScrollPos(int nBar, int nPos, BOOL bRedraw) const;\r
565                 BOOL  SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw) const;\r
566                 BOOL  SetWindowPlacement(const WINDOWPLACEMENT& wndpl) const;\r
567                 BOOL  ShowOwnedPopups(BOOL fShow) const;\r
568                 BOOL  ShowScrollBar(int nBar, BOOL bShow) const;\r
569                 BOOL  ShowWindowAsync(int nCmdShow) const;\r
570                 BOOL  UnLockWindowUpdate() const;\r
571                 CWnd* WindowFromDC(CDC* pDC) const;\r
572 \r
573     #ifndef WIN32_LEAN_AND_MEAN\r
574                 void  DragAcceptFiles(BOOL fAccept) const;\r
575     #endif\r
576   #endif\r
577 \r
578                 static LRESULT CALLBACK StaticWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
579                 operator HWND() const { return m_hWnd; }\r
580 \r
581         protected:\r
582                 // Override these functions as required\r
583                 virtual LRESULT FinalWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
584                 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);\r
585                 virtual void OnCreate();\r
586                 virtual void OnDraw(CDC* pDC);\r
587                 virtual BOOL OnEraseBkgnd(CDC* pDC);\r
588                 virtual void OnInitialUpdate();\r
589                 virtual void OnMenuUpdate(UINT nID);\r
590                 virtual LRESULT OnMessageReflect(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
591                 virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);\r
592                 virtual LRESULT OnNotifyReflect(WPARAM wParam, LPARAM lParam);\r
593                 virtual void PreCreate(CREATESTRUCT& cs);\r
594                 virtual void PreRegisterClass(WNDCLASS& wc);\r
595                 virtual BOOL PreTranslateMessage(MSG* pMsg);\r
596                 virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
597                 virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
598 \r
599                 HWND m_hWnd;                                    // handle to this object's window\r
600 \r
601         private:\r
602                 CWnd(const CWnd&);                              // Disable copy construction\r
603                 CWnd& operator = (const CWnd&); // Disable assignment operator\r
604                 void AddToMap();\r
605                 void Cleanup();\r
606                 LRESULT MessageReflect(HWND hwndParent, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
607                 BOOL RegisterClass(WNDCLASS& wc);\r
608                 BOOL RemoveFromMap();\r
609                 void Subclass(HWND hWnd);\r
610 \r
611                 Shared_Ptr<WNDCLASS> m_pwc;             // defines initialisation parameters for PreRegisterClass\r
612                 Shared_Ptr<CREATESTRUCT> m_pcs; // defines initialisation parameters for PreCreate and Create\r
613                 WNDPROC m_PrevWindowProc;               // pre-subclassed Window Procedure\r
614                 BOOL m_IsTmpWnd;                                // True if this CWnd is a TmpWnd\r
615 \r
616         }; // class CWnd\r
617 \r
618         // Special CWnd objects used by SetWindowPos\r
619         static const CWnd wndTop(HWND_TOP);\r
620         static const CWnd wndTopMost(HWND_TOPMOST);\r
621         static const CWnd wndBottom(HWND_BOTTOM);\r
622         static const CWnd wndNoTopMost(HWND_NOTOPMOST);\r
623 }\r
624 \r
625 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
626 \r
627 #include "gdi.h"\r
628 #include "menu.h"\r
629 \r
630 namespace Win32xx\r
631 {\r
632 \r
633         //////////////////////////////////////////\r
634         // Definitions for the CWinException class\r
635         //\r
636         inline CWinException::CWinException(LPCTSTR pszText) throw () : m_Error(::GetLastError()), m_pszText(pszText)\r
637         {\r
638                 memset(m_szErrorString, 0, MAX_STRING_SIZE * sizeof(TCHAR));\r
639 \r
640                 if (m_Error != 0)\r
641                 {\r
642                         DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;\r
643                         ::FormatMessage(dwFlags, NULL, m_Error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), m_szErrorString, MAX_STRING_SIZE-1, NULL);\r
644                 }\r
645         }\r
646 \r
647         inline DWORD CWinException::GetError() const throw ()\r
648         {\r
649                 return m_Error;\r
650         }\r
651 \r
652         inline LPCTSTR CWinException::GetErrorString() const throw ()\r
653         {\r
654                 return m_szErrorString;\r
655         }\r
656 \r
657         inline const char * CWinException::what() const throw ()\r
658         {\r
659                 // Sends the last error string to the debugger (typically displayed in the IDE's output window).\r
660                 ::OutputDebugString(m_szErrorString);\r
661                 return "CWinException thrown";\r
662         }\r
663 \r
664 \r
665         ////////////////////////////////////\r
666         // Definitions for the CWinApp class\r
667         //\r
668 \r
669         // To begin Win32++, inherit your application class from this one.\r
670         // You must run only one instance of the class inherited from this.\r
671         inline CWinApp::CWinApp() : m_Callback(NULL), m_hAccel(0), m_pWndAccel(0)\r
672         {\r
673                 try\r
674                 {\r
675                         m_csAppStart.Lock();\r
676                         assert( 0 == SetnGetThis() );   // Test if this is the first instance of CWinApp\r
677 \r
678                         m_dwTlsIndex = ::TlsAlloc();\r
679                         if (m_dwTlsIndex == TLS_OUT_OF_INDEXES)\r
680                         {\r
681                                 // We only get here in the unlikely event that all TLS indexes are already allocated by this app\r
682                                 // At least 64 TLS indexes per process are allowed. Win32++ requires only one TLS index.\r
683                                 m_csAppStart.Release();\r
684                                 throw CWinException(_T("CWinApp::CWinApp  Failed to allocate TLS Index"));\r
685                         }\r
686 \r
687                         SetnGetThis(this);\r
688                         m_csAppStart.Release();\r
689 \r
690                         // Set the instance handle\r
691         #ifdef _WIN32_WCE\r
692                         m_hInstance = (HINSTANCE)GetModuleHandle(0);\r
693         #else\r
694                         MEMORY_BASIC_INFORMATION mbi = {0};\r
695                         VirtualQuery( (LPCVOID)SetnGetThis, &mbi, sizeof(mbi) );\r
696                         assert(mbi.AllocationBase);\r
697                         m_hInstance = (HINSTANCE)mbi.AllocationBase;\r
698         #endif\r
699 \r
700                         m_hResource = m_hInstance;\r
701                         SetCallback();\r
702 \r
703                         // Assign the special CWnds used by SetWindowPos\r
704                         m_csMapLock.Lock();\r
705                         m_mapHWND.insert(std::make_pair(HWND_TOP, (CWnd*)&wndTop));\r
706                         m_mapHWND.insert(std::make_pair(HWND_TOPMOST, (CWnd*)&wndTopMost));\r
707                         m_mapHWND.insert(std::make_pair(HWND_NOTOPMOST, (CWnd*)&wndNoTopMost));\r
708                         m_mapHWND.insert(std::make_pair(HWND_BOTTOM, (CWnd*)&wndBottom));\r
709                         GetApp()->m_csMapLock.Release();\r
710                 }\r
711 \r
712                 catch (const CWinException &e)\r
713                 {\r
714                         e.what();\r
715                         throw;\r
716                 }\r
717         }\r
718 \r
719         inline CWinApp::~CWinApp()\r
720         {\r
721                 std::vector<TLSDataPtr>::iterator iter;\r
722                 for (iter = m_vTLSData.begin(); iter < m_vTLSData.end(); ++iter)\r
723                 {\r
724                         (*iter)->vTmpDCs.clear();\r
725 #ifndef _WIN32_WCE\r
726                         (*iter)->vTmpMenus.clear();\r
727 #endif\r
728                         (*iter)->vTmpWnds.clear();\r
729                 }\r
730 \r
731                 // Check that all CWnd windows are destroyed\r
732                 std::map<HWND, CWnd*, CompareHWND>::iterator m;\r
733                 for (m = m_mapHWND.begin(); m != m_mapHWND.end(); ++m)\r
734                 {\r
735                         HWND hWnd = (*m).first;\r
736                         if (::IsWindow(hWnd))\r
737                                 ::DestroyWindow(hWnd);\r
738                 }\r
739                 m_mapHWND.clear();\r
740                 m_mapGDI.clear();\r
741                 m_mapHDC.clear();\r
742                 m_mapHMENU.clear();\r
743 \r
744                 // Do remaining tidy up\r
745                 if (m_dwTlsIndex != TLS_OUT_OF_INDEXES)\r
746                 {\r
747                         ::TlsSetValue(GetTlsIndex(), NULL);\r
748                         ::TlsFree(m_dwTlsIndex);\r
749                 }\r
750 \r
751                 SetnGetThis((CWinApp*)-1);\r
752         }\r
753 \r
754         inline void CWinApp::AddTmpDC(CDC* pDC)\r
755         {\r
756                 // The TmpMenus are created by GetSybMenu.\r
757                 // They are removed by CleanupTemps\r
758                 assert(pDC);\r
759 \r
760                 // Ensure this thread has the TLS index set\r
761                 TLSData* pTLSData = GetApp()->SetTlsIndex();\r
762                 pTLSData->vTmpDCs.push_back(pDC); // save pDC as a smart pointer\r
763         }\r
764 \r
765         inline void CWinApp::AddTmpGDI(CGDIObject* pObject)\r
766         {\r
767                 // The temporary CGDIObjects are removed by CleanupTemps\r
768                 assert(pObject);\r
769 \r
770                 // Ensure this thread has the TLS index set\r
771                 TLSData* pTLSData = GetApp()->SetTlsIndex();\r
772                 pTLSData->vTmpGDIs.push_back(pObject); // save pObject as a smart pointer\r
773         }\r
774 \r
775 #ifndef _WIN32_WCE\r
776         inline CMenu* CWinApp::AddTmpMenu(HMENU hMenu)\r
777         {\r
778                 // The TmpMenus are created by GetSybMenu.\r
779                 // They are removed by CleanupTemps\r
780                 assert(::IsMenu(hMenu));\r
781                 assert(!GetCMenuFromMap(hMenu));\r
782 \r
783                 CMenu* pMenu = new CMenu;\r
784                 pMenu->m_hMenu = hMenu;\r
785                 m_csMapLock.Lock();\r
786                 m_mapHMENU.insert(std::make_pair(hMenu, pMenu));\r
787                 m_csMapLock.Release();\r
788                 pMenu->m_IsTmpMenu = TRUE;\r
789 \r
790                 // Ensure this thread has the TLS index set\r
791                 TLSData* pTLSData = GetApp()->SetTlsIndex();\r
792                 pTLSData->vTmpMenus.push_back(pMenu); // save pMenu as a smart pointer\r
793                 return pMenu;\r
794         }\r
795 #endif\r
796 \r
797         inline CWnd* CWinApp::AddTmpWnd(HWND hWnd)\r
798         {\r
799                 // TmpWnds are created if required to support functions like CWnd::GetParent.\r
800                 // They are removed by CleanupTemps\r
801         //      assert(::IsWindow(hWnd));\r
802                 assert(!GetCWndFromMap(hWnd));\r
803 \r
804                 CWnd* pWnd = new CWnd;\r
805                 pWnd->m_hWnd = hWnd;\r
806                 pWnd->AddToMap();\r
807                 pWnd->m_IsTmpWnd = TRUE;\r
808 \r
809                 // Ensure this thread has the TLS index set\r
810                 TLSData* pTLSData = GetApp()->SetTlsIndex();\r
811                 pTLSData->vTmpWnds.push_back(pWnd); // save pWnd as a smart pointer\r
812                 return pWnd;\r
813         }\r
814 \r
815         inline void CWinApp::CleanupTemps()\r
816         // Removes all Temporary CWnds and CMenus belonging to this thread\r
817         {\r
818                 // Retrieve the pointer to the TLS Data\r
819                 TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());\r
820                 assert(pTLSData);\r
821 \r
822                 pTLSData->vTmpDCs.clear();\r
823                 pTLSData->vTmpGDIs.clear();\r
824                 pTLSData->vTmpWnds.clear();\r
825 \r
826 \r
827         #ifndef _WIN32_WCE\r
828                 pTLSData->vTmpMenus.clear();\r
829         #endif\r
830         }\r
831 \r
832         inline CDC* CWinApp::GetCDCFromMap(HDC hDC)\r
833         {\r
834                 // Allocate an iterator for our HWND map\r
835                 std::map<HDC, CDC*, CompareHDC>::iterator m;\r
836 \r
837                 // Find the CDC pointer mapped to this HDC\r
838                 CDC* pDC = 0;\r
839                 m_csMapLock.Lock();\r
840                 m = m_mapHDC.find(hDC);\r
841 \r
842                 if (m != m_mapHDC.end())\r
843                         pDC = m->second;\r
844 \r
845                 m_csMapLock.Release();\r
846                 return pDC;\r
847         }\r
848 \r
849         inline CGDIObject* CWinApp::GetCGDIObjectFromMap(HGDIOBJ hObject)\r
850         {\r
851                 // Allocate an iterator for our HWND map\r
852                 std::map<HGDIOBJ, CGDIObject*, CompareGDI>::iterator m;\r
853 \r
854                 // Find the CGDIObject pointer mapped to this HGDIOBJ\r
855                 CGDIObject* pObject = 0;\r
856                 m_csMapLock.Lock();\r
857                 m = m_mapGDI.find(hObject);\r
858 \r
859                 if (m != m_mapGDI.end())\r
860                         pObject = m->second;\r
861 \r
862                 m_csMapLock.Release();\r
863                 return pObject;\r
864         }\r
865 \r
866         inline CMenu* CWinApp::GetCMenuFromMap(HMENU hMenu)\r
867         {\r
868                 std::map<HMENU, CMenu*, CompareHMENU>::iterator m;\r
869 \r
870                 // Find the CMenu pointer mapped to this HMENU\r
871                 CMenu* pMenu = 0;\r
872                 m_csMapLock.Lock();\r
873                 m = m_mapHMENU.find(hMenu);\r
874 \r
875                 if (m != m_mapHMENU.end())\r
876                         pMenu = m->second;\r
877 \r
878                 m_csMapLock.Release();\r
879                 return pMenu;\r
880         }\r
881 \r
882         inline CWnd* CWinApp::GetCWndFromMap(HWND hWnd)\r
883         {\r
884                 // Allocate an iterator for our HWND map\r
885                 std::map<HWND, CWnd*, CompareHWND>::iterator m;\r
886 \r
887                 // Find the CWnd pointer mapped to this HWND\r
888                 CWnd* pWnd = 0;\r
889                 m_csMapLock.Lock();\r
890                 m = m_mapHWND.find(hWnd);\r
891 \r
892                 if (m != m_mapHWND.end())\r
893                         pWnd = m->second;\r
894 \r
895                 m_csMapLock.Release();\r
896                 return pWnd;\r
897         }\r
898 \r
899         inline BOOL CWinApp::InitInstance()\r
900         {\r
901                 // InitInstance contains the initialization code for your application\r
902                 // You should override this function with the code to run when the application starts.\r
903 \r
904                 // return TRUE to indicate success. FALSE will end the application\r
905                 return TRUE;\r
906         }\r
907 \r
908         inline int CWinApp::MessageLoop()\r
909         {\r
910                 // This gets any messages queued for the application, and dispatches them.\r
911                 MSG Msg = {0};\r
912                 int status = 1;\r
913                 LONG lCount = 0;\r
914 \r
915                 while (status != 0)\r
916                 {\r
917                         // While idle, perform idle processing until OnIdle returns FALSE\r
918                         while (!::PeekMessage(&Msg, 0, 0, 0, PM_NOREMOVE) && OnIdle(lCount) == TRUE)\r
919                         {\r
920                                 ++lCount;\r
921                         }\r
922 \r
923                         lCount = 0;\r
924 \r
925                         // Now wait until we get a message\r
926                         if ((status = ::GetMessage(&Msg, NULL, 0, 0)) == -1)\r
927                                 return -1;\r
928 \r
929                         if (!PreTranslateMessage(Msg))\r
930                         {\r
931                                 ::TranslateMessage(&Msg);\r
932                                 ::DispatchMessage(&Msg);\r
933                         }\r
934                 }\r
935 \r
936                 return LOWORD(Msg.wParam);\r
937         }\r
938 \r
939         inline BOOL CWinApp::OnIdle(LONG lCount)\r
940         {\r
941                 if (lCount == 0)\r
942                         CleanupTemps();\r
943 \r
944                 return FALSE;\r
945         }\r
946 \r
947         inline BOOL CWinApp::PreTranslateMessage(MSG Msg)\r
948         {\r
949                 // This functions is called by the MessageLoop. It processes the\r
950                 // keyboard accelerator keys and calls CWnd::PreTranslateMessage for\r
951                 // keyboard and mouse events.\r
952 \r
953                 BOOL Processed = FALSE;\r
954 \r
955                 // only pre-translate mouse and keyboard input events\r
956                 if ((Msg.message >= WM_KEYFIRST && Msg.message <= WM_KEYLAST) ||\r
957                         (Msg.message >= WM_MOUSEFIRST && Msg.message <= WM_MOUSELAST))\r
958                 {\r
959                         // Process keyboard accelerators\r
960                         if (m_pWndAccel && ::TranslateAccelerator(*m_pWndAccel, m_hAccel, &Msg))\r
961                                 Processed = TRUE;\r
962                         else\r
963                         {\r
964                                 // Search the chain of parents for pretranslated messages.\r
965                                 for (HWND hWnd = Msg.hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd))\r
966                                 {\r
967                                         CWnd* pWnd = GetCWndFromMap(hWnd);\r
968                                         if (pWnd)\r
969                                         {\r
970                                                 Processed = pWnd->PreTranslateMessage(&Msg);\r
971                                                 if(Processed)\r
972                                                         break;\r
973                                         }\r
974                                 }\r
975                         }\r
976                 }\r
977 \r
978                 return Processed;\r
979         }\r
980 \r
981         inline int CWinApp::Run()\r
982         {\r
983                 // InitInstance runs the App's initialization code\r
984                 if (InitInstance())\r
985                 {\r
986                         // Dispatch the window messages\r
987                         return MessageLoop();\r
988                 }\r
989                 else\r
990                 {\r
991                         TRACE(_T("InitInstance failed!  Terminating program\n"));\r
992                         ::PostQuitMessage(-1);\r
993                         return -1;\r
994                 }\r
995         }\r
996 \r
997         inline void CWinApp::SetAccelerators(HACCEL hAccel, CWnd* pWndAccel)\r
998         // nID is the resource ID of the accelerator table\r
999         // pWndAccel is the window pointer for translated messages\r
1000         {\r
1001                 assert (hAccel);\r
1002                 assert (pWndAccel);\r
1003 \r
1004                 m_pWndAccel = pWndAccel;\r
1005                 m_hAccel = hAccel;\r
1006         }\r
1007 \r
1008         inline void CWinApp::SetCallback()\r
1009         {\r
1010                 // Registers a temporary window class so we can get the callback\r
1011                 // address of CWnd::StaticWindowProc.\r
1012                 // This technique works for all Window versions, including WinCE.\r
1013 \r
1014                 WNDCLASS wcDefault = {0};\r
1015 \r
1016                 LPCTSTR szClassName             = _T("Win32++ Temporary Window Class");\r
1017                 wcDefault.hInstance             = GetInstanceHandle();\r
1018                 wcDefault.lpfnWndProc   = CWnd::StaticWindowProc;\r
1019                 wcDefault.lpszClassName = szClassName;\r
1020 \r
1021                 ::RegisterClass(&wcDefault);\r
1022 \r
1023                 // Retrieve the class information\r
1024                 ZeroMemory(&wcDefault, sizeof(wcDefault));\r
1025                 ::GetClassInfo(GetInstanceHandle(), szClassName, &wcDefault);\r
1026 \r
1027                 // Save the callback address of CWnd::StaticWindowProc\r
1028                 assert(wcDefault.lpfnWndProc);  // Assert fails when running UNICODE build on ANSI OS.\r
1029                 m_Callback = wcDefault.lpfnWndProc;\r
1030                 ::UnregisterClass(szClassName, GetInstanceHandle());\r
1031         }\r
1032 \r
1033         inline CWinApp* CWinApp::SetnGetThis(CWinApp* pThis /*= 0*/)\r
1034         {\r
1035                 // This function stores the 'this' pointer in a static variable.\r
1036                 // Once stored, it can be used later to return the 'this' pointer.\r
1037                 // CWinApp's Destructor calls this function with a value of -1.\r
1038 \r
1039                 static CWinApp* pWinApp = 0;\r
1040 \r
1041                 if ((CWinApp*)-1 == pThis)\r
1042                         pWinApp = 0;\r
1043                 else if (0 == pWinApp)\r
1044                         pWinApp = pThis;\r
1045 \r
1046                 return pWinApp;\r
1047         }\r
1048 \r
1049         inline void CWinApp::SetResourceHandle(HINSTANCE hResource)\r
1050         {\r
1051                 // This function can be used to load a resource dll.\r
1052                 // A resource dll can be used to define resources in different languages.\r
1053                 // To use this function, place code like this in InitInstance\r
1054                 //\r
1055                 // HINSTANCE hResource = LoadLibrary(_T("MyResourceDLL.dll"));\r
1056                 // SetResourceHandle(hResource);\r
1057 \r
1058                 m_hResource = hResource;\r
1059         }\r
1060 \r
1061         inline TLSData* CWinApp::SetTlsIndex()\r
1062         {\r
1063                 TLSData* pTLSData = (TLSData*)::TlsGetValue(GetTlsIndex());\r
1064                 if (NULL == pTLSData)\r
1065                 {\r
1066                         pTLSData = new TLSData;\r
1067 \r
1068                         m_csTLSLock.Lock();\r
1069                         m_vTLSData.push_back(pTLSData); // store as a Shared_Ptr\r
1070                         m_csTLSLock.Release();\r
1071 \r
1072                         ::TlsSetValue(GetTlsIndex(), pTLSData);\r
1073                 }\r
1074 \r
1075                 return pTLSData;\r
1076         }\r
1077 \r
1078 \r
1079         ////////////////////////////////////////\r
1080         // Definitions for the CWnd class\r
1081         //\r
1082         inline CWnd::CWnd() : m_hWnd(NULL), m_PrevWindowProc(NULL), m_IsTmpWnd(FALSE)\r
1083         {\r
1084                 // Note: m_hWnd is set in CWnd::CreateEx(...)\r
1085                 m_pcs = new CREATESTRUCT;       // store the CREATESTRICT in a smart pointer\r
1086                 m_pwc = new WNDCLASS;           // store the WNDCLASS in a smart pointer\r
1087                 ::ZeroMemory(m_pcs.get(), sizeof(CREATESTRUCT));\r
1088                 ::ZeroMemory(m_pwc.get(), sizeof(WNDCLASS));\r
1089         }\r
1090 \r
1091         inline CWnd::~CWnd()\r
1092         {\r
1093                 // Destroys the window for this object and cleans up resources.\r
1094                 Destroy();\r
1095         }\r
1096 \r
1097         inline void CWnd::AddToMap()\r
1098         // Store the window handle and CWnd pointer in the HWND map\r
1099         {\r
1100                 assert( GetApp() );\r
1101                 GetApp()->m_csMapLock.Lock();\r
1102 \r
1103         //      assert(::IsWindow(m_hWnd));\r
1104                 assert(!GetApp()->GetCWndFromMap(m_hWnd));\r
1105 \r
1106                 GetApp()->m_mapHWND.insert(std::make_pair(m_hWnd, this));\r
1107                 GetApp()->m_csMapLock.Release();\r
1108         }\r
1109 \r
1110         inline BOOL CWnd::Attach(HWND hWnd)\r
1111         // Subclass an existing window and attach it to a CWnd\r
1112         {\r
1113                 assert( GetApp() );\r
1114                 assert(::IsWindow(hWnd));\r
1115 \r
1116                 // Ensure this thread has the TLS index set\r
1117                 // Note: Perform the attach from the same thread as the window's message loop\r
1118                 GetApp()->SetTlsIndex();\r
1119 \r
1120                 // Cleanup any previous attachment\r
1121                 if (m_PrevWindowProc)\r
1122                         Detach();\r
1123                 CWnd* pWnd = GetApp()->GetCWndFromMap(hWnd);\r
1124                 if (pWnd)\r
1125                         pWnd->Cleanup();\r
1126 \r
1127                 Subclass(hWnd);         // Set the window's callback to CWnd::StaticWindowProc\r
1128                 AddToMap();                     // Store the CWnd pointer in the HWND map\r
1129                 OnCreate();\r
1130                 OnInitialUpdate();\r
1131 \r
1132                 return TRUE;\r
1133         }\r
1134 \r
1135         inline BOOL CWnd::AttachDlgItem(UINT nID, CWnd* pParent)\r
1136         // Converts a dialog item to a CWnd object\r
1137         {\r
1138                 assert(pParent->IsWindow());\r
1139 \r
1140                 HWND hWnd = ::GetDlgItem(pParent->GetHwnd(), nID);\r
1141                 return Attach(hWnd);\r
1142         }\r
1143 \r
1144         inline void CWnd::CenterWindow() const\r
1145         // Centers this window over it's parent\r
1146         {\r
1147 \r
1148         // required for multi-monitor support with Dev-C++ and VC6\r
1149         #ifndef _WIN32_WCE\r
1150         #ifndef MONITOR_DEFAULTTONEAREST\r
1151                 #define MONITOR_DEFAULTTONEAREST    0x00000002\r
1152         #endif\r
1153         #ifndef HMONITOR\r
1154                 DECLARE_HANDLE(HMONITOR);\r
1155         #endif\r
1156         #ifndef MONITORINFO\r
1157                 typedef struct tagMONITORINFO\r
1158                 {\r
1159                         DWORD   cbSize;\r
1160                         RECT    rcMonitor;\r
1161                         RECT    rcWork;\r
1162                         DWORD   dwFlags;\r
1163                 } MONITORINFO, *LPMONITORINFO;\r
1164         #endif  // MONITOR_DEFAULTTONEAREST\r
1165         #endif  // _WIN32_WCE\r
1166 \r
1167                 assert(::IsWindow(m_hWnd));\r
1168 \r
1169                 CRect rc = GetWindowRect();\r
1170                 CRect rcParent;\r
1171                 CRect rcDesktop;\r
1172 \r
1173                 // Get screen dimensions excluding task bar\r
1174                 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesktop, 0);\r
1175 \r
1176                 // Get the parent window dimensions (parent could be the desktop)\r
1177                 if (GetParent() != NULL) rcParent = GetParent()->GetWindowRect();\r
1178                 else rcParent = rcDesktop;\r
1179 \r
1180         #ifndef _WIN32_WCE\r
1181                 // Import the GetMonitorInfo and MonitorFromWindow functions\r
1182                 HMODULE hUser32 = LoadLibrary(_T("USER32.DLL"));\r
1183                 typedef BOOL (WINAPI* LPGMI)(HMONITOR hMonitor, LPMONITORINFO lpmi);\r
1184                 typedef HMONITOR (WINAPI* LPMFW)(HWND hwnd, DWORD dwFlags);\r
1185                 LPMFW pfnMonitorFromWindow = (LPMFW)::GetProcAddress(hUser32, "MonitorFromWindow");\r
1186         #ifdef _UNICODE\r
1187                 LPGMI pfnGetMonitorInfo = (LPGMI)::GetProcAddress(hUser32, "GetMonitorInfoW");\r
1188         #else\r
1189                 LPGMI pfnGetMonitorInfo = (LPGMI)::GetProcAddress(hUser32, "GetMonitorInfoA");\r
1190         #endif\r
1191 \r
1192                 // Take multi-monitor systems into account\r
1193                 if (pfnGetMonitorInfo && pfnMonitorFromWindow)\r
1194                 {\r
1195                         HMONITOR hActiveMonitor = pfnMonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);\r
1196                         MONITORINFO mi = { sizeof(mi), 0};\r
1197 \r
1198                         if(pfnGetMonitorInfo(hActiveMonitor, &mi))\r
1199                         {\r
1200                                 rcDesktop = mi.rcWork;\r
1201                                 if (GetParent() == NULL) rcParent = mi.rcWork;\r
1202                         }\r
1203                 }\r
1204                 FreeLibrary(hUser32);\r
1205   #endif\r
1206 \r
1207                 // Calculate point to center the dialog over the portion of parent window on this monitor\r
1208                 rcParent.IntersectRect(rcParent, rcDesktop);\r
1209                 int x = rcParent.left + (rcParent.Width() - rc.Width())/2;\r
1210                 int y = rcParent.top + (rcParent.Height() - rc.Height())/2;\r
1211 \r
1212                 // Keep the dialog wholly on the monitor display\r
1213                 x = (x < rcDesktop.left)? rcDesktop.left : x;\r
1214                 x = (x > rcDesktop.right - rc.Width())? rcDesktop.right - rc.Width() : x;\r
1215                 y = (y < rcDesktop.top) ? rcDesktop.top: y;\r
1216                 y = (y > rcDesktop.bottom - rc.Height())? rcDesktop.bottom - rc.Height() : y;\r
1217 \r
1218                 SetWindowPos(0, x, y, 0, 0, SWP_NOSIZE);\r
1219         }\r
1220 \r
1221         inline void CWnd::Cleanup()\r
1222         // Returns the CWnd to its default state\r
1223         {\r
1224                 if ( GetApp() ) RemoveFromMap();\r
1225                 m_hWnd = NULL;\r
1226                 m_PrevWindowProc = NULL;\r
1227                 m_IsTmpWnd = FALSE;\r
1228         }\r
1229 \r
1230         inline HWND CWnd::Create(CWnd* pParent /* = NULL */)\r
1231         // Creates the window. This is the default method of window creation.\r
1232         {\r
1233 \r
1234                 // Test if Win32++ has been started\r
1235                 assert( GetApp() );\r
1236 \r
1237                 // Set the WNDCLASS parameters\r
1238                 PreRegisterClass(*m_pwc);\r
1239                 if (m_pwc->lpszClassName)\r
1240                 {\r
1241                         RegisterClass(*m_pwc);\r
1242                         m_pcs->lpszClass = m_pwc->lpszClassName;\r
1243                 }\r
1244 \r
1245                 // Set the CREATESTRUCT parameters\r
1246                 PreCreate(*m_pcs);\r
1247 \r
1248                 // Set the Window Class Name\r
1249                 if (!m_pcs->lpszClass)\r
1250                         m_pcs->lpszClass = _T("Win32++ Window");\r
1251 \r
1252                 // Set Parent\r
1253                 HWND hWndParent = pParent? pParent->GetHwnd() : 0;\r
1254                 if (!hWndParent && m_pcs->hwndParent)\r
1255                         hWndParent = m_pcs->hwndParent;\r
1256 \r
1257                 // Set the window style\r
1258                 DWORD dwStyle;\r
1259                 DWORD dwOverlappedStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;\r
1260                 if (m_pcs->style)\r
1261                         dwStyle = m_pcs->style;\r
1262                 else\r
1263                         dwStyle = WS_VISIBLE | ((hWndParent)? WS_CHILD : dwOverlappedStyle);\r
1264 \r
1265                 // Set window size and position\r
1266                 int x  = (m_pcs->cx || m_pcs->cy)? m_pcs->x  : CW_USEDEFAULT;\r
1267                 int cx = (m_pcs->cx || m_pcs->cy)? m_pcs->cx : CW_USEDEFAULT;\r
1268                 int y  = (m_pcs->cx || m_pcs->cy)? m_pcs->y  : CW_USEDEFAULT;\r
1269                 int cy = (m_pcs->cx || m_pcs->cy)? m_pcs->cy : CW_USEDEFAULT;\r
1270 \r
1271                 // Create the window\r
1272 #ifndef _WIN32_WCE\r
1273                 CreateEx(m_pcs->dwExStyle, m_pcs->lpszClass, m_pcs->lpszName, dwStyle, x, y,\r
1274                                 cx, cy, pParent, FromHandle(m_pcs->hMenu), m_pcs->lpCreateParams);\r
1275 #else\r
1276                 CreateEx(m_pcs->dwExStyle, m_pcs->lpszClass, m_pcs->lpszName, dwStyle, x, y,\r
1277                                 cx, cy, pParent, 0, m_pcs->lpCreateParams);\r
1278 #endif\r
1279 \r
1280                 return m_hWnd;\r
1281         }\r
1282 \r
1283         inline HWND CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rc, CWnd* pParent, CMenu* pMenu, LPVOID lpParam /*= NULL*/)\r
1284         // Creates the window by specifying all the window creation parameters\r
1285         {\r
1286                 int x = rc.left;\r
1287                 int y = rc.top;\r
1288                 int cx = rc.right - rc.left;\r
1289                 int cy = rc.bottom - rc.top;\r
1290                 return CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle, x, y, cx, cy, pParent, pMenu, lpParam);\r
1291         }\r
1292 \r
1293         inline HWND CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, CWnd* pParent, CMenu* pMenu, LPVOID lpParam /*= NULL*/)\r
1294         // Creates the window by specifying all the window creation parameters\r
1295         {\r
1296 \r
1297                 assert( GetApp() );             // Test if Win32++ has been started\r
1298                 assert(!::IsWindow(m_hWnd));    // Only one window per CWnd instance allowed\r
1299 \r
1300                 try\r
1301                 {\r
1302                         // Prepare the CWnd if it has been reused\r
1303                         Destroy();\r
1304 \r
1305                         // Ensure a window class is registered\r
1306                         std::vector<TCHAR> vTChar( MAX_STRING_SIZE+1, _T('\0') );\r
1307                         TCHAR* ClassName = &vTChar[0];\r
1308                         if (0 == lpszClassName || 0 == lstrlen(lpszClassName) )\r
1309                                 lstrcpyn (ClassName, _T("Win32++ Window"), MAX_STRING_SIZE);\r
1310                         else\r
1311                                 // Create our own local copy of szClassName.\r
1312                                 lstrcpyn(ClassName, lpszClassName, MAX_STRING_SIZE);\r
1313 \r
1314                         WNDCLASS wc = {0};\r
1315                         wc.lpszClassName = ClassName;\r
1316                         wc.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);\r
1317                         wc.hCursor               = ::LoadCursor(NULL, IDC_ARROW);\r
1318 \r
1319                         // Register the window class (if not already registered)\r
1320                         if (!RegisterClass(wc))\r
1321                                 throw CWinException(_T("Failed to register window class"));\r
1322 \r
1323                         HWND hWndParent = pParent? pParent->GetHwnd() : 0;\r
1324 \r
1325                         // Ensure this thread has the TLS index set\r
1326                         TLSData* pTLSData = GetApp()->SetTlsIndex();\r
1327 \r
1328                         // Store the CWnd pointer in thread local storage\r
1329                         pTLSData->pCWnd = this;\r
1330 \r
1331                         // Create window\r
1332 #ifdef _WIN32_WCE\r
1333                         m_hWnd = ::CreateWindowEx(dwExStyle, ClassName, lpszWindowName, dwStyle, x, y, nWidth, nHeight,\r
1334                                                                         hWndParent, 0, GetApp()->GetInstanceHandle(), lpParam);\r
1335 #else\r
1336                         HMENU hMenu = pMenu? pMenu->GetHandle() : NULL;\r
1337                         m_hWnd = ::CreateWindowEx(dwExStyle, ClassName, lpszWindowName, dwStyle, x, y, nWidth, nHeight,\r
1338                                                                         hWndParent, hMenu, GetApp()->GetInstanceHandle(), lpParam);\r
1339 #endif\r
1340 \r
1341                         // Now handle window creation failure\r
1342                         if (!m_hWnd)\r
1343                                 throw CWinException(_T("Failed to Create Window"));\r
1344 \r
1345                         // Automatically subclass predefined window class types\r
1346                         ::GetClassInfo(GetApp()->GetInstanceHandle(), lpszClassName, &wc);\r
1347                         if (wc.lpfnWndProc != GetApp()->m_Callback)\r
1348                         {\r
1349                                 Subclass(m_hWnd);\r
1350 \r
1351                                 // Send a message to force the HWND to be added to the map\r
1352                                 SendMessage(WM_NULL, 0L, 0L);\r
1353 \r
1354                                 OnCreate(); // We missed the WM_CREATE message, so call OnCreate now\r
1355                         }\r
1356 \r
1357                         // Clear the CWnd pointer from TLS\r
1358                         pTLSData->pCWnd = NULL;\r
1359                 }\r
1360 \r
1361                 catch (const CWinException &e)\r
1362                 {\r
1363                         TRACE(_T("\n*** Failed to create window ***\n"));\r
1364                         e.what();       // Display the last error message.\r
1365 \r
1366                         // eat the exception (don't rethrow)\r
1367                 }\r
1368 \r
1369                 // Window creation is complete. Now call OnInitialUpdate\r
1370                 OnInitialUpdate();\r
1371 \r
1372                 return m_hWnd;\r
1373         }\r
1374 \r
1375         inline void CWnd::Destroy()\r
1376         // Destroys the window and returns the CWnd back to its default state, ready for reuse.\r
1377         {\r
1378                 if (m_IsTmpWnd)\r
1379                         m_hWnd = NULL;\r
1380 \r
1381                 if (IsWindow())\r
1382                         ::DestroyWindow(m_hWnd);\r
1383 \r
1384                 // Return the CWnd to its default state\r
1385                 Cleanup();\r
1386         }\r
1387 \r
1388         inline HWND CWnd::Detach()\r
1389         // Reverse an Attach\r
1390         {\r
1391                 assert(::IsWindow(m_hWnd));\r
1392                 assert(0 != m_PrevWindowProc);  // Only a subclassed window can be detached\r
1393 \r
1394                 SetWindowLongPtr(GWLP_WNDPROC, (LONG_PTR)m_PrevWindowProc);\r
1395                 HWND hWnd = m_hWnd;\r
1396                 Cleanup();\r
1397 \r
1398                 return hWnd;\r
1399         }\r
1400 \r
1401         inline LRESULT CWnd::FinalWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
1402         // Pass messages on to the appropriate default window procedure\r
1403         // CMDIChild and CMDIFrame override this function\r
1404         {\r
1405                 return ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);\r
1406         }\r
1407 \r
1408         inline CWnd* CWnd::GetAncestor(UINT gaFlags /*= GA_ROOTOWNER*/) const\r
1409         // The GetAncestor function retrieves a pointer to the ancestor (root parent)\r
1410         // of the window. Supports Win95.\r
1411         {\r
1412                 assert(::IsWindow(m_hWnd));\r
1413                 HWND hWnd = m_hWnd;\r
1414 \r
1415                 // Load the User32 DLL\r
1416                 typedef HWND WINAPI GETANCESTOR(HWND, UINT);\r
1417                 GETANCESTOR* pfnGetAncestor = NULL;\r
1418                 HMODULE hModule = ::LoadLibrary(_T("USER32.DLL"));\r
1419 \r
1420                 if (hModule)\r
1421                 {\r
1422                         // Declare a pointer to the GetAncestor function\r
1423 #ifndef _WIN32_WCE\r
1424                         pfnGetAncestor = (GETANCESTOR*)::GetProcAddress(hModule, "GetAncestor");\r
1425 #else\r
1426                         pfnGetAncestor = (GETANCESTOR*)::GetProcAddress(hModule, L"GetAncestor");\r
1427 #endif\r
1428 \r
1429                         if (pfnGetAncestor)\r
1430                                 hWnd = (*pfnGetAncestor)(m_hWnd, gaFlags);\r
1431 \r
1432                         ::FreeLibrary(hModule);\r
1433                 }\r
1434 \r
1435                 if (!pfnGetAncestor)\r
1436                 {\r
1437                         // Provide our own GetAncestor if necessary\r
1438                         HWND hWndParent = ::GetParent(hWnd);\r
1439                         while (::IsChild(hWndParent, hWnd))\r
1440                         {\r
1441                                 hWnd = hWndParent;\r
1442                                 hWndParent = ::GetParent(hWnd);\r
1443                         }\r
1444                 }\r
1445 \r
1446                 return FromHandle(hWnd);\r
1447         }\r
1448 \r
1449         inline CString CWnd::GetClassName() const\r
1450         // Retrieves the name of the class to which the specified window belongs.\r
1451         {\r
1452                 assert(::IsWindow(m_hWnd));\r
1453 \r
1454                 CString str;\r
1455                 LPTSTR szStr = str.GetBuffer(MAX_STRING_SIZE+1);\r
1456                 ::GetClassName(m_hWnd, szStr, MAX_STRING_SIZE+1);\r
1457                 str.ReleaseBuffer();\r
1458                 return str;\r
1459         }\r
1460 \r
1461         inline CString CWnd::GetDlgItemText(int nIDDlgItem) const\r
1462         // Retrieves the title or text associated with a control in a dialog box.\r
1463         {\r
1464                 assert(::IsWindow(m_hWnd));\r
1465 \r
1466                 int nLength = ::GetWindowTextLength(::GetDlgItem(m_hWnd, nIDDlgItem));\r
1467                 CString str;\r
1468                 LPTSTR szStr = str.GetBuffer(nLength+1);\r
1469                 ::GetDlgItemText(m_hWnd, nIDDlgItem, szStr, nLength+1);\r
1470                 str.ReleaseBuffer();\r
1471                 return str;\r
1472         }\r
1473 \r
1474         inline CString CWnd::GetWindowText() const\r
1475         // Retrieves the text of the window's title bar.\r
1476         {\r
1477                 assert(::IsWindow(m_hWnd));\r
1478 \r
1479                 int nLength = ::GetWindowTextLength(m_hWnd);\r
1480                 CString str;\r
1481                 LPTSTR szStr = str.GetBuffer(nLength+1);\r
1482                 ::GetWindowText(m_hWnd, szStr, nLength+1);\r
1483                 str.ReleaseBuffer();\r
1484                 return str;\r
1485         }\r
1486 \r
1487         inline BOOL CWnd::OnCommand(WPARAM wParam, LPARAM lParam)\r
1488         {\r
1489                 UNREFERENCED_PARAMETER(wParam);\r
1490                 UNREFERENCED_PARAMETER(lParam);\r
1491 \r
1492                 // Override this to handle WM_COMMAND messages, for example\r
1493 \r
1494                 //      switch (LOWORD(wParam))\r
1495                 //      {\r
1496                 //      case IDM_FILE_NEW:\r
1497                 //              OnFileNew();\r
1498                 //              TRUE;   // return TRUE for handled commands\r
1499                 //      }\r
1500 \r
1501                 // return FALSE for unhandled commands\r
1502                 return FALSE;\r
1503         }\r
1504 \r
1505         inline void CWnd::OnCreate()\r
1506         {\r
1507                 // This function is called when a WM_CREATE message is recieved\r
1508                 // Override it in your derived class to automatically perform tasks\r
1509                 //  during window creation.\r
1510         }\r
1511 \r
1512         inline void CWnd::OnDraw(CDC* pDC)\r
1513         // Called when part of the client area of the window needs to be drawn\r
1514         {\r
1515                 UNREFERENCED_PARAMETER(pDC);\r
1516 \r
1517             // Override this function in your derived class to perform drawing tasks.\r
1518         }\r
1519 \r
1520         inline BOOL CWnd::OnEraseBkgnd(CDC* pDC)\r
1521         // Called when the background of the window's client area needs to be erased.\r
1522         {\r
1523                 UNREFERENCED_PARAMETER(pDC);\r
1524 \r
1525             // Override this function in your derived class to perform drawing tasks.\r
1526 \r
1527                 // Return Value: Return FALSE to also permit default erasure of the background\r
1528                 //                               Return TRUE to prevent default erasure of the background\r
1529 \r
1530                 return FALSE;\r
1531         }\r
1532 \r
1533 \r
1534         inline void CWnd::OnInitialUpdate()\r
1535         {\r
1536                 // This function is called automatically once the window is created\r
1537                 // Override it in your derived class to automatically perform tasks\r
1538                 // after window creation.\r
1539         }\r
1540 \r
1541         inline LRESULT CWnd::MessageReflect(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
1542         {\r
1543                 // A function used to call OnMessageReflect. You shouldn't need to call or\r
1544                 //  override this function.\r
1545 \r
1546                 HWND hWnd = NULL;\r
1547                 switch (uMsg)\r
1548                 {\r
1549                 case WM_COMMAND:\r
1550                 case WM_CTLCOLORBTN:\r
1551                 case WM_CTLCOLOREDIT:\r
1552                 case WM_CTLCOLORDLG:\r
1553                 case WM_CTLCOLORLISTBOX:\r
1554                 case WM_CTLCOLORSCROLLBAR:\r
1555                 case WM_CTLCOLORSTATIC:\r
1556                 case WM_CHARTOITEM:\r
1557                 case WM_VKEYTOITEM:\r
1558                 case WM_HSCROLL:\r
1559                 case WM_VSCROLL:\r
1560                         hWnd = (HWND)lParam;\r
1561                         break;\r
1562 \r
1563                 case WM_DRAWITEM:\r
1564                 case WM_MEASUREITEM:\r
1565                 case WM_DELETEITEM:\r
1566                 case WM_COMPAREITEM:\r
1567                         hWnd = ::GetDlgItem(hWndParent, (int)wParam);\r
1568                         break;\r
1569 \r
1570                 case WM_PARENTNOTIFY:\r
1571                         switch(LOWORD(wParam))\r
1572                         {\r
1573                         case WM_CREATE:\r
1574                         case WM_DESTROY:\r
1575                                 hWnd = (HWND)lParam;\r
1576                                 break;\r
1577                         }\r
1578                 }\r
1579 \r
1580                 CWnd* Wnd = GetApp()->GetCWndFromMap(hWnd);\r
1581 \r
1582                 if (Wnd != NULL)\r
1583                         return Wnd->OnMessageReflect(uMsg, wParam, lParam);\r
1584 \r
1585                 return 0L;\r
1586         }\r
1587 \r
1588         inline LRESULT CWnd::OnMessageReflect(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
1589         {\r
1590                 UNREFERENCED_PARAMETER(uMsg);\r
1591                 UNREFERENCED_PARAMETER(wParam);\r
1592                 UNREFERENCED_PARAMETER(lParam);\r
1593                 // This function processes those special messages (see above) sent\r
1594                 // by some older controls, and reflects them back to the originating CWnd object.\r
1595                 // Override this function in your derrived class to handle these special messages.\r
1596 \r
1597                 // Your overriding function should look like this ...\r
1598 \r
1599                 // switch (uMsg)\r
1600                 // {\r
1601                 //              Handle your reflected messages here\r
1602                 // }\r
1603 \r
1604                 // return 0L for unhandled messages\r
1605                 return 0L;\r
1606         }\r
1607 \r
1608         inline LRESULT CWnd::OnNotify(WPARAM wParam, LPARAM lParam)\r
1609         {\r
1610                 UNREFERENCED_PARAMETER(wParam);\r
1611                 UNREFERENCED_PARAMETER(lParam);\r
1612 \r
1613                 // You can use either OnNotifyReflect or OnNotify to handle notifications\r
1614                 // Override OnNotifyReflect to handle notifications in the CWnd class that\r
1615                 //   generated the notification.   OR\r
1616                 // Override OnNotify to handle notifications in the PARENT of the CWnd class\r
1617                 //   that generated the notification.\r
1618 \r
1619                 // Your overriding function should look like this ...\r
1620 \r
1621                 // switch (((LPNMHDR)lParam)->code)\r
1622                 // {\r
1623                 //              Handle your notifications from the CHILD window here\r
1624                 //      Return the value recommended by the Windows API documentation.\r
1625                 //      For many notifications, the return value doesn't matter, but for some it does.\r
1626                 // }\r
1627 \r
1628                 // return 0L for unhandled notifications\r
1629                 return 0L;\r
1630         }\r
1631 \r
1632         inline LRESULT CWnd::OnNotifyReflect(WPARAM wParam, LPARAM lParam)\r
1633         {\r
1634                 UNREFERENCED_PARAMETER(wParam);\r
1635                 UNREFERENCED_PARAMETER(lParam);\r
1636 \r
1637                 // Override OnNotifyReflect to handle notifications in the CWnd class that\r
1638                 //   generated the notification.\r
1639 \r
1640                 // Your overriding function should look like this ...\r
1641 \r
1642                 // switch (((LPNMHDR)lParam)->code)\r
1643                 // {\r
1644                 //              Handle your notifications from this window here\r
1645                 //      Return the value recommended by the Windows API documentation.\r
1646                 // }\r
1647 \r
1648                 // return 0L for unhandled notifications\r
1649                 return 0L;\r
1650         }\r
1651 \r
1652         inline void CWnd::OnMenuUpdate(UINT nID)\r
1653         // Called when menu items are about to be displayed\r
1654         {\r
1655                 UNREFERENCED_PARAMETER(nID);\r
1656 \r
1657                 // Override this function to modify the behaviour of menu items,\r
1658                 // such as adding or removing checkmarks\r
1659         }\r
1660 \r
1661         inline void CWnd::PreCreate(CREATESTRUCT& cs)\r
1662         // Called by CWnd::Create to set some window parameters\r
1663         {\r
1664                 // Test if Win32++ has been started\r
1665                 assert(GetApp());       // Test if Win32++ has been started\r
1666 \r
1667                 m_pcs->cx             = cs.cx;\r
1668                 m_pcs->cy             = cs.cy;\r
1669                 m_pcs->dwExStyle      = cs.dwExStyle;\r
1670                 m_pcs->hInstance      = GetApp()->GetInstanceHandle();\r
1671                 m_pcs->hMenu          = cs.hMenu;\r
1672                 m_pcs->hwndParent     = cs.hwndParent;\r
1673                 m_pcs->lpCreateParams = cs.lpCreateParams;\r
1674                 m_pcs->lpszClass      = cs.lpszClass;\r
1675                 m_pcs->lpszName       = cs.lpszName;\r
1676                 m_pcs->style          = cs.style;\r
1677                 m_pcs->x              = cs.x;\r
1678                 m_pcs->y              = cs.y;\r
1679 \r
1680                 // Overide this function in your derived class to set the\r
1681                 // CREATESTRUCT values prior to window creation.\r
1682                 // The cs.lpszClass parameter should NOT be specified if the\r
1683                 // PreRegisterClass function is used to create a window class.\r
1684         }\r
1685 \r
1686         inline void CWnd::PreRegisterClass(WNDCLASS& wc)\r
1687         // Called by CWnd::Create to set some window parameters\r
1688         //  Useful for setting the background brush and cursor\r
1689         {\r
1690                 // Test if Win32++ has been started\r
1691                 assert( GetApp() );\r
1692 \r
1693                 m_pwc->style                    = wc.style;\r
1694                 m_pwc->lpfnWndProc              = CWnd::StaticWindowProc;\r
1695                 m_pwc->cbClsExtra               = wc.cbClsExtra;\r
1696                 m_pwc->cbWndExtra               = wc.cbWndExtra;\r
1697                 m_pwc->hInstance                = GetApp()->GetInstanceHandle();\r
1698                 m_pwc->hIcon                    = wc.hIcon;\r
1699                 m_pwc->hCursor                  = wc.hCursor;\r
1700                 m_pwc->hbrBackground    = wc.hbrBackground;\r
1701                 m_pwc->lpszMenuName             = wc.lpszMenuName;\r
1702                 m_pwc->lpszClassName    = wc.lpszClassName;\r
1703 \r
1704                 // Overide this function in your derived class to set the\r
1705                 // WNDCLASS values prior to window creation.\r
1706 \r
1707                 // ADDITIONAL NOTES:\r
1708                 // 1) The lpszClassName must be set for this function to take effect.\r
1709                 // 2) The lpfnWndProc is always CWnd::StaticWindowProc.\r
1710                 // 3) No other defaults are set, so the following settings might prove useful\r
1711                 //     wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);\r
1712                 //     wc.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);\r
1713                 //     wc.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);\r
1714                 // 4) The styles that can be set here are WNDCLASS styles. These are a different\r
1715                 //     set of styles to those set by CREATESTRUCT (used in PreCreate).\r
1716                 // 5) RegisterClassEx is not used because its not supported on WinCE.\r
1717                 //     To set a small icon for the window, use SetIconSmall.\r
1718         }\r
1719 \r
1720         inline BOOL CWnd::PreTranslateMessage(MSG* pMsg)\r
1721         {\r
1722                 UNREFERENCED_PARAMETER(pMsg);\r
1723 \r
1724                 // Override this function if your class requires input messages to be\r
1725                 // translated before normal processing. Function which translate messages\r
1726                 // include TranslateAccelerator, TranslateMDISysAccel and IsDialogMessage.\r
1727                 // Return TRUE if the message is translated.\r
1728 \r
1729                 return FALSE;\r
1730         }\r
1731 \r
1732         inline BOOL CWnd::RegisterClass(WNDCLASS& wc)\r
1733         // A private function used by the PreRegisterClass function to register a\r
1734         //  window class prior to window creation\r
1735         {\r
1736                 assert( GetApp() );\r
1737                 assert( (0 != lstrlen(wc.lpszClassName) && ( lstrlen(wc.lpszClassName) <=  MAX_STRING_SIZE) ) );\r
1738 \r
1739                 // Check to see if this classname is already registered\r
1740                 WNDCLASS wcTest = {0};\r
1741                 BOOL Done = FALSE;\r
1742 \r
1743                 if (::GetClassInfo(GetApp()->GetInstanceHandle(), wc.lpszClassName, &wcTest))\r
1744                 {\r
1745                         wc = wcTest;\r
1746                         Done = TRUE;\r
1747                 }\r
1748 \r
1749                 if (!Done)\r
1750                 {\r
1751                         // Set defaults\r
1752                         wc.hInstance    = GetApp()->GetInstanceHandle();\r
1753                         wc.lpfnWndProc  = CWnd::StaticWindowProc;\r
1754 \r
1755                         // Register the WNDCLASS structure\r
1756                         if ( !::RegisterClass(&wc) )\r
1757                                 throw CWinException(_T("Failed to register window class"));\r
1758 \r
1759                         Done = TRUE;\r
1760                 }\r
1761 \r
1762                 return Done;\r
1763         }\r
1764 \r
1765         inline BOOL CWnd::RemoveFromMap()\r
1766         {\r
1767                 BOOL Success = FALSE;\r
1768 \r
1769                 if (GetApp())\r
1770                 {\r
1771 \r
1772                         // Allocate an iterator for our HWND map\r
1773                         std::map<HWND, CWnd*, CompareHWND>::iterator m;\r
1774 \r
1775                         CWinApp* pApp = GetApp();\r
1776                         if (pApp)\r
1777                         {\r
1778                                 // Erase the CWnd pointer entry from the map\r
1779                                 pApp->m_csMapLock.Lock();\r
1780                                 for (m = pApp->m_mapHWND.begin(); m != pApp->m_mapHWND.end(); ++m)\r
1781                                 {\r
1782                                         if (this == m->second)\r
1783                                         {\r
1784                                                 pApp->m_mapHWND.erase(m);\r
1785                                                 Success = TRUE;\r
1786                                                 break;\r
1787                                         }\r
1788                                 }\r
1789 \r
1790                                 pApp->m_csMapLock.Release();\r
1791                         }\r
1792                 }\r
1793 \r
1794                 return Success;\r
1795         }\r
1796 \r
1797         inline HICON CWnd::SetIconLarge(int nIcon)\r
1798         // Sets the large icon associated with the window\r
1799         {\r
1800                 assert( GetApp() );\r
1801                 assert(::IsWindow(m_hWnd));\r
1802 \r
1803                 HICON hIconLarge = (HICON) (::LoadImage (GetApp()->GetResourceHandle(), MAKEINTRESOURCE (nIcon), IMAGE_ICON,\r
1804                 ::GetSystemMetrics (SM_CXICON), ::GetSystemMetrics (SM_CYICON), 0));\r
1805 \r
1806                 if (hIconLarge)\r
1807                         SendMessage (WM_SETICON, WPARAM (ICON_BIG), LPARAM (hIconLarge));\r
1808                 else\r
1809                         TRACE(_T("**WARNING** SetIconLarge Failed\n"));\r
1810 \r
1811                 return hIconLarge;\r
1812         }\r
1813 \r
1814         inline HICON CWnd::SetIconSmall(int nIcon)\r
1815         // Sets the small icon associated with the window\r
1816         {\r
1817                 assert( GetApp() );\r
1818                 assert(::IsWindow(m_hWnd));\r
1819 \r
1820                 HICON hIconSmall = (HICON) (::LoadImage (GetApp()->GetResourceHandle(), MAKEINTRESOURCE (nIcon), IMAGE_ICON,\r
1821                 ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0));\r
1822 \r
1823                 if (hIconSmall)\r
1824                         SendMessage (WM_SETICON, WPARAM (ICON_SMALL), LPARAM (hIconSmall));\r
1825                 else\r
1826                         TRACE(_T("**WARNING** SetIconSmall Failed\n"));\r
1827 \r
1828                 return hIconSmall;\r
1829         }\r
1830 \r
1831         inline LRESULT CALLBACK CWnd::StaticWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
1832         // All CWnd windows direct their messages here. This function redirects the message\r
1833         // to the CWnd's WndProc function.\r
1834         {\r
1835                 assert( GetApp() );\r
1836 \r
1837                 CWnd* w = GetApp()->GetCWndFromMap(hWnd);\r
1838                 if (0 == w)\r
1839                 {\r
1840                         // The CWnd pointer wasn't found in the map, so add it now\r
1841 \r
1842                         // Retrieve the pointer to the TLS Data\r
1843                         TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());\r
1844                         assert(pTLSData);\r
1845 \r
1846                         // Retrieve pointer to CWnd object from Thread Local Storage TLS\r
1847                         w = pTLSData->pCWnd;\r
1848                         assert(w);                              // pTLSData->pCWnd is assigned in CreateEx\r
1849                         pTLSData->pCWnd = NULL;\r
1850 \r
1851                         // Store the CWnd pointer in the HWND map\r
1852                         w->m_hWnd = hWnd;\r
1853                         w->AddToMap();\r
1854                 }\r
1855 \r
1856                 return w->WndProc(uMsg, wParam, lParam);\r
1857 \r
1858         } // LRESULT CALLBACK StaticWindowProc(...)\r
1859 \r
1860         inline void CWnd::Subclass(HWND hWnd)\r
1861         // A private function used by CreateEx, Attach and AttachDlgItem\r
1862         {\r
1863                 assert(::IsWindow(hWnd));\r
1864 \r
1865                 m_PrevWindowProc = (WNDPROC)::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)CWnd::StaticWindowProc);\r
1866                 m_hWnd = hWnd;\r
1867         }\r
1868 \r
1869         inline LRESULT CWnd::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
1870         {\r
1871                 // Override this function in your class derrived from CWnd to handle\r
1872                 //  window messages. A typical function might look like this:\r
1873 \r
1874                 //      switch (uMsg)\r
1875                 //      {\r
1876                 //      case MESSAGE1:          // Some Windows API message\r
1877                 //              OnMessage1();   // A user defined function\r
1878                 //              break;                  // Also do default processing\r
1879                 //      case MESSAGE2:\r
1880                 //              OnMessage2();\r
1881                 //              return x;               // Don't do default processing, but instead return\r
1882                 //                                              //  a value recommended by the Windows API documentation\r
1883                 //      }\r
1884 \r
1885                 // Always pass unhandled messages on to WndProcDefault\r
1886                 return WndProcDefault(uMsg, wParam, lParam);\r
1887         }\r
1888 \r
1889         inline LRESULT CWnd::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
1890         // All WndProc functions should pass unhandled window messages to this function\r
1891         {\r
1892                 LRESULT lr = 0L;\r
1893 \r
1894         switch (uMsg)\r
1895                 {\r
1896                 case UWM_CLEANUPTEMPS:\r
1897                         {\r
1898                                 TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());\r
1899                                 pTLSData->vTmpWnds.clear();\r
1900                         }\r
1901                         break;\r
1902                 case WM_COMMAND:\r
1903                         {\r
1904                                 // Refelect this message if it's from a control\r
1905                                 CWnd* pWnd = GetApp()->GetCWndFromMap((HWND)lParam);\r
1906                                 if (pWnd != NULL)\r
1907                                         lr = pWnd->OnCommand(wParam, lParam);\r
1908 \r
1909                                 // Handle user commands\r
1910                                 if (!lr)\r
1911                                         lr =  OnCommand(wParam, lParam);\r
1912 \r
1913                                 if (lr) return 0L;\r
1914                         }\r
1915                         break;  // Note: Some MDI commands require default processing\r
1916                 case WM_CREATE:\r
1917                         OnCreate();\r
1918                         break;\r
1919         // An example of how to end the application when the window closes\r
1920         //  If needed, put this in the class you inherit from CWnd\r
1921         //      case WM_DESTROY:\r
1922         //              ::PostQuitMessage(0);\r
1923         //              return 0L;\r
1924                 case WM_NOTIFY:\r
1925                         {\r
1926                                 // Do Notification reflection if it came from a CWnd object\r
1927                                 HWND hwndFrom = ((LPNMHDR)lParam)->hwndFrom;\r
1928                                 CWnd* pWndFrom = GetApp()->GetCWndFromMap(hwndFrom);\r
1929 \r
1930                                 if (lstrcmp(GetClassName(), _T("ReBarWindow32")) != 0)  // Skip notification reflection for rebars to avoid double handling\r
1931                                 {\r
1932                                         if (pWndFrom != NULL)\r
1933                                                 lr = pWndFrom->OnNotifyReflect(wParam, lParam);\r
1934                                         else\r
1935                                         {\r
1936                                                 // Some controls (eg ListView) have child windows.\r
1937                                                 // Reflect those notifications too.\r
1938                                                 CWnd* pWndFromParent = GetApp()->GetCWndFromMap(::GetParent(hwndFrom));\r
1939                                                 if (pWndFromParent != NULL)\r
1940                                                         lr = pWndFromParent->OnNotifyReflect(wParam, lParam);\r
1941                                         }\r
1942                                 }\r
1943 \r
1944                                 // Handle user notifications\r
1945                                 if (!lr) lr = OnNotify(wParam, lParam);\r
1946                                 if (lr) return lr;\r
1947                         }\r
1948                         break;\r
1949 \r
1950                 case WM_PAINT:\r
1951                         {\r
1952                                 // Subclassed controls expect to do their own painting.\r
1953                                 // CustomDraw or OwnerDraw are normally used to modify the drawing of controls.\r
1954                                 if (m_PrevWindowProc) break;\r
1955 \r
1956                                 if (::GetUpdateRect(m_hWnd, NULL, FALSE))\r
1957                                 {\r
1958                                         CPaintDC dc(this);\r
1959                                         OnDraw(&dc);\r
1960                                 }\r
1961                                 else\r
1962                                 // RedrawWindow can require repainting without an update rect\r
1963                                 {\r
1964                                         CClientDC dc(this);\r
1965                                         OnDraw(&dc);\r
1966                                 }\r
1967                         }\r
1968                         return 0L;\r
1969 \r
1970                 case WM_ERASEBKGND:\r
1971                         {\r
1972                                 CDC dc((HDC)wParam);\r
1973                                 BOOL bResult = OnEraseBkgnd(&dc);\r
1974                                 dc.Detach();\r
1975                                 if (bResult) return TRUE;\r
1976                         }\r
1977                         break;\r
1978 \r
1979                 // A set of messages to be reflected back to the control that generated them\r
1980                 case WM_CTLCOLORBTN:\r
1981                 case WM_CTLCOLOREDIT:\r
1982                 case WM_CTLCOLORDLG:\r
1983                 case WM_CTLCOLORLISTBOX:\r
1984                 case WM_CTLCOLORSCROLLBAR:\r
1985                 case WM_CTLCOLORSTATIC:\r
1986                 case WM_DRAWITEM:\r
1987                 case WM_MEASUREITEM:\r
1988                 case WM_DELETEITEM:\r
1989                 case WM_COMPAREITEM:\r
1990                 case WM_CHARTOITEM:\r
1991                 case WM_VKEYTOITEM:\r
1992                 case WM_HSCROLL:\r
1993                 case WM_VSCROLL:\r
1994                 case WM_PARENTNOTIFY:\r
1995                         {\r
1996                         //      if (m_PrevWindowProc) break; // Suppress for subclassed windows\r
1997 \r
1998                                 LRESULT lr = MessageReflect(m_hWnd, uMsg, wParam, lParam);\r
1999                                 if (lr) return lr;      // Message processed so return\r
2000                         }\r
2001                         break;                          // Do default processing when message not already processed\r
2002 \r
2003                 case UWM_UPDATE_COMMAND:\r
2004                         OnMenuUpdate((UINT)wParam); // Perform menu updates\r
2005                 break;\r
2006 \r
2007                 } // switch (uMsg)\r
2008 \r
2009                 // Now hand all messages to the default procedure\r
2010                 if (m_PrevWindowProc)\r
2011                         return ::CallWindowProc(m_PrevWindowProc, m_hWnd, uMsg, wParam, lParam);\r
2012                 else\r
2013                         return FinalWindowProc(uMsg, wParam, lParam);\r
2014 \r
2015         } // LRESULT CWnd::WindowProc(...)\r
2016 \r
2017 \r
2018         //\r
2019         // Wrappers for Win32 API functions\r
2020         //\r
2021 \r
2022         inline CDC* CWnd::BeginPaint(PAINTSTRUCT& ps) const\r
2023         // The BeginPaint function prepares the specified window for painting and fills a PAINTSTRUCT structure with\r
2024         // information about the painting.\r
2025         {\r
2026         assert(::IsWindow(m_hWnd));\r
2027                 return FromHandle(::BeginPaint(m_hWnd, &ps));\r
2028         }\r
2029 \r
2030         inline BOOL CWnd::BringWindowToTop() const\r
2031         // The BringWindowToTop function brings the specified window to the top\r
2032         // of the Z order. If the window is a top-level window, it is activated.\r
2033         {\r
2034         assert(::IsWindow(m_hWnd));\r
2035                 return ::BringWindowToTop(m_hWnd);\r
2036         }\r
2037 \r
2038         inline LRESULT CWnd::CallWindowProc(WNDPROC lpPrevWndFunc, UINT Msg, WPARAM wParam, LPARAM lParam) const\r
2039         {\r
2040         assert(::IsWindow(m_hWnd));\r
2041                 return ::CallWindowProc(lpPrevWndFunc, m_hWnd, Msg, wParam, lParam);\r
2042         }\r
2043 \r
2044         inline BOOL CWnd::CheckDlgButton(int nIDButton, UINT uCheck) const\r
2045         // The CheckDlgButton function changes the check state of a button control.\r
2046         {\r
2047         assert(::IsWindow(m_hWnd));\r
2048                 return ::CheckDlgButton(m_hWnd, nIDButton, uCheck);\r
2049         }\r
2050 \r
2051         inline BOOL CWnd::CheckRadioButton(int nIDFirstButton, int nIDLastButton, int nIDCheckButton) const\r
2052         // The CheckRadioButton function adds a check mark to (checks) a specified radio button in a group\r
2053         // and removes a check mark from (clears) all other radio buttons in the group.\r
2054         {\r
2055                 assert(::IsWindow(m_hWnd));\r
2056                 return ::CheckRadioButton(m_hWnd, nIDFirstButton, nIDLastButton, nIDCheckButton);\r
2057         }\r
2058 \r
2059         inline CWnd* CWnd::ChildWindowFromPoint(POINT pt) const\r
2060         // determines which, if any, of the child windows belonging to a parent window contains\r
2061         // the specified point. The search is restricted to immediate child windows.\r
2062         // Grandchildren, and deeper descendant windows are not searched.\r
2063         {\r
2064                 assert(::IsWindow(m_hWnd));\r
2065                 return FromHandle(::ChildWindowFromPoint(m_hWnd, pt));\r
2066         }\r
2067 \r
2068         inline BOOL CWnd::ClientToScreen(POINT& pt) const\r
2069         // The ClientToScreen function converts the client-area coordinates of a specified point to screen coordinates.\r
2070         {\r
2071                 assert(::IsWindow(m_hWnd));\r
2072                 return ::ClientToScreen(m_hWnd, &pt);\r
2073         }\r
2074 \r
2075         inline BOOL CWnd::ClientToScreen(RECT& rc) const\r
2076         // The ClientToScreen function converts the client-area coordinates of a specified RECT to screen coordinates.\r
2077         {\r
2078                 assert(::IsWindow(m_hWnd));\r
2079                 return (BOOL)::MapWindowPoints(m_hWnd, NULL, (LPPOINT)&rc, 2);\r
2080         }\r
2081 \r
2082         inline HDWP CWnd::DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const\r
2083         // The DeferWindowPos function updates the specified multiple-window \96 position structure for the window.\r
2084         {\r
2085         assert(::IsWindow(m_hWnd));\r
2086                 return ::DeferWindowPos(hWinPosInfo, m_hWnd, hWndInsertAfter, x, y, cx, cy, uFlags);\r
2087         }\r
2088 \r
2089         inline HDWP CWnd::DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, const RECT& rc, UINT uFlags) const\r
2090         // The DeferWindowPos function updates the specified multiple-window \96 position structure for the window.\r
2091         {\r
2092                 assert(::IsWindow(m_hWnd));\r
2093                 return ::DeferWindowPos(hWinPosInfo, m_hWnd, hWndInsertAfter, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, uFlags);\r
2094         }\r
2095 \r
2096         inline LRESULT CWnd::DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) const\r
2097         // This function provides default processing for any window messages that an application does not process.\r
2098         {\r
2099                 assert(::IsWindow(m_hWnd));\r
2100                 return ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);\r
2101         }\r
2102 \r
2103         inline BOOL CWnd::DrawMenuBar() const\r
2104         // The DrawMenuBar function redraws the menu bar of the specified window. If the menu bar changes after\r
2105         // the system has created the window, this function must be called to draw the changed menu bar.\r
2106         {\r
2107                 assert(::IsWindow(m_hWnd));\r
2108                 return ::DrawMenuBar(m_hWnd);\r
2109         }\r
2110 \r
2111         inline BOOL CWnd::EnableWindow(BOOL bEnable /*= TRUE*/) const\r
2112         // The EnableWindow function enables or disables mouse and\r
2113         // keyboard input to the window.\r
2114         {\r
2115                 assert(::IsWindow(m_hWnd));\r
2116                 return ::EnableWindow(m_hWnd, bEnable);\r
2117         }\r
2118 \r
2119         inline BOOL CWnd::EndPaint(PAINTSTRUCT& ps) const\r
2120         // The EndPaint function marks the end of painting in the specified window. This function is required for\r
2121         // each call to the BeginPaint function, but only after painting is complete.\r
2122         {\r
2123                 assert(::IsWindow(m_hWnd));\r
2124                 return ::EndPaint(m_hWnd, &ps);\r
2125         }\r
2126 \r
2127         inline CWnd* CWnd::GetActiveWindow() const\r
2128         // The GetActiveWindow function retrieves a pointer to the active window attached to the calling\r
2129         // thread's message queue.\r
2130         {\r
2131                 return FromHandle( ::GetActiveWindow() );\r
2132         }\r
2133 \r
2134         inline CWnd* CWnd::GetCapture() const\r
2135         // The GetCapture function retrieves a pointer to the window (if any) that has captured the mouse.\r
2136         {\r
2137                 return FromHandle( ::GetCapture() );\r
2138         }\r
2139 \r
2140         inline ULONG_PTR CWnd::GetClassLongPtr(int nIndex) const\r
2141         // The GetClassLongPtr function retrieves the specified value from the\r
2142         // WNDCLASSEX structure associated with the window.\r
2143         {\r
2144                 assert(::IsWindow(m_hWnd));\r
2145                 return ::GetClassLongPtr(m_hWnd, nIndex);\r
2146         }\r
2147 \r
2148         inline CRect CWnd::GetClientRect() const\r
2149         // The GetClientRect function retrieves the coordinates of a window's client area.\r
2150         // The client coordinates specify the upper-left and lower-right corners of the\r
2151         // client area. Because client coordinates are relative to the upper-left corner\r
2152         // of a window's client area, the coordinates of the upper-left corner are (0,0).\r
2153         {\r
2154                 assert(::IsWindow(m_hWnd));\r
2155                 CRect rc;\r
2156                 ::GetClientRect(m_hWnd, &rc);\r
2157                 return rc;\r
2158         }\r
2159 \r
2160         inline CDC* CWnd::GetDC() const\r
2161         // The GetDC function retrieves a handle to a display device context (DC) for the\r
2162         // client area of the window.\r
2163         {\r
2164                 assert(::IsWindow(m_hWnd));\r
2165                 return CDC::AddTempHDC(::GetDC(m_hWnd), m_hWnd);\r
2166         }\r
2167 \r
2168         inline CDC* CWnd::GetDCEx(HRGN hrgnClip, DWORD flags) const\r
2169         // The GetDCEx function retrieves a handle to a display device context (DC) for the\r
2170         // client area or entire area of a window\r
2171         {\r
2172                 assert(::IsWindow(m_hWnd));\r
2173                 return CDC::AddTempHDC(::GetDCEx(m_hWnd, hrgnClip, flags), m_hWnd);\r
2174         }\r
2175 \r
2176         inline CWnd* CWnd::GetDesktopWindow() const\r
2177         // The GetDesktopWindow function retrieves a pointer to the desktop window.\r
2178         {\r
2179                 return FromHandle( ::GetDesktopWindow() );\r
2180         }\r
2181 \r
2182         inline CWnd* CWnd::GetDlgItem(int nIDDlgItem) const\r
2183         // The GetDlgItem function retrieves a handle to a control in the dialog box.\r
2184         {\r
2185                 assert(::IsWindow(m_hWnd));\r
2186                 return FromHandle( ::GetDlgItem(m_hWnd, nIDDlgItem) );\r
2187         }\r
2188 \r
2189         inline UINT CWnd::GetDlgItemInt(int nIDDlgItem, BOOL* lpTranslated, BOOL bSigned) const\r
2190         // The GetDlgItemInt function translates the text of a specified control in a dialog box into an integer value.\r
2191         {\r
2192                 assert(::IsWindow(m_hWnd));\r
2193                 return ::GetDlgItemInt(m_hWnd, nIDDlgItem, lpTranslated, bSigned);\r
2194         }\r
2195 \r
2196         inline CWnd* CWnd::GetFocus() const\r
2197         // The GetFocus function retrieves a pointer to the window that has the keyboard focus, if the window\r
2198         // is attached to the calling thread's message queue.\r
2199         {\r
2200                 return FromHandle( ::GetFocus() );\r
2201         }\r
2202 \r
2203         inline CFont* CWnd::GetFont() const\r
2204         // Retrieves the font with which the window is currently drawing its text.\r
2205         {\r
2206                 assert(::IsWindow(m_hWnd));\r
2207                 return FromHandle((HFONT)SendMessage(WM_GETFONT, 0, 0));\r
2208         }\r
2209 \r
2210         inline HICON CWnd::GetIcon(BOOL bBigIcon) const\r
2211         // Retrieves a handle to the large or small icon associated with a window.\r
2212         {\r
2213                 assert(::IsWindow(m_hWnd));\r
2214                 return (HICON)SendMessage(WM_GETICON, (WPARAM)bBigIcon, 0);\r
2215         }\r
2216 \r
2217         inline CWnd* CWnd::GetNextDlgGroupItem(CWnd* pCtl, BOOL bPrevious) const\r
2218         // The GetNextDlgGroupItem function retrieves a pointer to the first control in a group of controls that\r
2219         // precedes (or follows) the specified control in a dialog box.\r
2220         {\r
2221                 assert(::IsWindow(m_hWnd));\r
2222                 assert(pCtl);\r
2223                 return FromHandle(::GetNextDlgGroupItem(m_hWnd, pCtl->GetHwnd(), bPrevious));\r
2224         }\r
2225 \r
2226         inline CWnd* CWnd::GetNextDlgTabItem(CWnd* pCtl, BOOL bPrevious) const\r
2227         // The GetNextDlgTabItem function retrieves a pointer to the first control that has the WS_TABSTOP style\r
2228         // that precedes (or follows) the specified control.\r
2229         {\r
2230                 assert(::IsWindow(m_hWnd));\r
2231                 assert(pCtl);\r
2232                 return FromHandle(::GetNextDlgTabItem(m_hWnd, pCtl->GetHwnd(), bPrevious));\r
2233         }\r
2234 \r
2235         inline CWnd* CWnd::GetParent() const\r
2236         // The GetParent function retrieves a pointer to the specified window's parent or owner.\r
2237         {\r
2238                 assert(::IsWindow(m_hWnd));\r
2239                 return FromHandle( ::GetParent(m_hWnd) );\r
2240         }\r
2241 \r
2242         inline LONG_PTR CWnd::GetWindowLongPtr(int nIndex) const\r
2243         // The GetWindowLongPtr function retrieves information about the window.\r
2244         {\r
2245                 assert(::IsWindow(m_hWnd));\r
2246                 return ::GetWindowLongPtr(m_hWnd, nIndex);\r
2247         }\r
2248 \r
2249         inline BOOL CWnd::GetScrollInfo(int fnBar, SCROLLINFO& si) const\r
2250         // The GetScrollInfo function retrieves the parameters of a scroll bar, including\r
2251         // the minimum and maximum scrolling positions, the page size, and the position\r
2252         // of the scroll box (thumb).\r
2253         {\r
2254                 assert(::IsWindow(m_hWnd));\r
2255                 return ::GetScrollInfo(m_hWnd, fnBar, &si);\r
2256         }\r
2257 \r
2258         inline CRect CWnd::GetUpdateRect(BOOL bErase) const\r
2259         // The GetUpdateRect function retrieves the coordinates of the smallest rectangle that completely\r
2260         // encloses the update region of the specified window.\r
2261         {\r
2262                 assert(::IsWindow(m_hWnd));\r
2263                 CRect rc;\r
2264                 ::GetUpdateRect(m_hWnd, &rc, bErase);\r
2265                 return rc;\r
2266         }\r
2267 \r
2268         inline int CWnd::GetUpdateRgn(CRgn* pRgn, BOOL bErase) const\r
2269         // The GetUpdateRgn function retrieves the update region of a window by copying it into the specified region.\r
2270         {\r
2271                 assert(::IsWindow(m_hWnd));\r
2272                 assert(pRgn);\r
2273                 HRGN hRgn = (HRGN)pRgn->GetHandle();\r
2274                 return ::GetUpdateRgn(m_hWnd, hRgn, bErase);\r
2275         }\r
2276 \r
2277         inline CWnd* CWnd::GetWindow(UINT uCmd) const\r
2278         // The GetWindow function retrieves a pointer to a window that has the specified\r
2279         // relationship (Z-Order or owner) to the specified window.\r
2280         // Possible uCmd values: GW_CHILD, GW_ENABLEDPOPUP, GW_HWNDFIRST, GW_HWNDLAST,\r
2281         // GW_HWNDNEXT, GW_HWNDPREV, GW_OWNER\r
2282         {\r
2283                 assert(::IsWindow(m_hWnd));\r
2284                 return FromHandle( ::GetWindow(m_hWnd, uCmd) );\r
2285         }\r
2286 \r
2287         inline CDC* CWnd::GetWindowDC() const\r
2288         // The GetWindowDC function retrieves the device context (DC) for the entire\r
2289         // window, including title bar, menus, and scroll bars.\r
2290         {\r
2291                 assert(::IsWindow(m_hWnd));\r
2292                 return CDC::AddTempHDC(::GetWindowDC(m_hWnd), m_hWnd);\r
2293         }\r
2294 \r
2295         inline CRect CWnd::GetWindowRect() const\r
2296         // retrieves the dimensions of the bounding rectangle of the window.\r
2297         // The dimensions are given in screen coordinates that are relative to the\r
2298         // upper-left corner of the screen.\r
2299         {\r
2300                 assert(::IsWindow(m_hWnd));\r
2301                 CRect rc;\r
2302                 ::GetWindowRect(m_hWnd, &rc);\r
2303                 return rc;\r
2304         }\r
2305 \r
2306         inline int CWnd::GetWindowTextLength() const\r
2307         // The GetWindowTextLength function retrieves the length, in characters, of the specified window's\r
2308         // title bar text (if the window has a title bar).\r
2309         {\r
2310                 assert(::IsWindow(m_hWnd));\r
2311                 return ::GetWindowTextLength(m_hWnd);\r
2312         }\r
2313 \r
2314         inline void CWnd::Invalidate(BOOL bErase /*= TRUE*/) const\r
2315         // The Invalidate function adds the entire client area the window's update region.\r
2316         // The update region represents the portion of the window's client area that must be redrawn.\r
2317         {\r
2318                 assert(::IsWindow(m_hWnd));\r
2319                 ::InvalidateRect(m_hWnd, NULL, bErase);\r
2320         }\r
2321 \r
2322         inline BOOL CWnd::InvalidateRect(LPCRECT lpRect, BOOL bErase /*= TRUE*/) const\r
2323         // The InvalidateRect function adds a rectangle to the window's update region.\r
2324         // The update region represents the portion of the window's client area that must be redrawn.\r
2325         {\r
2326                 assert(::IsWindow(m_hWnd));\r
2327                 return ::InvalidateRect(m_hWnd, lpRect, bErase);\r
2328         }\r
2329 \r
2330         inline BOOL CWnd::InvalidateRgn(CRgn* pRgn, BOOL bErase /*= TRUE*/) const\r
2331         // The InvalidateRgn function invalidates the client area within the specified region\r
2332         // by adding it to the current update region of a window. The invalidated region,\r
2333         // along with all other areas in the update region, is marked for painting when the\r
2334         // next WM_PAINT message occurs.\r
2335         {\r
2336                 assert(::IsWindow(m_hWnd));\r
2337                 HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;\r
2338                 return ::InvalidateRgn(m_hWnd, hRgn, bErase);\r
2339         }\r
2340 \r
2341         inline BOOL CWnd::IsChild(CWnd* pChild) const\r
2342         // The IsChild function tests whether a window is a child window or descendant window\r
2343         // of a parent window's CWnd.\r
2344         {\r
2345                 assert(::IsWindow(m_hWnd));\r
2346                 return ::IsChild(m_hWnd, pChild->GetHwnd());\r
2347         }\r
2348 \r
2349         inline BOOL CWnd::IsDialogMessage(LPMSG lpMsg) const\r
2350         // The IsDialogMessage function determines whether a message is intended for the specified dialog box and,\r
2351         // if it is, processes the message.\r
2352         {\r
2353                 assert(::IsWindow(m_hWnd));\r
2354                 return ::IsDialogMessage(m_hWnd, lpMsg);\r
2355         }\r
2356 \r
2357         inline UINT CWnd::IsDlgButtonChecked(int nIDButton) const\r
2358         // The IsDlgButtonChecked function determines whether a button control has a check mark next to it\r
2359         // or whether a three-state button control is grayed, checked, or neither.\r
2360         {\r
2361                 assert(::IsWindow(m_hWnd));\r
2362                 return ::IsDlgButtonChecked(m_hWnd, nIDButton);\r
2363         }\r
2364 \r
2365         inline BOOL CWnd::IsWindowEnabled() const\r
2366         // The IsWindowEnabled function determines whether the window is enabled\r
2367         // for mouse and keyboard input.\r
2368         {\r
2369                 assert(::IsWindow(m_hWnd));\r
2370                 return ::IsWindowEnabled(m_hWnd);\r
2371         }\r
2372 \r
2373         inline BOOL CWnd::IsWindowVisible() const\r
2374         // The IsWindowVisible function retrieves the visibility state of the window.\r
2375         {\r
2376                 assert(::IsWindow(m_hWnd));\r
2377                 return ::IsWindowVisible(m_hWnd);\r
2378         }\r
2379 \r
2380         inline BOOL CWnd::IsWindow() const\r
2381         // The IsWindow function determines whether the window exists.\r
2382         {\r
2383                 return ::IsWindow(m_hWnd);\r
2384         }\r
2385 \r
2386         inline void  CWnd::MapWindowPoints(CWnd* pWndTo, POINT& pt) const\r
2387         // The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one\r
2388         // window to a coordinate space relative to another window.\r
2389         {\r
2390                 assert (m_hWnd);\r
2391                 if(pWndTo)\r
2392                 {\r
2393                         assert (pWndTo->GetHwnd());\r
2394                         ::MapWindowPoints(m_hWnd, pWndTo->GetHwnd(), &pt, 1);\r
2395                 }\r
2396                 else\r
2397                         ::MapWindowPoints(m_hWnd, NULL, &pt, 1);\r
2398         }\r
2399 \r
2400         inline void CWnd::MapWindowPoints(CWnd* pWndTo, RECT& rc) const\r
2401         // The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one\r
2402         // window to a coordinate space relative to another window.\r
2403         {\r
2404                 assert (m_hWnd);\r
2405                 if(pWndTo)\r
2406                 {\r
2407                         assert (pWndTo->GetHwnd());\r
2408                         ::MapWindowPoints(m_hWnd, pWndTo->GetHwnd(), (LPPOINT)&rc, 2);\r
2409                 }\r
2410                 else\r
2411                         ::MapWindowPoints(m_hWnd, NULL, (LPPOINT)&rc, 2);\r
2412         }\r
2413 \r
2414         inline void CWnd::MapWindowPoints(CWnd* pWndTo, LPPOINT ptArray, UINT nCount) const\r
2415         // The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one\r
2416         // window to a coordinate space relative to another window.\r
2417         {\r
2418                 assert (m_hWnd);\r
2419                 if (pWndTo)\r
2420                 {\r
2421                         assert (pWndTo->GetHwnd());\r
2422                         ::MapWindowPoints(m_hWnd, pWndTo->GetHwnd(), (LPPOINT)ptArray, nCount);\r
2423                 }\r
2424                 else\r
2425                         ::MapWindowPoints(m_hWnd, NULL, (LPPOINT)ptArray, nCount);\r
2426         }\r
2427 \r
2428         inline int CWnd::MessageBox(LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) const\r
2429         // The MessageBox function creates, displays, and operates a message box.\r
2430         // Possible combinations of uType values include: MB_OK, MB_HELP, MB_OKCANCEL, MB_RETRYCANCEL,\r
2431         // MB_YESNO, MB_YESNOCANCEL, MB_ICONEXCLAMATION, MB_ICONWARNING, MB_ICONERROR (+ many others).\r
2432         {\r
2433                 assert(::IsWindow(m_hWnd));\r
2434                 return ::MessageBox(m_hWnd, lpText, lpCaption, uType);\r
2435         }\r
2436 \r
2437         inline BOOL CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint /* = TRUE*/) const\r
2438         // The MoveWindow function changes the position and dimensions of the window.\r
2439         {\r
2440                 assert(::IsWindow(m_hWnd));\r
2441                 return ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint = TRUE);\r
2442         }\r
2443 \r
2444         inline BOOL CWnd::MoveWindow(const RECT& rc, BOOL bRepaint /* = TRUE*/) const\r
2445         // The MoveWindow function changes the position and dimensions of the window.\r
2446         {\r
2447                 assert(::IsWindow(m_hWnd));\r
2448                 return ::MoveWindow(m_hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, bRepaint);\r
2449         }\r
2450 \r
2451         inline BOOL CWnd::PostMessage(UINT uMsg, WPARAM wParam /*= 0L*/, LPARAM lParam /*= 0L*/) const\r
2452         // The PostMessage function places (posts) a message in the message queue\r
2453         // associated with the thread that created the window and returns without\r
2454         // waiting for the thread to process the message.\r
2455         {\r
2456                 assert(::IsWindow(m_hWnd));\r
2457                 return ::PostMessage(m_hWnd, uMsg, wParam, lParam);\r
2458         }\r
2459 \r
2460         inline BOOL CWnd::PostMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const\r
2461         // Required by by some macros\r
2462         {\r
2463                 assert(::IsWindow(m_hWnd));\r
2464                 return ::PostMessage(hWnd, uMsg, wParam, lParam);\r
2465         }\r
2466 \r
2467         inline BOOL CWnd::RedrawWindow(LPCRECT lpRectUpdate, CRgn* pRgn, UINT flags) const\r
2468         // The RedrawWindow function updates the specified rectangle or region in a window's client area.\r
2469         {\r
2470                 assert(::IsWindow(m_hWnd));\r
2471                 HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;\r
2472                 return ::RedrawWindow(m_hWnd, lpRectUpdate, hRgn, flags);\r
2473         }\r
2474 \r
2475         inline int CWnd::ReleaseDC(CDC* pDC) const\r
2476         // The ReleaseDC function releases a device context (DC), freeing it for use\r
2477         // by other applications.\r
2478         {\r
2479                 assert(::IsWindow(m_hWnd));\r
2480                 assert(pDC);\r
2481                 return ::ReleaseDC(m_hWnd, pDC->GetHDC());\r
2482         }\r
2483 \r
2484         inline BOOL CWnd::ScreenToClient(POINT& Point) const\r
2485         // The ScreenToClient function converts the screen coordinates of a specified point on the screen to client-area coordinates.\r
2486         {\r
2487                 assert(::IsWindow(m_hWnd));\r
2488                 return ::ScreenToClient(m_hWnd, &Point);\r
2489         }\r
2490 \r
2491         inline BOOL CWnd::ScreenToClient(RECT& rc) const\r
2492         // The ScreenToClient function converts the screen coordinates of a specified RECT on the screen to client-area coordinates.\r
2493         {\r
2494                 assert(::IsWindow(m_hWnd));\r
2495                 return (BOOL)::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rc, 2);\r
2496         }\r
2497 \r
2498         inline LRESULT CWnd::SendDlgItemMessage(int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam) const\r
2499         // The SendDlgItemMessage function sends a message to the specified control in a dialog box.\r
2500         {\r
2501                 assert(::IsWindow(m_hWnd));\r
2502                 return ::SendDlgItemMessage(m_hWnd, nIDDlgItem, Msg, wParam, lParam);\r
2503         }\r
2504 \r
2505         inline LRESULT CWnd::SendMessage(UINT uMsg, WPARAM wParam /*= 0L*/, LPARAM lParam /*= 0L*/) const\r
2506         // The SendMessage function sends the specified message to a window or windows.\r
2507         // It calls the window procedure for the window and does not return until the\r
2508         // window procedure has processed the message.\r
2509         {\r
2510                 assert(::IsWindow(m_hWnd));\r
2511                 return ::SendMessage(m_hWnd, uMsg, wParam, lParam);\r
2512         }\r
2513 \r
2514         inline LRESULT CWnd::SendMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const\r
2515         // Required by by some macros\r
2516         {\r
2517                 assert(::IsWindow(m_hWnd));\r
2518                 return ::SendMessage(hWnd, uMsg, wParam, lParam);\r
2519         }\r
2520 \r
2521         inline BOOL CWnd::SendNotifyMessage(UINT Msg, WPARAM wParam, LPARAM lParam) const\r
2522         // The SendNotifyMessage function sends the specified message to a window or windows. If the window was created by the\r
2523         // calling thread, SendNotifyMessage calls the window procedure for the window and does not return until the window procedure\r
2524         // has processed the message. If the window was created by a different thread, SendNotifyMessage passes the message to the\r
2525         // window procedure and returns immediately; it does not wait for the window procedure to finish processing the message.\r
2526         {\r
2527                 assert(::IsWindow(m_hWnd));\r
2528                 return ::SendNotifyMessage(m_hWnd, Msg, wParam, lParam);\r
2529         }\r
2530 \r
2531         inline CWnd* CWnd::SetActiveWindow() const\r
2532         // The SetActiveWindow function activates the window, but\r
2533         // not if the application is in the background.\r
2534         {\r
2535                 assert(::IsWindow(m_hWnd));\r
2536                 return FromHandle( ::SetActiveWindow(m_hWnd) );\r
2537         }\r
2538 \r
2539         inline CWnd* CWnd::SetCapture() const\r
2540         // The SetCapture function sets the mouse capture to the window.\r
2541         // SetCapture captures mouse input either when the mouse is over the capturing\r
2542         // window, or when the mouse button was pressed while the mouse was over the\r
2543         // capturing window and the button is still down.\r
2544         {\r
2545                 assert(::IsWindow(m_hWnd));\r
2546                 return FromHandle( ::SetCapture(m_hWnd) );\r
2547         }\r
2548 \r
2549         inline ULONG_PTR CWnd::SetClassLongPtr(int nIndex, LONG_PTR dwNewLong) const\r
2550         // The SetClassLongPtr function replaces the specified value at the specified offset in the\r
2551         // extra class memory or the WNDCLASSEX structure for the class to which the window belongs.\r
2552         {\r
2553                 assert(::IsWindow(m_hWnd));\r
2554                 return ::SetClassLongPtr(m_hWnd, nIndex, dwNewLong);\r
2555         }\r
2556 \r
2557         inline CWnd* CWnd::SetFocus() const\r
2558         // The SetFocus function sets the keyboard focus to the window.\r
2559         {\r
2560                 assert(::IsWindow(m_hWnd));\r
2561                 return FromHandle( ::SetFocus(m_hWnd) );\r
2562         }\r
2563 \r
2564         inline void CWnd::SetFont(CFont* pFont, BOOL bRedraw /* = TRUE*/) const\r
2565         // Specifies the font that the window will use when drawing text.\r
2566         {\r
2567                 assert(::IsWindow(m_hWnd));\r
2568                 assert(pFont);\r
2569                 SendMessage(WM_SETFONT, (WPARAM)pFont->GetHandle(), (LPARAM)bRedraw);\r
2570         }\r
2571 \r
2572         inline HICON CWnd::SetIcon(HICON hIcon, BOOL bBigIcon) const\r
2573         // Associates a new large or small icon with a window.\r
2574         {\r
2575                 assert(::IsWindow(m_hWnd));\r
2576                 return (HICON)SendMessage(WM_SETICON, (WPARAM)bBigIcon, (LPARAM)hIcon);\r
2577         }\r
2578 \r
2579         inline BOOL CWnd::SetForegroundWindow() const\r
2580         // The SetForegroundWindow function puts the thread that created the window into the\r
2581         // foreground and activates the window.\r
2582         {\r
2583                 assert(::IsWindow(m_hWnd));\r
2584                 return ::SetForegroundWindow(m_hWnd);\r
2585         }\r
2586 \r
2587         inline CWnd* CWnd::SetParent(CWnd* pWndParent) const\r
2588         // The SetParent function changes the parent window of the child window.\r
2589         {\r
2590                 assert(::IsWindow(m_hWnd));\r
2591                 if (pWndParent)\r
2592                 {\r
2593                         HWND hParent = pWndParent->GetHwnd();\r
2594                         return FromHandle(::SetParent(m_hWnd, hParent));\r
2595                 }\r
2596                 else\r
2597                         return FromHandle(::SetParent(m_hWnd, 0));\r
2598         }\r
2599 \r
2600         inline BOOL CWnd::SetRedraw(BOOL bRedraw /*= TRUE*/) const\r
2601         // This function allows changes in that window to be redrawn or prevents changes\r
2602         // in that window from being redrawn.\r
2603         {\r
2604                 assert(::IsWindow(m_hWnd));\r
2605                 return (BOOL)::SendMessage(m_hWnd, WM_SETREDRAW, (WPARAM)bRedraw, 0L);\r
2606         }\r
2607 \r
2608         inline LONG_PTR CWnd::SetWindowLongPtr(int nIndex, LONG_PTR dwNewLong) const\r
2609         // The SetWindowLongPtr function changes an attribute of the window.\r
2610         {\r
2611                 assert(::IsWindow(m_hWnd));\r
2612                 return ::SetWindowLongPtr(m_hWnd, nIndex, dwNewLong);\r
2613         }\r
2614 \r
2615         inline BOOL CWnd::SetWindowPos(const CWnd* pInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const\r
2616         // The SetWindowPos function changes the size, position, and Z order of a child, pop-up,\r
2617         // or top-level window.\r
2618         // The pInsertAfter can one of:  &wndTop, &wndTopMost, &wndBottom, or &wndNoTopMost\r
2619         {\r
2620                 assert(::IsWindow(m_hWnd));\r
2621                 HWND hWndInsertAfter = pInsertAfter? pInsertAfter->GetHwnd() : (HWND)0;\r
2622                 return ::SetWindowPos(m_hWnd, hWndInsertAfter, x, y, cx, cy, uFlags);\r
2623         }\r
2624 \r
2625         inline BOOL CWnd::SetWindowPos(const CWnd* pInsertAfter, const RECT& rc, UINT uFlags) const\r
2626         // The SetWindowPos function changes the size, position, and Z order of a child, pop-up,\r
2627         // or top-level window.\r
2628         // The SetWindowPos function changes the size, position, and Z order of a child, pop-up,\r
2629         // or top-level window.\r
2630         // The pInsertAfter can one of:  &wndTop, &wndTopMost, &wndBottom, or &wndNoTopMost\r
2631         {\r
2632                 assert(::IsWindow(m_hWnd));\r
2633                 HWND hWndInsertAfter = pInsertAfter? pInsertAfter->GetHwnd() : (HWND)0;\r
2634                 return ::SetWindowPos(m_hWnd, hWndInsertAfter, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, uFlags);\r
2635         }\r
2636 \r
2637         inline int CWnd::SetWindowRgn(CRgn* pRgn, BOOL bRedraw /*= TRUE*/) const\r
2638         // The SetWindowRgn function sets the window region of the window.\r
2639         // The window region determines the area within the window where the system permits drawing.\r
2640         {\r
2641                 assert(::IsWindow(m_hWnd));\r
2642                 HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;\r
2643                 int iResult = ::SetWindowRgn(m_hWnd, hRgn, bRedraw);\r
2644                 if (iResult && pRgn)\r
2645                         pRgn->Detach(); // The system owns the region now\r
2646                 return iResult;\r
2647         }\r
2648 \r
2649         inline BOOL CWnd::SetDlgItemInt(int nIDDlgItem, UINT uValue, BOOL bSigned) const\r
2650         // The SetDlgItemInt function sets the text of a control in a dialog box to the string representation of a specified integer value.\r
2651         {\r
2652                 assert(::IsWindow(m_hWnd));\r
2653                 return ::SetDlgItemInt(m_hWnd, nIDDlgItem, uValue, bSigned);\r
2654         }\r
2655 \r
2656         inline BOOL CWnd::SetDlgItemText(int nIDDlgItem, LPCTSTR lpString) const\r
2657         // The SetDlgItemText function sets the title or text of a control in a dialog box.\r
2658         {\r
2659                 assert(::IsWindow(m_hWnd));\r
2660                 return ::SetDlgItemText(m_hWnd, nIDDlgItem, lpString);\r
2661         }\r
2662 \r
2663         inline UINT_PTR CWnd::SetTimer(UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc) const\r
2664         // Creates a timer with the specified time-out value.\r
2665         {\r
2666                 assert(::IsWindow(m_hWnd));\r
2667                 return ::SetTimer(m_hWnd, nIDEvent, uElapse, lpTimerFunc);\r
2668         }\r
2669 \r
2670         inline BOOL CWnd::SetWindowText(LPCTSTR lpString) const\r
2671         // The SetWindowText function changes the text of the window's title bar (if it has one).\r
2672         {\r
2673                 assert(::IsWindow(m_hWnd));\r
2674                 return ::SetWindowText(m_hWnd, lpString);\r
2675         }\r
2676 \r
2677         inline HRESULT CWnd::SetWindowTheme(LPCWSTR pszSubAppName, LPCWSTR pszSubIdList) const\r
2678         // Set the XP Theme for a window.\r
2679         // Exampes:\r
2680         //  SetWindowTheme(NULL, NULL);         // Reverts the window's XP theme back to default\r
2681         //  SetWindowTheme(L" ", L" ");         // Disables XP theme for the window\r
2682         {\r
2683                 HRESULT hr = E_NOTIMPL;\r
2684 \r
2685 #ifndef _WIN32_WCE\r
2686 \r
2687                 HMODULE hMod = ::LoadLibrary(_T("uxtheme.dll"));\r
2688                 if(hMod)\r
2689                 {\r
2690                         typedef HRESULT (__stdcall *PFNSETWINDOWTHEME)(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);\r
2691                         PFNSETWINDOWTHEME pfn = (PFNSETWINDOWTHEME)GetProcAddress(hMod, "SetWindowTheme");\r
2692 \r
2693                         hr = (*pfn)(m_hWnd, pszSubAppName, pszSubIdList);\r
2694 \r
2695                         ::FreeLibrary(hMod);\r
2696                 }\r
2697 \r
2698 #endif\r
2699 \r
2700                 return hr;\r
2701         }\r
2702 \r
2703         inline BOOL CWnd::ShowWindow(int nCmdShow /*= SW_SHOWNORMAL*/) const\r
2704         // The ShowWindow function sets the window's show state.\r
2705         {\r
2706                 assert(::IsWindow(m_hWnd));\r
2707                 return ::ShowWindow(m_hWnd, nCmdShow);\r
2708         }\r
2709 \r
2710         inline BOOL CWnd::UpdateWindow() const\r
2711         // The UpdateWindow function updates the client area of the window by sending a\r
2712         // WM_PAINT message to the window if the window's update region is not empty.\r
2713         // If the update region is empty, no message is sent.\r
2714         {\r
2715                 assert(::IsWindow(m_hWnd));\r
2716                 return ::UpdateWindow(m_hWnd);\r
2717         }\r
2718 \r
2719         inline BOOL CWnd::ValidateRect(LPCRECT prc) const\r
2720         // The ValidateRect function validates the client area within a rectangle by\r
2721         // removing the rectangle from the update region of the window.\r
2722         {\r
2723                 assert(::IsWindow(m_hWnd));\r
2724                 return ::ValidateRect(m_hWnd, prc);\r
2725         }\r
2726 \r
2727         inline BOOL CWnd::ValidateRgn(CRgn* pRgn) const\r
2728         // The ValidateRgn function validates the client area within a region by\r
2729         // removing the region from the current update region of the window.\r
2730         {\r
2731                 assert(::IsWindow(m_hWnd));\r
2732                 HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;\r
2733                 return ::ValidateRgn(m_hWnd, hRgn);\r
2734         }\r
2735 \r
2736         inline CWnd* CWnd::WindowFromPoint(POINT pt)\r
2737         // Retrieves the window that contains the specified point (in screen coodinates).\r
2738         {\r
2739                 return FromHandle(::WindowFromPoint(pt));\r
2740         }\r
2741 \r
2742         //\r
2743         // These functions aren't supported on WinCE\r
2744         //\r
2745   #ifndef _WIN32_WCE\r
2746         inline BOOL CWnd::CloseWindow() const\r
2747         // The CloseWindow function minimizes (but does not destroy) the window.\r
2748         // To destroy a window, an application can use the Destroy function.\r
2749         {\r
2750                 assert(::IsWindow(m_hWnd));\r
2751                 return ::CloseWindow(m_hWnd);\r
2752         }\r
2753 \r
2754         inline int CWnd::DlgDirList(LPTSTR lpPathSpec, int nIDListBox, int nIDStaticPath, UINT uFileType) const\r
2755         // The DlgDirList function replaces the contents of a list box with the names of the subdirectories and files\r
2756         // in a specified directory. You can filter the list of names by specifying a set of file attributes.\r
2757         {\r
2758                 assert(::IsWindow(m_hWnd));\r
2759                 return ::DlgDirList(m_hWnd, lpPathSpec, nIDListBox, nIDStaticPath, uFileType);\r
2760         }\r
2761 \r
2762         inline int CWnd::DlgDirListComboBox(LPTSTR lpPathSpec, int nIDComboBox, int nIDStaticPath, UINT uFiletype) const\r
2763         // The DlgDirListComboBox function replaces the contents of a combo box with the names of the subdirectories\r
2764         // and files in a specified directory. You can filter the list of names by specifying a set of file attributes.\r
2765         {\r
2766                 assert(::IsWindow(m_hWnd));\r
2767                 return ::DlgDirListComboBox(m_hWnd, lpPathSpec, nIDComboBox, nIDStaticPath, uFiletype);\r
2768         }\r
2769 \r
2770         inline BOOL CWnd::DlgDirSelectEx(LPTSTR lpString, int nCount, int nIDListBox) const\r
2771         // The DlgDirSelectEx function retrieves the current selection from a single-selection list box. It assumes that the list box\r
2772         // has been filled by the DlgDirList function and that the selection is a drive letter, filename, or directory name.\r
2773         {\r
2774                 assert(::IsWindow(m_hWnd));\r
2775                 return ::DlgDirSelectEx(m_hWnd, lpString, nCount, nIDListBox);\r
2776         }\r
2777 \r
2778         inline BOOL CWnd::DlgDirSelectComboBoxEx(LPTSTR lpString, int nCount, int nIDComboBox) const\r
2779         // The DlgDirSelectComboBoxEx function retrieves the current selection from a combo box filled by using the\r
2780         // DlgDirListComboBox function. The selection is interpreted as a drive letter, a file, or a directory name.\r
2781         {\r
2782                 assert(::IsWindow(m_hWnd));\r
2783                 return ::DlgDirSelectComboBoxEx(m_hWnd, lpString, nCount, nIDComboBox);\r
2784         }\r
2785 \r
2786     #ifndef WIN32_LEAN_AND_MEAN\r
2787     inline void CWnd::DragAcceptFiles(BOOL fAccept) const\r
2788         // Registers whether a window accepts dropped files.\r
2789         {\r
2790                 assert(::IsWindow(m_hWnd));\r
2791                 ::DragAcceptFiles(m_hWnd, fAccept);\r
2792         }\r
2793     #endif\r
2794 \r
2795         inline BOOL CWnd::DrawAnimatedRects(int idAni, RECT& rcFrom, RECT& rcTo) const\r
2796         // The DrawAnimatedRects function draws a wire-frame rectangle and animates it to indicate the opening of\r
2797         // an icon or the minimizing or maximizing of a window.\r
2798         {\r
2799                 assert(::IsWindow(m_hWnd));\r
2800                 return ::DrawAnimatedRects(m_hWnd, idAni, &rcFrom, &rcTo);\r
2801         }\r
2802 \r
2803         inline BOOL CWnd::DrawCaption(CDC* pDC, RECT& rc, UINT uFlags) const\r
2804         // The DrawCaption function draws a window caption.\r
2805         {\r
2806                 assert(::IsWindow(m_hWnd));\r
2807                 assert(pDC);\r
2808                 return ::DrawCaption(m_hWnd, pDC->GetHDC(), &rc, uFlags);\r
2809         }\r
2810 \r
2811         inline BOOL CWnd::EnableScrollBar(UINT uSBflags, UINT uArrows) const\r
2812         // The EnableScrollBar function enables or disables one or both scroll bar arrows.\r
2813         {\r
2814                 assert(::IsWindow(m_hWnd));\r
2815                 return ::EnableScrollBar(m_hWnd, uSBflags, uArrows);\r
2816         }\r
2817 \r
2818         inline CWnd* CWnd::GetLastActivePopup() const\r
2819         // The GetLastActivePopup function determines which pop-up window owned by the specified window was most recently active.\r
2820         {\r
2821                 assert(::IsWindow(m_hWnd));\r
2822                 return FromHandle( ::GetLastActivePopup(m_hWnd) );\r
2823         }\r
2824 \r
2825         inline CMenu* CWnd::GetMenu() const\r
2826         // The GetMenu function retrieves a handle to the menu assigned to the window.\r
2827         {\r
2828                 assert(::IsWindow(m_hWnd));\r
2829                 return FromHandle(::GetMenu(m_hWnd));\r
2830         }\r
2831 \r
2832         inline int CWnd::GetScrollPos(int nBar) const\r
2833         // The GetScrollPos function retrieves the current position of the scroll box\r
2834         // (thumb) in the specified scroll bar.\r
2835         {\r
2836                 assert(::IsWindow(m_hWnd));\r
2837                 return ::GetScrollPos(m_hWnd, nBar);\r
2838         }\r
2839 \r
2840         inline BOOL CWnd::GetScrollRange(int nBar, int& MinPos, int& MaxPos) const\r
2841         // The GetScrollRange function retrieves the current minimum and maximum scroll box\r
2842         // (thumb) positions for the specified scroll bar.\r
2843         {\r
2844                 assert(::IsWindow(m_hWnd));\r
2845                 return ::GetScrollRange(m_hWnd, nBar, &MinPos, &MaxPos );\r
2846         }\r
2847 \r
2848         inline CMenu* CWnd::GetSystemMenu(BOOL bRevert) const\r
2849         // The GetSystemMenu function allows the application to access the window menu (also known as the system menu\r
2850         // or the control menu) for copying and modifying.\r
2851         {\r
2852                 assert(::IsWindow(m_hWnd));\r
2853                 return FromHandle(::GetSystemMenu(m_hWnd, bRevert));\r
2854         }\r
2855 \r
2856         inline CWnd* CWnd::GetTopWindow() const\r
2857         // The GetTopWindow function examines the Z order of the child windows associated with the parent window and\r
2858         // retrieves a handle to the child window at the top of the Z order.\r
2859         {\r
2860                 assert(::IsWindow(m_hWnd));\r
2861                 return FromHandle( ::GetTopWindow(m_hWnd) );\r
2862         }\r
2863 \r
2864         inline BOOL CWnd::GetWindowPlacement(WINDOWPLACEMENT& wndpl) const\r
2865         // The GetWindowPlacement function retrieves the show state and the restored,\r
2866         // minimized, and maximized positions of the window.\r
2867         {\r
2868                 assert(::IsWindow(m_hWnd));\r
2869                 return ::GetWindowPlacement(m_hWnd, &wndpl);\r
2870         }\r
2871 \r
2872         inline BOOL CWnd::HiliteMenuItem(CMenu* pMenu, UINT uItemHilite, UINT uHilite) const\r
2873         // The HiliteMenuItem function highlights or removes the highlighting from an item in a menu bar.\r
2874         {\r
2875                 assert(::IsWindow(m_hWnd));\r
2876                 assert(pMenu);\r
2877                 return ::HiliteMenuItem(m_hWnd, pMenu->GetHandle(), uItemHilite, uHilite);\r
2878         }\r
2879 \r
2880         inline BOOL CWnd::IsIconic() const\r
2881         // The IsIconic function determines whether the window is minimized (iconic).\r
2882         {\r
2883                 assert(::IsWindow(m_hWnd));\r
2884                 return ::IsIconic(m_hWnd);\r
2885         }\r
2886 \r
2887         inline BOOL CWnd::IsZoomed() const\r
2888         // The IsZoomed function determines whether the window is maximized.\r
2889         {\r
2890                 assert(::IsWindow(m_hWnd));\r
2891                 return ::IsZoomed(m_hWnd);\r
2892         }\r
2893 \r
2894         inline BOOL CWnd::KillTimer(UINT_PTR uIDEvent) const\r
2895         // Destroys the specified timer.\r
2896         {\r
2897                 assert(::IsWindow(m_hWnd));\r
2898                 return ::KillTimer(m_hWnd, uIDEvent);\r
2899         }\r
2900 \r
2901         inline BOOL CWnd::LockWindowUpdate() const\r
2902         // Disables drawing in the window. Only one window can be locked at a time.\r
2903         // Use UnLockWindowUpdate to re-enable drawing in the window\r
2904         {\r
2905                 assert(::IsWindow(m_hWnd));\r
2906                 return ::LockWindowUpdate(m_hWnd);\r
2907         }\r
2908 \r
2909         inline BOOL CWnd::OpenIcon() const\r
2910         // The OpenIcon function restores a minimized (iconic) window to its previous size and position.\r
2911         {\r
2912                 assert(::IsWindow(m_hWnd));\r
2913                 return ::OpenIcon(m_hWnd);\r
2914         }\r
2915 \r
2916         inline void CWnd::Print(CDC* pDC, DWORD dwFlags) const\r
2917         // Requests that the window draw itself in the specified device context, most commonly in a printer device context.\r
2918         {\r
2919                 assert(::IsWindow(m_hWnd));\r
2920                 assert(pDC);\r
2921                 SendMessage(m_hWnd, WM_PRINT, (WPARAM)pDC, (LPARAM)dwFlags);\r
2922         }\r
2923 \r
2924         inline BOOL CWnd::ScrollWindow(int XAmount, int YAmount, LPCRECT lprcScroll, LPCRECT lprcClip) const\r
2925         // The ScrollWindow function scrolls the contents of the specified window's client area.\r
2926         {\r
2927                 assert(::IsWindow(m_hWnd));\r
2928                 return ::ScrollWindow(m_hWnd, XAmount, YAmount, lprcScroll, lprcClip);\r
2929         }\r
2930 \r
2931         inline int CWnd::ScrollWindowEx(int dx, int dy, LPCRECT lprcScroll, LPCRECT lprcClip, CRgn* prgnUpdate, LPRECT lprcUpdate, UINT flags) const\r
2932         // The ScrollWindow function scrolls the contents of the window's client area.\r
2933         {\r
2934                 assert(::IsWindow(m_hWnd));\r
2935                 HRGN hrgnUpdate = prgnUpdate? (HRGN)prgnUpdate->GetHandle() : NULL;\r
2936                 return ::ScrollWindowEx(m_hWnd, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate, flags);\r
2937         }\r
2938 \r
2939         inline BOOL CWnd::SetMenu(CMenu* pMenu) const\r
2940         // The SetMenu function assigns a menu to the specified window.\r
2941         // A hMenu of NULL removes the menu.\r
2942         {\r
2943                 assert(::IsWindow(m_hWnd));\r
2944                 return ::SetMenu(m_hWnd, pMenu? pMenu->GetHandle() : NULL);\r
2945         }\r
2946 \r
2947         inline int CWnd::SetScrollInfo(int fnBar, const SCROLLINFO& si, BOOL fRedraw) const\r
2948         // The SetScrollInfo function sets the parameters of a scroll bar, including\r
2949         // the minimum and maximum scrolling positions, the page size, and the\r
2950         // position of the scroll box (thumb).\r
2951         {\r
2952                 assert(::IsWindow(m_hWnd));\r
2953                 return ::SetScrollInfo(m_hWnd, fnBar, &si, fRedraw);\r
2954         }\r
2955 \r
2956         inline int CWnd::SetScrollPos(int nBar, int nPos, BOOL bRedraw) const\r
2957         // The SetScrollPos function sets the position of the scroll box (thumb) in\r
2958         // the specified scroll bar.\r
2959         {\r
2960                 assert(::IsWindow(m_hWnd));\r
2961                 return ::SetScrollPos(m_hWnd, nBar, nPos, bRedraw);\r
2962         }\r
2963 \r
2964         inline BOOL CWnd::SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw) const\r
2965         // The SetScrollRange function sets the minimum and maximum scroll box positions for the scroll bar.\r
2966         {\r
2967                 assert(::IsWindow(m_hWnd));\r
2968                 return ::SetScrollRange(m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);\r
2969         }\r
2970 \r
2971         inline BOOL CWnd::SetWindowPlacement(const WINDOWPLACEMENT& wndpl) const\r
2972         // The SetWindowPlacement function sets the show state and the restored, minimized,\r
2973         // and maximized positions of the window.\r
2974         {\r
2975                 assert(::IsWindow(m_hWnd));\r
2976                 return ::SetWindowPlacement(m_hWnd, &wndpl);\r
2977         }\r
2978 \r
2979         inline BOOL CWnd::ShowOwnedPopups(BOOL fShow) const\r
2980         // The ShowOwnedPopups function shows or hides all pop-up windows owned by the specified window.\r
2981         {\r
2982                 assert(::IsWindow(m_hWnd));\r
2983                 return ::ShowOwnedPopups(m_hWnd, fShow);\r
2984         }\r
2985 \r
2986         inline BOOL CWnd::ShowScrollBar(int nBar, BOOL bShow) const\r
2987         // The ShowScrollBar function shows or hides the specified scroll bar.\r
2988         {\r
2989                 assert(::IsWindow(m_hWnd));\r
2990                 return ::ShowScrollBar(m_hWnd, nBar, bShow);\r
2991         }\r
2992 \r
2993         inline BOOL CWnd::ShowWindowAsync(int nCmdShow) const\r
2994         // The ShowWindowAsync function sets the show state of a window created by a different thread.\r
2995         {\r
2996                 assert(::IsWindow(m_hWnd));\r
2997                 return ::ShowWindowAsync(m_hWnd, nCmdShow);\r
2998         }\r
2999 \r
3000         inline BOOL CWnd::UnLockWindowUpdate() const\r
3001         // Enables drawing in the window. Only one window can be locked at a time.\r
3002         // Use LockWindowUpdate to disable drawing in the window\r
3003         {\r
3004                 assert(::IsWindow(m_hWnd));\r
3005                 return ::LockWindowUpdate(0);\r
3006         }\r
3007 \r
3008         inline CWnd* CWnd::WindowFromDC(CDC* pDC) const\r
3009         // The WindowFromDC function returns a handle to the window associated with the specified display device context (DC).\r
3010         {\r
3011                 assert(pDC);\r
3012                 return FromHandle( ::WindowFromDC(pDC->GetHDC()) );\r
3013         }\r
3014 \r
3015 \r
3016   #endif\r
3017 \r
3018 }; // namespace Win32xx\r
3019 \r
3020 \r
3021 #endif // _WIN32XX_WINCORE_H_\r
3022 \r

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