1 // Win32++ Version 7.3
\r
2 // Released: 30th November 2011
\r
6 // url: https://sourceforge.net/projects/win32-framework
\r
9 // Copyright (c) 2005-2011 David Nash
\r
11 // Permission is hereby granted, free of charge, to
\r
12 // any person obtaining a copy of this software and
\r
13 // associated documentation files (the "Software"),
\r
14 // to deal in the Software without restriction, including
\r
15 // without limitation the rights to use, copy, modify,
\r
16 // merge, publish, distribute, sublicense, and/or sell
\r
17 // copies of the Software, and to permit persons to whom
\r
18 // the Software is furnished to do so, subject to the
\r
19 // following conditions:
\r
21 // The above copyright notice and this permission notice
\r
22 // shall be included in all copies or substantial portions
\r
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
\r
26 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
\r
27 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
\r
28 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
\r
29 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
\r
30 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
31 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
32 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
\r
33 // OR OTHER DEALINGS IN THE SOFTWARE.
\r
35 ////////////////////////////////////////////////////////
\r
38 ///////////////////////////////////////////////////////
\r
40 // Declaration of the following classes:
\r
41 // CWinApp, CWnd, CWinException, CCriticalSection,
\r
42 // CPoint, CRect, and CSize
\r
44 // This file contains the declarations for the core set of classes required to
\r
45 // create simple windows using Win32++.
\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
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
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
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
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
71 #ifndef _WIN32XX_WINCORE_H_
\r
72 #define _WIN32XX_WINCORE_H_
\r
75 // Remove pointless warning messages
\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
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
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
98 #pragma GCC diagnostic ignored "-Wmissing-braces"
\r
99 #pragma GCC diagnostic ignored "-Wunused-value"
\r
103 #include "wcestddef.h"
\r
106 #define _WINSOCKAPI_ // Prevent winsock.h #include's.
\r
108 #include <assert.h>
\r
110 #include <algorithm>
\r
113 #include <windows.h>
\r
114 #include <commctrl.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
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
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
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
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
181 // Required for WinCE
\r
182 #ifndef TLS_OUT_OF_INDEXES
\r
183 #define TLS_OUT_OF_INDEXES ((DWORD_PTR) -1)
\r
185 #ifndef WM_PARENTNOTIFY
\r
186 #define WM_PARENTNOTIFY 0x0210
\r
193 ////////////////////////////////////////////////
\r
194 // Forward declarations.
\r
195 // These classes are defined later or elsewhere
\r
208 // tString is a TCHAR std::string
\r
209 typedef std::basic_string<TCHAR> tString;
\r
211 // tStringStream is a TCHAR std::stringstream
\r
212 typedef std::basic_stringstream<TCHAR> tStringStream;
\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
226 enum Constants // Defines the maximum size for TCHAR strings
\r
228 MAX_MENU_STRING = 80,
\r
229 MAX_STRING_SIZE = 255,
\r
232 struct CompareHDC // The comparison function object used by CWinApp::m_mapHDC
\r
234 bool operator()(HDC const a, const HDC b) const
\r
235 {return ((DWORD_PTR)a < (DWORD_PTR)b);}
\r
238 struct CompareGDI // The comparison function object used by CWinApp::m_mapGDI
\r
240 bool operator()(HGDIOBJ const a, const HGDIOBJ b) const
\r
241 {return ((DWORD_PTR)a < (DWORD_PTR)b);}
\r
244 struct CompareHMENU // The comparison function object used by CWinApp::m_mapHMENU
\r
246 bool operator()(HMENU const a, const HMENU b) const
\r
247 {return ((DWORD_PTR)a < (DWORD_PTR)b);}
\r
250 struct CompareHWND // The comparison function object used by CWinApp::m_mapHWND
\r
252 bool operator()(HWND const a, const HWND b) const
\r
253 {return ((DWORD_PTR)a < (DWORD_PTR)b);}
\r
256 struct TLSData // Used for Thread Local Storage (TLS)
\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
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
268 std::vector<MenuPtr> vTmpMenus; // A vector of temporary CMenu pointers
\r
273 /////////////////////////////////////////
\r
274 // Declarations for the CCriticalSection class
\r
275 // This class is used for thread synchronisation
\r
276 class CCriticalSection
\r
279 CCriticalSection() { ::InitializeCriticalSection(&m_cs); }
\r
280 ~CCriticalSection() { ::DeleteCriticalSection(&m_cs); }
\r
282 void Lock() { ::EnterCriticalSection(&m_cs); }
\r
283 void Release() { ::LeaveCriticalSection(&m_cs); }
\r
286 CCriticalSection ( const CCriticalSection& );
\r
287 CCriticalSection& operator = ( const CCriticalSection& );
\r
289 CRITICAL_SECTION m_cs;
\r
293 ////////////////////////////////////////
\r
294 // Declaration of the CWinException class
\r
296 // Note: Each function guarantees not to throw an exception
\r
298 class CWinException : public std::exception
\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
310 TCHAR m_szErrorString[MAX_STRING_SIZE];
\r
314 ///////////////////////////////////
\r
315 // Declaration of the CWinApp class
\r
319 // Provide these access to CWinApp's private members:
\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
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
340 friend CMenu* FromHandle(HMENU hMenu);
\r
343 typedef Shared_Ptr<TLSData> TLSDataPtr;
\r
347 virtual ~CWinApp();
\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
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
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
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
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
399 #include "winutils.h"
\r
400 #include "cstring.h"
\r
405 ////////////////////////////////
\r
406 // Declaration of the CWnd class
\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
417 CWnd(); // Constructor
\r
418 CWnd(HWND hWnd) // Constructor
\r
420 if (hWnd == HWND_TOP || hWnd == HWND_TOPMOST || hWnd == HWND_BOTTOM || hWnd == HWND_NOTOPMOST)
\r
427 virtual ~CWnd(); // Destructor
\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
442 HWND GetHwnd() const { return m_hWnd; }
\r
443 WNDPROC GetPrevWindowProc() const { return m_PrevWindowProc; }
\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
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
573 #ifndef WIN32_LEAN_AND_MEAN
\r
574 void DragAcceptFiles(BOOL fAccept) const;
\r
578 static LRESULT CALLBACK StaticWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
\r
579 operator HWND() const { return m_hWnd; }
\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
599 HWND m_hWnd; // handle to this object's window
\r
602 CWnd(const CWnd&); // Disable copy construction
\r
603 CWnd& operator = (const CWnd&); // Disable assignment operator
\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
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
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
625 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\r
633 //////////////////////////////////////////
\r
634 // Definitions for the CWinException class
\r
636 inline CWinException::CWinException(LPCTSTR pszText) throw () : m_Error(::GetLastError()), m_pszText(pszText)
\r
638 memset(m_szErrorString, 0, MAX_STRING_SIZE * sizeof(TCHAR));
\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
647 inline DWORD CWinException::GetError() const throw ()
\r
652 inline LPCTSTR CWinException::GetErrorString() const throw ()
\r
654 return m_szErrorString;
\r
657 inline const char * CWinException::what() const throw ()
\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
665 ////////////////////////////////////
\r
666 // Definitions for the CWinApp class
\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
675 m_csAppStart.Lock();
\r
676 assert( 0 == SetnGetThis() ); // Test if this is the first instance of CWinApp
\r
678 m_dwTlsIndex = ::TlsAlloc();
\r
679 if (m_dwTlsIndex == TLS_OUT_OF_INDEXES)
\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
688 m_csAppStart.Release();
\r
690 // Set the instance handle
\r
692 m_hInstance = (HINSTANCE)GetModuleHandle(0);
\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
700 m_hResource = m_hInstance;
\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
712 catch (const CWinException &e)
\r
719 inline CWinApp::~CWinApp()
\r
721 std::vector<TLSDataPtr>::iterator iter;
\r
722 for (iter = m_vTLSData.begin(); iter < m_vTLSData.end(); ++iter)
\r
724 (*iter)->vTmpDCs.clear();
\r
726 (*iter)->vTmpMenus.clear();
\r
728 (*iter)->vTmpWnds.clear();
\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
735 HWND hWnd = (*m).first;
\r
736 if (::IsWindow(hWnd))
\r
737 ::DestroyWindow(hWnd);
\r
742 m_mapHMENU.clear();
\r
744 // Do remaining tidy up
\r
745 if (m_dwTlsIndex != TLS_OUT_OF_INDEXES)
\r
747 ::TlsSetValue(GetTlsIndex(), NULL);
\r
748 ::TlsFree(m_dwTlsIndex);
\r
751 SetnGetThis((CWinApp*)-1);
\r
754 inline void CWinApp::AddTmpDC(CDC* pDC)
\r
756 // The TmpMenus are created by GetSybMenu.
\r
757 // They are removed by CleanupTemps
\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
765 inline void CWinApp::AddTmpGDI(CGDIObject* pObject)
\r
767 // The temporary CGDIObjects are removed by CleanupTemps
\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
776 inline CMenu* CWinApp::AddTmpMenu(HMENU hMenu)
\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
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
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
797 inline CWnd* CWinApp::AddTmpWnd(HWND hWnd)
\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
804 CWnd* pWnd = new CWnd;
\r
805 pWnd->m_hWnd = hWnd;
\r
807 pWnd->m_IsTmpWnd = TRUE;
\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
815 inline void CWinApp::CleanupTemps()
\r
816 // Removes all Temporary CWnds and CMenus belonging to this thread
\r
818 // Retrieve the pointer to the TLS Data
\r
819 TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());
\r
822 pTLSData->vTmpDCs.clear();
\r
823 pTLSData->vTmpGDIs.clear();
\r
824 pTLSData->vTmpWnds.clear();
\r
828 pTLSData->vTmpMenus.clear();
\r
832 inline CDC* CWinApp::GetCDCFromMap(HDC hDC)
\r
834 // Allocate an iterator for our HWND map
\r
835 std::map<HDC, CDC*, CompareHDC>::iterator m;
\r
837 // Find the CDC pointer mapped to this HDC
\r
839 m_csMapLock.Lock();
\r
840 m = m_mapHDC.find(hDC);
\r
842 if (m != m_mapHDC.end())
\r
845 m_csMapLock.Release();
\r
849 inline CGDIObject* CWinApp::GetCGDIObjectFromMap(HGDIOBJ hObject)
\r
851 // Allocate an iterator for our HWND map
\r
852 std::map<HGDIOBJ, CGDIObject*, CompareGDI>::iterator m;
\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
859 if (m != m_mapGDI.end())
\r
860 pObject = m->second;
\r
862 m_csMapLock.Release();
\r
866 inline CMenu* CWinApp::GetCMenuFromMap(HMENU hMenu)
\r
868 std::map<HMENU, CMenu*, CompareHMENU>::iterator m;
\r
870 // Find the CMenu pointer mapped to this HMENU
\r
872 m_csMapLock.Lock();
\r
873 m = m_mapHMENU.find(hMenu);
\r
875 if (m != m_mapHMENU.end())
\r
878 m_csMapLock.Release();
\r
882 inline CWnd* CWinApp::GetCWndFromMap(HWND hWnd)
\r
884 // Allocate an iterator for our HWND map
\r
885 std::map<HWND, CWnd*, CompareHWND>::iterator m;
\r
887 // Find the CWnd pointer mapped to this HWND
\r
889 m_csMapLock.Lock();
\r
890 m = m_mapHWND.find(hWnd);
\r
892 if (m != m_mapHWND.end())
\r
895 m_csMapLock.Release();
\r
899 inline BOOL CWinApp::InitInstance()
\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
904 // return TRUE to indicate success. FALSE will end the application
\r
908 inline int CWinApp::MessageLoop()
\r
910 // This gets any messages queued for the application, and dispatches them.
\r
915 while (status != 0)
\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
925 // Now wait until we get a message
\r
926 if ((status = ::GetMessage(&Msg, NULL, 0, 0)) == -1)
\r
929 if (!PreTranslateMessage(Msg))
\r
931 ::TranslateMessage(&Msg);
\r
932 ::DispatchMessage(&Msg);
\r
936 return LOWORD(Msg.wParam);
\r
939 inline BOOL CWinApp::OnIdle(LONG lCount)
\r
947 inline BOOL CWinApp::PreTranslateMessage(MSG Msg)
\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
953 BOOL Processed = FALSE;
\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
959 // Process keyboard accelerators
\r
960 if (m_pWndAccel && ::TranslateAccelerator(*m_pWndAccel, m_hAccel, &Msg))
\r
964 // Search the chain of parents for pretranslated messages.
\r
965 for (HWND hWnd = Msg.hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd))
\r
967 CWnd* pWnd = GetCWndFromMap(hWnd);
\r
970 Processed = pWnd->PreTranslateMessage(&Msg);
\r
981 inline int CWinApp::Run()
\r
983 // InitInstance runs the App's initialization code
\r
984 if (InitInstance())
\r
986 // Dispatch the window messages
\r
987 return MessageLoop();
\r
991 TRACE(_T("InitInstance failed! Terminating program\n"));
\r
992 ::PostQuitMessage(-1);
\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
1002 assert (pWndAccel);
\r
1004 m_pWndAccel = pWndAccel;
\r
1005 m_hAccel = hAccel;
\r
1008 inline void CWinApp::SetCallback()
\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
1014 WNDCLASS wcDefault = {0};
\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
1021 ::RegisterClass(&wcDefault);
\r
1023 // Retrieve the class information
\r
1024 ZeroMemory(&wcDefault, sizeof(wcDefault));
\r
1025 ::GetClassInfo(GetInstanceHandle(), szClassName, &wcDefault);
\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
1033 inline CWinApp* CWinApp::SetnGetThis(CWinApp* pThis /*= 0*/)
\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
1039 static CWinApp* pWinApp = 0;
\r
1041 if ((CWinApp*)-1 == pThis)
\r
1043 else if (0 == pWinApp)
\r
1049 inline void CWinApp::SetResourceHandle(HINSTANCE hResource)
\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
1055 // HINSTANCE hResource = LoadLibrary(_T("MyResourceDLL.dll"));
\r
1056 // SetResourceHandle(hResource);
\r
1058 m_hResource = hResource;
\r
1061 inline TLSData* CWinApp::SetTlsIndex()
\r
1063 TLSData* pTLSData = (TLSData*)::TlsGetValue(GetTlsIndex());
\r
1064 if (NULL == pTLSData)
\r
1066 pTLSData = new TLSData;
\r
1068 m_csTLSLock.Lock();
\r
1069 m_vTLSData.push_back(pTLSData); // store as a Shared_Ptr
\r
1070 m_csTLSLock.Release();
\r
1072 ::TlsSetValue(GetTlsIndex(), pTLSData);
\r
1079 ////////////////////////////////////////
\r
1080 // Definitions for the CWnd class
\r
1082 inline CWnd::CWnd() : m_hWnd(NULL), m_PrevWindowProc(NULL), m_IsTmpWnd(FALSE)
\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
1091 inline CWnd::~CWnd()
\r
1093 // Destroys the window for this object and cleans up resources.
\r
1097 inline void CWnd::AddToMap()
\r
1098 // Store the window handle and CWnd pointer in the HWND map
\r
1100 assert( GetApp() );
\r
1101 GetApp()->m_csMapLock.Lock();
\r
1103 // assert(::IsWindow(m_hWnd));
\r
1104 assert(!GetApp()->GetCWndFromMap(m_hWnd));
\r
1106 GetApp()->m_mapHWND.insert(std::make_pair(m_hWnd, this));
\r
1107 GetApp()->m_csMapLock.Release();
\r
1110 inline BOOL CWnd::Attach(HWND hWnd)
\r
1111 // Subclass an existing window and attach it to a CWnd
\r
1113 assert( GetApp() );
\r
1114 assert(::IsWindow(hWnd));
\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
1120 // Cleanup any previous attachment
\r
1121 if (m_PrevWindowProc)
\r
1123 CWnd* pWnd = GetApp()->GetCWndFromMap(hWnd);
\r
1127 Subclass(hWnd); // Set the window's callback to CWnd::StaticWindowProc
\r
1128 AddToMap(); // Store the CWnd pointer in the HWND map
\r
1130 OnInitialUpdate();
\r
1135 inline BOOL CWnd::AttachDlgItem(UINT nID, CWnd* pParent)
\r
1136 // Converts a dialog item to a CWnd object
\r
1138 assert(pParent->IsWindow());
\r
1140 HWND hWnd = ::GetDlgItem(pParent->GetHwnd(), nID);
\r
1141 return Attach(hWnd);
\r
1144 inline void CWnd::CenterWindow() const
\r
1145 // Centers this window over it's parent
\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
1154 DECLARE_HANDLE(HMONITOR);
\r
1156 #ifndef MONITORINFO
\r
1157 typedef struct tagMONITORINFO
\r
1163 } MONITORINFO, *LPMONITORINFO;
\r
1164 #endif // MONITOR_DEFAULTTONEAREST
\r
1165 #endif // _WIN32_WCE
\r
1167 assert(::IsWindow(m_hWnd));
\r
1169 CRect rc = GetWindowRect();
\r
1173 // Get screen dimensions excluding task bar
\r
1174 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesktop, 0);
\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
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
1187 LPGMI pfnGetMonitorInfo = (LPGMI)::GetProcAddress(hUser32, "GetMonitorInfoW");
\r
1189 LPGMI pfnGetMonitorInfo = (LPGMI)::GetProcAddress(hUser32, "GetMonitorInfoA");
\r
1192 // Take multi-monitor systems into account
\r
1193 if (pfnGetMonitorInfo && pfnMonitorFromWindow)
\r
1195 HMONITOR hActiveMonitor = pfnMonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
\r
1196 MONITORINFO mi = { sizeof(mi), 0};
\r
1198 if(pfnGetMonitorInfo(hActiveMonitor, &mi))
\r
1200 rcDesktop = mi.rcWork;
\r
1201 if (GetParent() == NULL) rcParent = mi.rcWork;
\r
1204 FreeLibrary(hUser32);
\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
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
1218 SetWindowPos(0, x, y, 0, 0, SWP_NOSIZE);
\r
1221 inline void CWnd::Cleanup()
\r
1222 // Returns the CWnd to its default state
\r
1224 if ( GetApp() ) RemoveFromMap();
\r
1226 m_PrevWindowProc = NULL;
\r
1227 m_IsTmpWnd = FALSE;
\r
1230 inline HWND CWnd::Create(CWnd* pParent /* = NULL */)
\r
1231 // Creates the window. This is the default method of window creation.
\r
1234 // Test if Win32++ has been started
\r
1235 assert( GetApp() );
\r
1237 // Set the WNDCLASS parameters
\r
1238 PreRegisterClass(*m_pwc);
\r
1239 if (m_pwc->lpszClassName)
\r
1241 RegisterClass(*m_pwc);
\r
1242 m_pcs->lpszClass = m_pwc->lpszClassName;
\r
1245 // Set the CREATESTRUCT parameters
\r
1246 PreCreate(*m_pcs);
\r
1248 // Set the Window Class Name
\r
1249 if (!m_pcs->lpszClass)
\r
1250 m_pcs->lpszClass = _T("Win32++ Window");
\r
1253 HWND hWndParent = pParent? pParent->GetHwnd() : 0;
\r
1254 if (!hWndParent && m_pcs->hwndParent)
\r
1255 hWndParent = m_pcs->hwndParent;
\r
1257 // Set the window style
\r
1259 DWORD dwOverlappedStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
\r
1261 dwStyle = m_pcs->style;
\r
1263 dwStyle = WS_VISIBLE | ((hWndParent)? WS_CHILD : dwOverlappedStyle);
\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
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
1276 CreateEx(m_pcs->dwExStyle, m_pcs->lpszClass, m_pcs->lpszName, dwStyle, x, y,
\r
1277 cx, cy, pParent, 0, m_pcs->lpCreateParams);
\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
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
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
1297 assert( GetApp() ); // Test if Win32++ has been started
\r
1298 assert(!::IsWindow(m_hWnd)); // Only one window per CWnd instance allowed
\r
1302 // Prepare the CWnd if it has been reused
\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
1311 // Create our own local copy of szClassName.
\r
1312 lstrcpyn(ClassName, lpszClassName, MAX_STRING_SIZE);
\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
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
1323 HWND hWndParent = pParent? pParent->GetHwnd() : 0;
\r
1325 // Ensure this thread has the TLS index set
\r
1326 TLSData* pTLSData = GetApp()->SetTlsIndex();
\r
1328 // Store the CWnd pointer in thread local storage
\r
1329 pTLSData->pCWnd = this;
\r
1333 m_hWnd = ::CreateWindowEx(dwExStyle, ClassName, lpszWindowName, dwStyle, x, y, nWidth, nHeight,
\r
1334 hWndParent, 0, GetApp()->GetInstanceHandle(), lpParam);
\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
1341 // Now handle window creation failure
\r
1343 throw CWinException(_T("Failed to Create Window"));
\r
1345 // Automatically subclass predefined window class types
\r
1346 ::GetClassInfo(GetApp()->GetInstanceHandle(), lpszClassName, &wc);
\r
1347 if (wc.lpfnWndProc != GetApp()->m_Callback)
\r
1351 // Send a message to force the HWND to be added to the map
\r
1352 SendMessage(WM_NULL, 0L, 0L);
\r
1354 OnCreate(); // We missed the WM_CREATE message, so call OnCreate now
\r
1357 // Clear the CWnd pointer from TLS
\r
1358 pTLSData->pCWnd = NULL;
\r
1361 catch (const CWinException &e)
\r
1363 TRACE(_T("\n*** Failed to create window ***\n"));
\r
1364 e.what(); // Display the last error message.
\r
1366 // eat the exception (don't rethrow)
\r
1369 // Window creation is complete. Now call OnInitialUpdate
\r
1370 OnInitialUpdate();
\r
1375 inline void CWnd::Destroy()
\r
1376 // Destroys the window and returns the CWnd back to its default state, ready for reuse.
\r
1382 ::DestroyWindow(m_hWnd);
\r
1384 // Return the CWnd to its default state
\r
1388 inline HWND CWnd::Detach()
\r
1389 // Reverse an Attach
\r
1391 assert(::IsWindow(m_hWnd));
\r
1392 assert(0 != m_PrevWindowProc); // Only a subclassed window can be detached
\r
1394 SetWindowLongPtr(GWLP_WNDPROC, (LONG_PTR)m_PrevWindowProc);
\r
1395 HWND hWnd = m_hWnd;
\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
1405 return ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
\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
1412 assert(::IsWindow(m_hWnd));
\r
1413 HWND hWnd = m_hWnd;
\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
1422 // Declare a pointer to the GetAncestor function
\r
1423 #ifndef _WIN32_WCE
\r
1424 pfnGetAncestor = (GETANCESTOR*)::GetProcAddress(hModule, "GetAncestor");
\r
1426 pfnGetAncestor = (GETANCESTOR*)::GetProcAddress(hModule, L"GetAncestor");
\r
1429 if (pfnGetAncestor)
\r
1430 hWnd = (*pfnGetAncestor)(m_hWnd, gaFlags);
\r
1432 ::FreeLibrary(hModule);
\r
1435 if (!pfnGetAncestor)
\r
1437 // Provide our own GetAncestor if necessary
\r
1438 HWND hWndParent = ::GetParent(hWnd);
\r
1439 while (::IsChild(hWndParent, hWnd))
\r
1441 hWnd = hWndParent;
\r
1442 hWndParent = ::GetParent(hWnd);
\r
1446 return FromHandle(hWnd);
\r
1449 inline CString CWnd::GetClassName() const
\r
1450 // Retrieves the name of the class to which the specified window belongs.
\r
1452 assert(::IsWindow(m_hWnd));
\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
1461 inline CString CWnd::GetDlgItemText(int nIDDlgItem) const
\r
1462 // Retrieves the title or text associated with a control in a dialog box.
\r
1464 assert(::IsWindow(m_hWnd));
\r
1466 int nLength = ::GetWindowTextLength(::GetDlgItem(m_hWnd, nIDDlgItem));
\r
1468 LPTSTR szStr = str.GetBuffer(nLength+1);
\r
1469 ::GetDlgItemText(m_hWnd, nIDDlgItem, szStr, nLength+1);
\r
1470 str.ReleaseBuffer();
\r
1474 inline CString CWnd::GetWindowText() const
\r
1475 // Retrieves the text of the window's title bar.
\r
1477 assert(::IsWindow(m_hWnd));
\r
1479 int nLength = ::GetWindowTextLength(m_hWnd);
\r
1481 LPTSTR szStr = str.GetBuffer(nLength+1);
\r
1482 ::GetWindowText(m_hWnd, szStr, nLength+1);
\r
1483 str.ReleaseBuffer();
\r
1487 inline BOOL CWnd::OnCommand(WPARAM wParam, LPARAM lParam)
\r
1489 UNREFERENCED_PARAMETER(wParam);
\r
1490 UNREFERENCED_PARAMETER(lParam);
\r
1492 // Override this to handle WM_COMMAND messages, for example
\r
1494 // switch (LOWORD(wParam))
\r
1496 // case IDM_FILE_NEW:
\r
1498 // TRUE; // return TRUE for handled commands
\r
1501 // return FALSE for unhandled commands
\r
1505 inline void CWnd::OnCreate()
\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
1512 inline void CWnd::OnDraw(CDC* pDC)
\r
1513 // Called when part of the client area of the window needs to be drawn
\r
1515 UNREFERENCED_PARAMETER(pDC);
\r
1517 // Override this function in your derived class to perform drawing tasks.
\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
1523 UNREFERENCED_PARAMETER(pDC);
\r
1525 // Override this function in your derived class to perform drawing tasks.
\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
1534 inline void CWnd::OnInitialUpdate()
\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
1541 inline LRESULT CWnd::MessageReflect(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
1543 // A function used to call OnMessageReflect. You shouldn't need to call or
\r
1544 // override this function.
\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
1560 hWnd = (HWND)lParam;
\r
1564 case WM_MEASUREITEM:
\r
1565 case WM_DELETEITEM:
\r
1566 case WM_COMPAREITEM:
\r
1567 hWnd = ::GetDlgItem(hWndParent, (int)wParam);
\r
1570 case WM_PARENTNOTIFY:
\r
1571 switch(LOWORD(wParam))
\r
1575 hWnd = (HWND)lParam;
\r
1580 CWnd* Wnd = GetApp()->GetCWndFromMap(hWnd);
\r
1583 return Wnd->OnMessageReflect(uMsg, wParam, lParam);
\r
1588 inline LRESULT CWnd::OnMessageReflect(UINT uMsg, WPARAM wParam, LPARAM lParam)
\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
1597 // Your overriding function should look like this ...
\r
1601 // Handle your reflected messages here
\r
1604 // return 0L for unhandled messages
\r
1608 inline LRESULT CWnd::OnNotify(WPARAM wParam, LPARAM lParam)
\r
1610 UNREFERENCED_PARAMETER(wParam);
\r
1611 UNREFERENCED_PARAMETER(lParam);
\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
1619 // Your overriding function should look like this ...
\r
1621 // switch (((LPNMHDR)lParam)->code)
\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
1628 // return 0L for unhandled notifications
\r
1632 inline LRESULT CWnd::OnNotifyReflect(WPARAM wParam, LPARAM lParam)
\r
1634 UNREFERENCED_PARAMETER(wParam);
\r
1635 UNREFERENCED_PARAMETER(lParam);
\r
1637 // Override OnNotifyReflect to handle notifications in the CWnd class that
\r
1638 // generated the notification.
\r
1640 // Your overriding function should look like this ...
\r
1642 // switch (((LPNMHDR)lParam)->code)
\r
1644 // Handle your notifications from this window here
\r
1645 // Return the value recommended by the Windows API documentation.
\r
1648 // return 0L for unhandled notifications
\r
1652 inline void CWnd::OnMenuUpdate(UINT nID)
\r
1653 // Called when menu items are about to be displayed
\r
1655 UNREFERENCED_PARAMETER(nID);
\r
1657 // Override this function to modify the behaviour of menu items,
\r
1658 // such as adding or removing checkmarks
\r
1661 inline void CWnd::PreCreate(CREATESTRUCT& cs)
\r
1662 // Called by CWnd::Create to set some window parameters
\r
1664 // Test if Win32++ has been started
\r
1665 assert(GetApp()); // Test if Win32++ has been started
\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
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
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
1690 // Test if Win32++ has been started
\r
1691 assert( GetApp() );
\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
1704 // Overide this function in your derived class to set the
\r
1705 // WNDCLASS values prior to window creation.
\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
1720 inline BOOL CWnd::PreTranslateMessage(MSG* pMsg)
\r
1722 UNREFERENCED_PARAMETER(pMsg);
\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
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
1736 assert( GetApp() );
\r
1737 assert( (0 != lstrlen(wc.lpszClassName) && ( lstrlen(wc.lpszClassName) <= MAX_STRING_SIZE) ) );
\r
1739 // Check to see if this classname is already registered
\r
1740 WNDCLASS wcTest = {0};
\r
1741 BOOL Done = FALSE;
\r
1743 if (::GetClassInfo(GetApp()->GetInstanceHandle(), wc.lpszClassName, &wcTest))
\r
1752 wc.hInstance = GetApp()->GetInstanceHandle();
\r
1753 wc.lpfnWndProc = CWnd::StaticWindowProc;
\r
1755 // Register the WNDCLASS structure
\r
1756 if ( !::RegisterClass(&wc) )
\r
1757 throw CWinException(_T("Failed to register window class"));
\r
1765 inline BOOL CWnd::RemoveFromMap()
\r
1767 BOOL Success = FALSE;
\r
1772 // Allocate an iterator for our HWND map
\r
1773 std::map<HWND, CWnd*, CompareHWND>::iterator m;
\r
1775 CWinApp* pApp = GetApp();
\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
1782 if (this == m->second)
\r
1784 pApp->m_mapHWND.erase(m);
\r
1790 pApp->m_csMapLock.Release();
\r
1797 inline HICON CWnd::SetIconLarge(int nIcon)
\r
1798 // Sets the large icon associated with the window
\r
1800 assert( GetApp() );
\r
1801 assert(::IsWindow(m_hWnd));
\r
1803 HICON hIconLarge = (HICON) (::LoadImage (GetApp()->GetResourceHandle(), MAKEINTRESOURCE (nIcon), IMAGE_ICON,
\r
1804 ::GetSystemMetrics (SM_CXICON), ::GetSystemMetrics (SM_CYICON), 0));
\r
1807 SendMessage (WM_SETICON, WPARAM (ICON_BIG), LPARAM (hIconLarge));
\r
1809 TRACE(_T("**WARNING** SetIconLarge Failed\n"));
\r
1811 return hIconLarge;
\r
1814 inline HICON CWnd::SetIconSmall(int nIcon)
\r
1815 // Sets the small icon associated with the window
\r
1817 assert( GetApp() );
\r
1818 assert(::IsWindow(m_hWnd));
\r
1820 HICON hIconSmall = (HICON) (::LoadImage (GetApp()->GetResourceHandle(), MAKEINTRESOURCE (nIcon), IMAGE_ICON,
\r
1821 ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0));
\r
1824 SendMessage (WM_SETICON, WPARAM (ICON_SMALL), LPARAM (hIconSmall));
\r
1826 TRACE(_T("**WARNING** SetIconSmall Failed\n"));
\r
1828 return hIconSmall;
\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
1835 assert( GetApp() );
\r
1837 CWnd* w = GetApp()->GetCWndFromMap(hWnd);
\r
1840 // The CWnd pointer wasn't found in the map, so add it now
\r
1842 // Retrieve the pointer to the TLS Data
\r
1843 TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());
\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
1851 // Store the CWnd pointer in the HWND map
\r
1856 return w->WndProc(uMsg, wParam, lParam);
\r
1858 } // LRESULT CALLBACK StaticWindowProc(...)
\r
1860 inline void CWnd::Subclass(HWND hWnd)
\r
1861 // A private function used by CreateEx, Attach and AttachDlgItem
\r
1863 assert(::IsWindow(hWnd));
\r
1865 m_PrevWindowProc = (WNDPROC)::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)CWnd::StaticWindowProc);
\r
1869 inline LRESULT CWnd::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\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
1876 // case MESSAGE1: // Some Windows API message
\r
1877 // OnMessage1(); // A user defined function
\r
1878 // break; // Also do default processing
\r
1881 // return x; // Don't do default processing, but instead return
\r
1882 // // a value recommended by the Windows API documentation
\r
1885 // Always pass unhandled messages on to WndProcDefault
\r
1886 return WndProcDefault(uMsg, wParam, lParam);
\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
1896 case UWM_CLEANUPTEMPS:
\r
1898 TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());
\r
1899 pTLSData->vTmpWnds.clear();
\r
1904 // Refelect this message if it's from a control
\r
1905 CWnd* pWnd = GetApp()->GetCWndFromMap((HWND)lParam);
\r
1907 lr = pWnd->OnCommand(wParam, lParam);
\r
1909 // Handle user commands
\r
1911 lr = OnCommand(wParam, lParam);
\r
1913 if (lr) return 0L;
\r
1915 break; // Note: Some MDI commands require default processing
\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
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
1930 if (lstrcmp(GetClassName(), _T("ReBarWindow32")) != 0) // Skip notification reflection for rebars to avoid double handling
\r
1932 if (pWndFrom != NULL)
\r
1933 lr = pWndFrom->OnNotifyReflect(wParam, lParam);
\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
1944 // Handle user notifications
\r
1945 if (!lr) lr = OnNotify(wParam, lParam);
\r
1946 if (lr) return lr;
\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
1956 if (::GetUpdateRect(m_hWnd, NULL, FALSE))
\r
1958 CPaintDC dc(this);
\r
1962 // RedrawWindow can require repainting without an update rect
\r
1964 CClientDC dc(this);
\r
1970 case WM_ERASEBKGND:
\r
1972 CDC dc((HDC)wParam);
\r
1973 BOOL bResult = OnEraseBkgnd(&dc);
\r
1975 if (bResult) return TRUE;
\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
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
1994 case WM_PARENTNOTIFY:
\r
1996 // if (m_PrevWindowProc) break; // Suppress for subclassed windows
\r
1998 LRESULT lr = MessageReflect(m_hWnd, uMsg, wParam, lParam);
\r
1999 if (lr) return lr; // Message processed so return
\r
2001 break; // Do default processing when message not already processed
\r
2003 case UWM_UPDATE_COMMAND:
\r
2004 OnMenuUpdate((UINT)wParam); // Perform menu updates
\r
2007 } // switch (uMsg)
\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
2013 return FinalWindowProc(uMsg, wParam, lParam);
\r
2015 } // LRESULT CWnd::WindowProc(...)
\r
2019 // Wrappers for Win32 API functions
\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
2026 assert(::IsWindow(m_hWnd));
\r
2027 return FromHandle(::BeginPaint(m_hWnd, &ps));
\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
2034 assert(::IsWindow(m_hWnd));
\r
2035 return ::BringWindowToTop(m_hWnd);
\r
2038 inline LRESULT CWnd::CallWindowProc(WNDPROC lpPrevWndFunc, UINT Msg, WPARAM wParam, LPARAM lParam) const
\r
2040 assert(::IsWindow(m_hWnd));
\r
2041 return ::CallWindowProc(lpPrevWndFunc, m_hWnd, Msg, wParam, lParam);
\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
2047 assert(::IsWindow(m_hWnd));
\r
2048 return ::CheckDlgButton(m_hWnd, nIDButton, uCheck);
\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
2055 assert(::IsWindow(m_hWnd));
\r
2056 return ::CheckRadioButton(m_hWnd, nIDFirstButton, nIDLastButton, nIDCheckButton);
\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
2064 assert(::IsWindow(m_hWnd));
\r
2065 return FromHandle(::ChildWindowFromPoint(m_hWnd, pt));
\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
2071 assert(::IsWindow(m_hWnd));
\r
2072 return ::ClientToScreen(m_hWnd, &pt);
\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
2078 assert(::IsWindow(m_hWnd));
\r
2079 return (BOOL)::MapWindowPoints(m_hWnd, NULL, (LPPOINT)&rc, 2);
\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
2085 assert(::IsWindow(m_hWnd));
\r
2086 return ::DeferWindowPos(hWinPosInfo, m_hWnd, hWndInsertAfter, x, y, cx, cy, uFlags);
\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
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
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
2099 assert(::IsWindow(m_hWnd));
\r
2100 return ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
\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
2107 assert(::IsWindow(m_hWnd));
\r
2108 return ::DrawMenuBar(m_hWnd);
\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
2115 assert(::IsWindow(m_hWnd));
\r
2116 return ::EnableWindow(m_hWnd, bEnable);
\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
2123 assert(::IsWindow(m_hWnd));
\r
2124 return ::EndPaint(m_hWnd, &ps);
\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
2131 return FromHandle( ::GetActiveWindow() );
\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
2137 return FromHandle( ::GetCapture() );
\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
2144 assert(::IsWindow(m_hWnd));
\r
2145 return ::GetClassLongPtr(m_hWnd, nIndex);
\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
2154 assert(::IsWindow(m_hWnd));
\r
2156 ::GetClientRect(m_hWnd, &rc);
\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
2164 assert(::IsWindow(m_hWnd));
\r
2165 return CDC::AddTempHDC(::GetDC(m_hWnd), m_hWnd);
\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
2172 assert(::IsWindow(m_hWnd));
\r
2173 return CDC::AddTempHDC(::GetDCEx(m_hWnd, hrgnClip, flags), m_hWnd);
\r
2176 inline CWnd* CWnd::GetDesktopWindow() const
\r
2177 // The GetDesktopWindow function retrieves a pointer to the desktop window.
\r
2179 return FromHandle( ::GetDesktopWindow() );
\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
2185 assert(::IsWindow(m_hWnd));
\r
2186 return FromHandle( ::GetDlgItem(m_hWnd, nIDDlgItem) );
\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
2192 assert(::IsWindow(m_hWnd));
\r
2193 return ::GetDlgItemInt(m_hWnd, nIDDlgItem, lpTranslated, bSigned);
\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
2200 return FromHandle( ::GetFocus() );
\r
2203 inline CFont* CWnd::GetFont() const
\r
2204 // Retrieves the font with which the window is currently drawing its text.
\r
2206 assert(::IsWindow(m_hWnd));
\r
2207 return FromHandle((HFONT)SendMessage(WM_GETFONT, 0, 0));
\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
2213 assert(::IsWindow(m_hWnd));
\r
2214 return (HICON)SendMessage(WM_GETICON, (WPARAM)bBigIcon, 0);
\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
2221 assert(::IsWindow(m_hWnd));
\r
2223 return FromHandle(::GetNextDlgGroupItem(m_hWnd, pCtl->GetHwnd(), bPrevious));
\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
2230 assert(::IsWindow(m_hWnd));
\r
2232 return FromHandle(::GetNextDlgTabItem(m_hWnd, pCtl->GetHwnd(), bPrevious));
\r
2235 inline CWnd* CWnd::GetParent() const
\r
2236 // The GetParent function retrieves a pointer to the specified window's parent or owner.
\r
2238 assert(::IsWindow(m_hWnd));
\r
2239 return FromHandle( ::GetParent(m_hWnd) );
\r
2242 inline LONG_PTR CWnd::GetWindowLongPtr(int nIndex) const
\r
2243 // The GetWindowLongPtr function retrieves information about the window.
\r
2245 assert(::IsWindow(m_hWnd));
\r
2246 return ::GetWindowLongPtr(m_hWnd, nIndex);
\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
2254 assert(::IsWindow(m_hWnd));
\r
2255 return ::GetScrollInfo(m_hWnd, fnBar, &si);
\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
2262 assert(::IsWindow(m_hWnd));
\r
2264 ::GetUpdateRect(m_hWnd, &rc, bErase);
\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
2271 assert(::IsWindow(m_hWnd));
\r
2273 HRGN hRgn = (HRGN)pRgn->GetHandle();
\r
2274 return ::GetUpdateRgn(m_hWnd, hRgn, bErase);
\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
2283 assert(::IsWindow(m_hWnd));
\r
2284 return FromHandle( ::GetWindow(m_hWnd, uCmd) );
\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
2291 assert(::IsWindow(m_hWnd));
\r
2292 return CDC::AddTempHDC(::GetWindowDC(m_hWnd), m_hWnd);
\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
2300 assert(::IsWindow(m_hWnd));
\r
2302 ::GetWindowRect(m_hWnd, &rc);
\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
2310 assert(::IsWindow(m_hWnd));
\r
2311 return ::GetWindowTextLength(m_hWnd);
\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
2318 assert(::IsWindow(m_hWnd));
\r
2319 ::InvalidateRect(m_hWnd, NULL, bErase);
\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
2326 assert(::IsWindow(m_hWnd));
\r
2327 return ::InvalidateRect(m_hWnd, lpRect, bErase);
\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
2336 assert(::IsWindow(m_hWnd));
\r
2337 HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;
\r
2338 return ::InvalidateRgn(m_hWnd, hRgn, bErase);
\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
2345 assert(::IsWindow(m_hWnd));
\r
2346 return ::IsChild(m_hWnd, pChild->GetHwnd());
\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
2353 assert(::IsWindow(m_hWnd));
\r
2354 return ::IsDialogMessage(m_hWnd, lpMsg);
\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
2361 assert(::IsWindow(m_hWnd));
\r
2362 return ::IsDlgButtonChecked(m_hWnd, nIDButton);
\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
2369 assert(::IsWindow(m_hWnd));
\r
2370 return ::IsWindowEnabled(m_hWnd);
\r
2373 inline BOOL CWnd::IsWindowVisible() const
\r
2374 // The IsWindowVisible function retrieves the visibility state of the window.
\r
2376 assert(::IsWindow(m_hWnd));
\r
2377 return ::IsWindowVisible(m_hWnd);
\r
2380 inline BOOL CWnd::IsWindow() const
\r
2381 // The IsWindow function determines whether the window exists.
\r
2383 return ::IsWindow(m_hWnd);
\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
2393 assert (pWndTo->GetHwnd());
\r
2394 ::MapWindowPoints(m_hWnd, pWndTo->GetHwnd(), &pt, 1);
\r
2397 ::MapWindowPoints(m_hWnd, NULL, &pt, 1);
\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
2407 assert (pWndTo->GetHwnd());
\r
2408 ::MapWindowPoints(m_hWnd, pWndTo->GetHwnd(), (LPPOINT)&rc, 2);
\r
2411 ::MapWindowPoints(m_hWnd, NULL, (LPPOINT)&rc, 2);
\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
2421 assert (pWndTo->GetHwnd());
\r
2422 ::MapWindowPoints(m_hWnd, pWndTo->GetHwnd(), (LPPOINT)ptArray, nCount);
\r
2425 ::MapWindowPoints(m_hWnd, NULL, (LPPOINT)ptArray, nCount);
\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
2433 assert(::IsWindow(m_hWnd));
\r
2434 return ::MessageBox(m_hWnd, lpText, lpCaption, uType);
\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
2440 assert(::IsWindow(m_hWnd));
\r
2441 return ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint = TRUE);
\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
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
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
2456 assert(::IsWindow(m_hWnd));
\r
2457 return ::PostMessage(m_hWnd, uMsg, wParam, lParam);
\r
2460 inline BOOL CWnd::PostMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const
\r
2461 // Required by by some macros
\r
2463 assert(::IsWindow(m_hWnd));
\r
2464 return ::PostMessage(hWnd, uMsg, wParam, lParam);
\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
2470 assert(::IsWindow(m_hWnd));
\r
2471 HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;
\r
2472 return ::RedrawWindow(m_hWnd, lpRectUpdate, hRgn, flags);
\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
2479 assert(::IsWindow(m_hWnd));
\r
2481 return ::ReleaseDC(m_hWnd, pDC->GetHDC());
\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
2487 assert(::IsWindow(m_hWnd));
\r
2488 return ::ScreenToClient(m_hWnd, &Point);
\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
2494 assert(::IsWindow(m_hWnd));
\r
2495 return (BOOL)::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rc, 2);
\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
2501 assert(::IsWindow(m_hWnd));
\r
2502 return ::SendDlgItemMessage(m_hWnd, nIDDlgItem, Msg, wParam, lParam);
\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
2510 assert(::IsWindow(m_hWnd));
\r
2511 return ::SendMessage(m_hWnd, uMsg, wParam, lParam);
\r
2514 inline LRESULT CWnd::SendMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const
\r
2515 // Required by by some macros
\r
2517 assert(::IsWindow(m_hWnd));
\r
2518 return ::SendMessage(hWnd, uMsg, wParam, lParam);
\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
2527 assert(::IsWindow(m_hWnd));
\r
2528 return ::SendNotifyMessage(m_hWnd, Msg, wParam, lParam);
\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
2535 assert(::IsWindow(m_hWnd));
\r
2536 return FromHandle( ::SetActiveWindow(m_hWnd) );
\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
2545 assert(::IsWindow(m_hWnd));
\r
2546 return FromHandle( ::SetCapture(m_hWnd) );
\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
2553 assert(::IsWindow(m_hWnd));
\r
2554 return ::SetClassLongPtr(m_hWnd, nIndex, dwNewLong);
\r
2557 inline CWnd* CWnd::SetFocus() const
\r
2558 // The SetFocus function sets the keyboard focus to the window.
\r
2560 assert(::IsWindow(m_hWnd));
\r
2561 return FromHandle( ::SetFocus(m_hWnd) );
\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
2567 assert(::IsWindow(m_hWnd));
\r
2569 SendMessage(WM_SETFONT, (WPARAM)pFont->GetHandle(), (LPARAM)bRedraw);
\r
2572 inline HICON CWnd::SetIcon(HICON hIcon, BOOL bBigIcon) const
\r
2573 // Associates a new large or small icon with a window.
\r
2575 assert(::IsWindow(m_hWnd));
\r
2576 return (HICON)SendMessage(WM_SETICON, (WPARAM)bBigIcon, (LPARAM)hIcon);
\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
2583 assert(::IsWindow(m_hWnd));
\r
2584 return ::SetForegroundWindow(m_hWnd);
\r
2587 inline CWnd* CWnd::SetParent(CWnd* pWndParent) const
\r
2588 // The SetParent function changes the parent window of the child window.
\r
2590 assert(::IsWindow(m_hWnd));
\r
2593 HWND hParent = pWndParent->GetHwnd();
\r
2594 return FromHandle(::SetParent(m_hWnd, hParent));
\r
2597 return FromHandle(::SetParent(m_hWnd, 0));
\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
2604 assert(::IsWindow(m_hWnd));
\r
2605 return (BOOL)::SendMessage(m_hWnd, WM_SETREDRAW, (WPARAM)bRedraw, 0L);
\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
2611 assert(::IsWindow(m_hWnd));
\r
2612 return ::SetWindowLongPtr(m_hWnd, nIndex, dwNewLong);
\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
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
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
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
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
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
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
2652 assert(::IsWindow(m_hWnd));
\r
2653 return ::SetDlgItemInt(m_hWnd, nIDDlgItem, uValue, bSigned);
\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
2659 assert(::IsWindow(m_hWnd));
\r
2660 return ::SetDlgItemText(m_hWnd, nIDDlgItem, lpString);
\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
2666 assert(::IsWindow(m_hWnd));
\r
2667 return ::SetTimer(m_hWnd, nIDEvent, uElapse, lpTimerFunc);
\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
2673 assert(::IsWindow(m_hWnd));
\r
2674 return ::SetWindowText(m_hWnd, lpString);
\r
2677 inline HRESULT CWnd::SetWindowTheme(LPCWSTR pszSubAppName, LPCWSTR pszSubIdList) const
\r
2678 // Set the XP Theme for a window.
\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
2683 HRESULT hr = E_NOTIMPL;
\r
2685 #ifndef _WIN32_WCE
\r
2687 HMODULE hMod = ::LoadLibrary(_T("uxtheme.dll"));
\r
2690 typedef HRESULT (__stdcall *PFNSETWINDOWTHEME)(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);
\r
2691 PFNSETWINDOWTHEME pfn = (PFNSETWINDOWTHEME)GetProcAddress(hMod, "SetWindowTheme");
\r
2693 hr = (*pfn)(m_hWnd, pszSubAppName, pszSubIdList);
\r
2695 ::FreeLibrary(hMod);
\r
2703 inline BOOL CWnd::ShowWindow(int nCmdShow /*= SW_SHOWNORMAL*/) const
\r
2704 // The ShowWindow function sets the window's show state.
\r
2706 assert(::IsWindow(m_hWnd));
\r
2707 return ::ShowWindow(m_hWnd, nCmdShow);
\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
2715 assert(::IsWindow(m_hWnd));
\r
2716 return ::UpdateWindow(m_hWnd);
\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
2723 assert(::IsWindow(m_hWnd));
\r
2724 return ::ValidateRect(m_hWnd, prc);
\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
2731 assert(::IsWindow(m_hWnd));
\r
2732 HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;
\r
2733 return ::ValidateRgn(m_hWnd, hRgn);
\r
2736 inline CWnd* CWnd::WindowFromPoint(POINT pt)
\r
2737 // Retrieves the window that contains the specified point (in screen coodinates).
\r
2739 return FromHandle(::WindowFromPoint(pt));
\r
2743 // These functions aren't supported on WinCE
\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
2750 assert(::IsWindow(m_hWnd));
\r
2751 return ::CloseWindow(m_hWnd);
\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
2758 assert(::IsWindow(m_hWnd));
\r
2759 return ::DlgDirList(m_hWnd, lpPathSpec, nIDListBox, nIDStaticPath, uFileType);
\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
2766 assert(::IsWindow(m_hWnd));
\r
2767 return ::DlgDirListComboBox(m_hWnd, lpPathSpec, nIDComboBox, nIDStaticPath, uFiletype);
\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
2774 assert(::IsWindow(m_hWnd));
\r
2775 return ::DlgDirSelectEx(m_hWnd, lpString, nCount, nIDListBox);
\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
2782 assert(::IsWindow(m_hWnd));
\r
2783 return ::DlgDirSelectComboBoxEx(m_hWnd, lpString, nCount, nIDComboBox);
\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
2790 assert(::IsWindow(m_hWnd));
\r
2791 ::DragAcceptFiles(m_hWnd, fAccept);
\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
2799 assert(::IsWindow(m_hWnd));
\r
2800 return ::DrawAnimatedRects(m_hWnd, idAni, &rcFrom, &rcTo);
\r
2803 inline BOOL CWnd::DrawCaption(CDC* pDC, RECT& rc, UINT uFlags) const
\r
2804 // The DrawCaption function draws a window caption.
\r
2806 assert(::IsWindow(m_hWnd));
\r
2808 return ::DrawCaption(m_hWnd, pDC->GetHDC(), &rc, uFlags);
\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
2814 assert(::IsWindow(m_hWnd));
\r
2815 return ::EnableScrollBar(m_hWnd, uSBflags, uArrows);
\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
2821 assert(::IsWindow(m_hWnd));
\r
2822 return FromHandle( ::GetLastActivePopup(m_hWnd) );
\r
2825 inline CMenu* CWnd::GetMenu() const
\r
2826 // The GetMenu function retrieves a handle to the menu assigned to the window.
\r
2828 assert(::IsWindow(m_hWnd));
\r
2829 return FromHandle(::GetMenu(m_hWnd));
\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
2836 assert(::IsWindow(m_hWnd));
\r
2837 return ::GetScrollPos(m_hWnd, nBar);
\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
2844 assert(::IsWindow(m_hWnd));
\r
2845 return ::GetScrollRange(m_hWnd, nBar, &MinPos, &MaxPos );
\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
2852 assert(::IsWindow(m_hWnd));
\r
2853 return FromHandle(::GetSystemMenu(m_hWnd, bRevert));
\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
2860 assert(::IsWindow(m_hWnd));
\r
2861 return FromHandle( ::GetTopWindow(m_hWnd) );
\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
2868 assert(::IsWindow(m_hWnd));
\r
2869 return ::GetWindowPlacement(m_hWnd, &wndpl);
\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
2875 assert(::IsWindow(m_hWnd));
\r
2877 return ::HiliteMenuItem(m_hWnd, pMenu->GetHandle(), uItemHilite, uHilite);
\r
2880 inline BOOL CWnd::IsIconic() const
\r
2881 // The IsIconic function determines whether the window is minimized (iconic).
\r
2883 assert(::IsWindow(m_hWnd));
\r
2884 return ::IsIconic(m_hWnd);
\r
2887 inline BOOL CWnd::IsZoomed() const
\r
2888 // The IsZoomed function determines whether the window is maximized.
\r
2890 assert(::IsWindow(m_hWnd));
\r
2891 return ::IsZoomed(m_hWnd);
\r
2894 inline BOOL CWnd::KillTimer(UINT_PTR uIDEvent) const
\r
2895 // Destroys the specified timer.
\r
2897 assert(::IsWindow(m_hWnd));
\r
2898 return ::KillTimer(m_hWnd, uIDEvent);
\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
2905 assert(::IsWindow(m_hWnd));
\r
2906 return ::LockWindowUpdate(m_hWnd);
\r
2909 inline BOOL CWnd::OpenIcon() const
\r
2910 // The OpenIcon function restores a minimized (iconic) window to its previous size and position.
\r
2912 assert(::IsWindow(m_hWnd));
\r
2913 return ::OpenIcon(m_hWnd);
\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
2919 assert(::IsWindow(m_hWnd));
\r
2921 SendMessage(m_hWnd, WM_PRINT, (WPARAM)pDC, (LPARAM)dwFlags);
\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
2927 assert(::IsWindow(m_hWnd));
\r
2928 return ::ScrollWindow(m_hWnd, XAmount, YAmount, lprcScroll, lprcClip);
\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
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
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
2943 assert(::IsWindow(m_hWnd));
\r
2944 return ::SetMenu(m_hWnd, pMenu? pMenu->GetHandle() : NULL);
\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
2952 assert(::IsWindow(m_hWnd));
\r
2953 return ::SetScrollInfo(m_hWnd, fnBar, &si, fRedraw);
\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
2960 assert(::IsWindow(m_hWnd));
\r
2961 return ::SetScrollPos(m_hWnd, nBar, nPos, bRedraw);
\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
2967 assert(::IsWindow(m_hWnd));
\r
2968 return ::SetScrollRange(m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);
\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
2975 assert(::IsWindow(m_hWnd));
\r
2976 return ::SetWindowPlacement(m_hWnd, &wndpl);
\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
2982 assert(::IsWindow(m_hWnd));
\r
2983 return ::ShowOwnedPopups(m_hWnd, fShow);
\r
2986 inline BOOL CWnd::ShowScrollBar(int nBar, BOOL bShow) const
\r
2987 // The ShowScrollBar function shows or hides the specified scroll bar.
\r
2989 assert(::IsWindow(m_hWnd));
\r
2990 return ::ShowScrollBar(m_hWnd, nBar, bShow);
\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
2996 assert(::IsWindow(m_hWnd));
\r
2997 return ::ShowWindowAsync(m_hWnd, nCmdShow);
\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
3004 assert(::IsWindow(m_hWnd));
\r
3005 return ::LockWindowUpdate(0);
\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
3012 return FromHandle( ::WindowFromDC(pDC->GetHDC()) );
\r
3018 }; // namespace Win32xx
\r
3021 #endif // _WIN32XX_WINCORE_H_
\r