--- /dev/null
+// Win32++ Version 7.3\r
+// Released: 30th November 2011\r
+//\r
+// David Nash\r
+// url: https://sourceforge.net/projects/win32-framework\r
+//\r
+//\r
+// Copyright (c) 2005-2011 David Nash\r
+//\r
+// Permission is hereby granted, free of charge, to\r
+// any person obtaining a copy of this software and\r
+// associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify,\r
+// merge, publish, distribute, sublicense, and/or sell\r
+// copies of the Software, and to permit persons to whom\r
+// the Software is furnished to do so, subject to the\r
+// following conditions:\r
+//\r
+// The above copyright notice and this permission notice\r
+// shall be included in all copies or substantial portions\r
+// of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF\r
+// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\r
+// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\r
+// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\r
+// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR\r
+// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE\r
+// OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+////////////////////////////////////////////////////////\r
+\r
+\r
+///////////////////////////////////////////////////////\r
+// wincore.h\r
+// Declaration of the following classes:\r
+// CWinApp, CWnd, CWinException, CCriticalSection,\r
+// CPoint, CRect, and CSize\r
+//\r
+// This file contains the declarations for the core set of classes required to\r
+// create simple windows using Win32++.\r
+//\r
+// 1) CCriticalSection: This class is used internally to manage thread access\r
+// to shared resources. You can also use this class to lock and\r
+// release your own critical sections.\r
+//\r
+// 2) CWinException: This class is used internally by Win32++ to handle\r
+// exceptions. You can also use it to throw and catch exceptions.\r
+//\r
+// 3) WinApp: This class is used start Win32++ and run the message loop. You\r
+// should inherit from this class to start Win32++ in your own\r
+// application.\r
+//\r
+// 4) CWnd: This class is used to represent a window. It provides a means\r
+// of creating the window, and handling its messages. Inherit\r
+// from this class to define and control windows.\r
+//\r
+//\r
+// Note: This header file (or another Win32++ header file which includes it)\r
+// should be included before all other header files. It sets some\r
+// important macros which need to be set before including Windows.h\r
+// Including this file first also allows it to disable some pointless\r
+// warning messages (see below).\r
+\r
+\r
+\r
+#ifndef _WIN32XX_WINCORE_H_\r
+#define _WIN32XX_WINCORE_H_\r
+\r
+\r
+// Remove pointless warning messages\r
+#ifdef _MSC_VER\r
+ #pragma warning (disable : 4996) // function or variable may be unsafe (deprecated)\r
+ #ifndef _CRT_SECURE_NO_WARNINGS\r
+ #define _CRT_SECURE_NO_WARNINGS // eliminate deprecation warnings for VS2005/VS2010\r
+ #endif\r
+ #if _MSC_VER < 1500\r
+ #pragma warning (disable : 4511) // copy operator could not be generated\r
+ #pragma warning (disable : 4512) // assignment operator could not be generated\r
+ #pragma warning (disable : 4702) // unreachable code (bugs in Microsoft's STL)\r
+ #pragma warning (disable : 4786) // identifier was truncated\r
+ #endif\r
+#endif\r
+\r
+#ifdef __BORLANDC__\r
+ #pragma option -w-8019 // code has no effect\r
+ #pragma option -w-8026 // functions with exception specifiations are not expanded inline\r
+ #pragma option -w-8027 // function not expanded inline\r
+ #pragma option -w-8030 // Temporary used for 'rhs' \r
+ #define STRICT 1\r
+#endif\r
+\r
+#ifdef __GNUC__\r
+ #pragma GCC diagnostic ignored "-Wmissing-braces"\r
+ #pragma GCC diagnostic ignored "-Wunused-value"\r
+#endif\r
+\r
+#ifdef _WIN32_WCE\r
+ #include "wcestddef.h"\r
+#endif\r
+\r
+#define _WINSOCKAPI_ // Prevent winsock.h #include's.\r
+\r
+#include <assert.h>\r
+#include <vector>\r
+#include <algorithm>\r
+#include <string>\r
+#include <map>\r
+#include <windows.h>\r
+#include <commctrl.h>\r
+#include <stdio.h>\r
+#include <tchar.h>\r
+#include <shlwapi.h>\r
+#include "shared_ptr.h"\r
+//#include "winutils.h" // included later in this file\r
+//#include "cstring.h" // included later in this file\r
+//#include "gdi.h" // included later in this file\r
+//#include "menu.h" // included later in this file\r
+\r
+// For compilers lacking Win64 support\r
+#ifndef GetWindowLongPtr\r
+ #define GetWindowLongPtr GetWindowLong\r
+ #define SetWindowLongPtr SetWindowLong\r
+ #define GWLP_WNDPROC GWL_WNDPROC\r
+ #define GWLP_HINSTANCE GWL_HINSTANCE\r
+ #define GWLP_ID GWL_ID\r
+ #define GWLP_USERDATA GWL_USERDATA\r
+ #define DWLP_DLGPROC DWL_DLGPROC\r
+ #define DWLP_MSGRESULT DWL_MSGRESULT\r
+ #define DWLP_USER DWL_USER\r
+ #define DWORD_PTR DWORD\r
+ #define LONG_PTR LONG\r
+ #define ULONG_PTR LONG\r
+#endif\r
+#ifndef GetClassLongPtr\r
+ #define GetClassLongPtr GetClassLong\r
+ #define SetClassLongPtr SetClassLong\r
+ #define GCLP_HBRBACKGROUND GCL_HBRBACKGROUND\r
+ #define GCLP_HCURSOR GCL_HCURSOR\r
+ #define GCLP_HICON GCL_HICON\r
+ #define GCLP_HICONSM GCL_HICONSM\r
+ #define GCLP_HMODULE GCL_HMODULE\r
+ #define GCLP_MENUNAME GCL_MENUNAME\r
+ #define GCLP_WNDPROC GCL_WNDPROC\r
+#endif\r
+\r
+\r
+// Messages defined by Win32++\r
+#define UWM_POPUPMENU (WM_APP + 1) // Message - creates the menubar popup menu\r
+#define UWM_DOCK_START (WM_APP + 2) // Notification - about to start undocking\r
+#define UWM_DOCK_MOVE (WM_APP + 3) // Notification - undocked docker is being moved\r
+#define UWM_DOCK_END (WM_APP + 4) // Notification - docker has been docked\r
+#define UWM_BAR_START (WM_APP + 5) // Notification - docker bar selected for move\r
+#define UWM_BAR_MOVE (WM_APP + 6) // Notification - docker bar moved\r
+#define UWM_BAR_END (WM_APP + 7) // Notification - end of docker bar move\r
+#define UWM_UNDOCKED (WM_APP + 8) // Notification - sent by docker when undocked\r
+#define UWM_FRAMELOSTFOCUS (WM_APP + 9) // Notification - sent by frame to view window when focus lost\r
+#define UWM_FRAMEGOTFOCUS (WM_APP + 10) // Notification - sent by frame to view window when focus acquired\r
+#define UWM_DOCK_DESTROYED (WM_APP + 11) // Message - posted when docker is destroyed\r
+#define UWM_TAB_CHANGED (WM_APP + 12) // Notification - tab layout changed\r
+#define UWM_TOOLBAR_RESIZE (WM_APP + 13) // Message - sent by toolbar to parent. Used by the rebar\r
+#define UWM_UPDATE_COMMAND (WM_APP + 14) // Message - sent before a menu is displayed. Used by OnUpdate\r
+#define UWM_DOCK_ACTIVATED (WM_APP + 15) // Message - sent to dock ancestor when a docker is activated or deactivated.\r
+#define UWM_GETMENUTHEME (WM_APP + 16) // Message - returns a pointer to MenuTheme\r
+#define UWM_GETREBARTHEME (WM_APP + 17) // Message - returns a pointer to CToolBar\r
+#define UWM_GETTOOLBARTHEME (WM_APP + 18) // Message - returns a pointer to ToolBarTheme\r
+#define UWM_CLEANUPTEMPS (WM_APP + 19) // Message - posted to cleanup temporary CDCs\r
+\r
+\r
+// Automatically include the Win32xx namespace\r
+// define NO_USING_NAMESPACE to skip this step\r
+namespace Win32xx {}\r
+#ifndef NO_USING_NAMESPACE\r
+ using namespace Win32xx;\r
+#endif\r
+\r
+// Required for WinCE\r
+#ifndef TLS_OUT_OF_INDEXES\r
+ #define TLS_OUT_OF_INDEXES ((DWORD_PTR) -1)\r
+#endif\r
+#ifndef WM_PARENTNOTIFY\r
+ #define WM_PARENTNOTIFY 0x0210\r
+#endif\r
+\r
+\r
+namespace Win32xx\r
+{\r
+\r
+ ////////////////////////////////////////////////\r
+ // Forward declarations.\r
+ // These classes are defined later or elsewhere\r
+ class CDC;\r
+ class CGDIObject;\r
+ class CMenu;\r
+ class CWinApp;\r
+ class CWnd;\r
+ class CBitmap;\r
+ class CBrush;\r
+ class CFont;\r
+ class CPalette;\r
+ class CPen;\r
+ class CRgn;\r
+\r
+ // tString is a TCHAR std::string\r
+ typedef std::basic_string<TCHAR> tString;\r
+\r
+ // tStringStream is a TCHAR std::stringstream\r
+ typedef std::basic_stringstream<TCHAR> tStringStream;\r
+\r
+ // Some useful smart pointers\r
+ typedef Shared_Ptr<CDC> DCPtr;\r
+ typedef Shared_Ptr<CGDIObject> GDIPtr;\r
+ typedef Shared_Ptr<CMenu> MenuPtr;\r
+ typedef Shared_Ptr<CWnd> WndPtr;\r
+ typedef Shared_Ptr<CBitmap> BitmapPtr;\r
+ typedef Shared_Ptr<CBrush> BrushPtr;\r
+ typedef Shared_Ptr<CFont> FontPtr;\r
+ typedef Shared_Ptr<CPalette> PalettePtr;\r
+ typedef Shared_Ptr<CPen> PenPtr;\r
+ typedef Shared_Ptr<CRgn> RgnPtr;\r
+\r
+ enum Constants // Defines the maximum size for TCHAR strings\r
+ {\r
+ MAX_MENU_STRING = 80,\r
+ MAX_STRING_SIZE = 255,\r
+ };\r
+\r
+ struct CompareHDC // The comparison function object used by CWinApp::m_mapHDC\r
+ {\r
+ bool operator()(HDC const a, const HDC b) const\r
+ {return ((DWORD_PTR)a < (DWORD_PTR)b);}\r
+ };\r
+\r
+ struct CompareGDI // The comparison function object used by CWinApp::m_mapGDI\r
+ {\r
+ bool operator()(HGDIOBJ const a, const HGDIOBJ b) const\r
+ {return ((DWORD_PTR)a < (DWORD_PTR)b);}\r
+ };\r
+\r
+ struct CompareHMENU // The comparison function object used by CWinApp::m_mapHMENU\r
+ {\r
+ bool operator()(HMENU const a, const HMENU b) const\r
+ {return ((DWORD_PTR)a < (DWORD_PTR)b);}\r
+ };\r
+\r
+ struct CompareHWND // The comparison function object used by CWinApp::m_mapHWND\r
+ {\r
+ bool operator()(HWND const a, const HWND b) const\r
+ {return ((DWORD_PTR)a < (DWORD_PTR)b);}\r
+ };\r
+\r
+ struct TLSData // Used for Thread Local Storage (TLS)\r
+ {\r
+ CWnd* pCWnd; // pointer to CWnd object for Window creation\r
+ CWnd* pMenuBar; // pointer to CMenuBar object used for the WH_MSGFILTER hook\r
+ HHOOK hHook; // WH_MSGFILTER hook for CMenuBar and Modeless Dialogs\r
+\r
+ std::vector<DCPtr> vTmpDCs; // A vector of temporary CDC pointers\r
+ std::vector<GDIPtr> vTmpGDIs; // A vector of temporary CGDIObject pointers\r
+ std::vector<WndPtr> vTmpWnds; // A vector of temporary CWnd pointers\r
+ TLSData() : pCWnd(0), pMenuBar(0), hHook(0) {}\r
+\r
+#ifndef _WIN32_WCE\r
+ std::vector<MenuPtr> vTmpMenus; // A vector of temporary CMenu pointers\r
+#endif\r
+ };\r
+\r
+\r
+ /////////////////////////////////////////\r
+ // Declarations for the CCriticalSection class\r
+ // This class is used for thread synchronisation\r
+ class CCriticalSection\r
+ {\r
+ public:\r
+ CCriticalSection() { ::InitializeCriticalSection(&m_cs); }\r
+ ~CCriticalSection() { ::DeleteCriticalSection(&m_cs); }\r
+\r
+ void Lock() { ::EnterCriticalSection(&m_cs); }\r
+ void Release() { ::LeaveCriticalSection(&m_cs); }\r
+\r
+ private:\r
+ CCriticalSection ( const CCriticalSection& );\r
+ CCriticalSection& operator = ( const CCriticalSection& );\r
+\r
+ CRITICAL_SECTION m_cs;\r
+ };\r
+\r
+\r
+ ////////////////////////////////////////\r
+ // Declaration of the CWinException class\r
+ //\r
+ // Note: Each function guarantees not to throw an exception\r
+\r
+ class CWinException : public std::exception\r
+ {\r
+ public:\r
+ CWinException(LPCTSTR pszText) throw ();\r
+ ~CWinException() throw() {}\r
+ DWORD GetError() const throw ();\r
+ LPCTSTR GetErrorString() const throw ();\r
+ const char * what () const throw ();\r
+\r
+ private:\r
+ DWORD m_Error;\r
+ LPCTSTR m_pszText;\r
+ TCHAR m_szErrorString[MAX_STRING_SIZE];\r
+ };\r
+\r
+\r
+ ///////////////////////////////////\r
+ // Declaration of the CWinApp class\r
+ //\r
+ class CWinApp\r
+ {\r
+ // Provide these access to CWinApp's private members:\r
+ friend class CDC;\r
+ friend class CDialog;\r
+ friend class CGDIObject;\r
+ friend class CMenu;\r
+ friend class CMenuBar;\r
+ friend class CPropertyPage;\r
+ friend class CPropertySheet;\r
+ friend class CTaskDialog;\r
+ friend class CWnd;\r
+ friend CWinApp* GetApp();\r
+ friend CGDIObject* FromHandle(HGDIOBJ hObject);\r
+ friend CBitmap* FromHandle(HBITMAP hBitmap);\r
+ friend CBrush* FromHandle(HBRUSH hBrush);\r
+ friend CFont* FromHandle(HFONT hFont);\r
+ friend CPalette* FromHandle(HPALETTE hPalette);\r
+ friend CPen* FromHandle(HPEN hPen);\r
+ friend CRgn* FromHandle(HRGN hRgn);\r
+ friend CDC* FromHandle(HDC hDC);\r
+ friend CWnd* FromHandle(HWND hWnd);\r
+#ifndef _WIN32_WCE\r
+ friend CMenu* FromHandle(HMENU hMenu);\r
+#endif\r
+\r
+ typedef Shared_Ptr<TLSData> TLSDataPtr;\r
+\r
+ public:\r
+ CWinApp();\r
+ virtual ~CWinApp();\r
+\r
+ HACCEL GetAccelerators() const { return m_hAccel; }\r
+ HINSTANCE GetInstanceHandle() const { return m_hInstance; }\r
+ HINSTANCE GetResourceHandle() const { return (m_hResource ? m_hResource : m_hInstance); }\r
+ void SetAccelerators(HACCEL hAccel, CWnd* pWndAccel);\r
+ void SetResourceHandle(HINSTANCE hResource);\r
+\r
+ // These are the functions you might wish to override\r
+ virtual BOOL InitInstance();\r
+ virtual int MessageLoop();\r
+ virtual BOOL OnIdle(LONG lCount);\r
+ virtual BOOL PreTranslateMessage(MSG Msg);\r
+ virtual int Run();\r
+\r
+ private:\r
+ CWinApp(const CWinApp&); // Disable copy construction\r
+ CWinApp& operator = (const CWinApp&); // Disable assignment operator\r
+ CDC* GetCDCFromMap(HDC hDC);\r
+ CGDIObject* GetCGDIObjectFromMap(HGDIOBJ hObject);\r
+ CMenu* GetCMenuFromMap(HMENU hMenu);\r
+ CWnd* GetCWndFromMap(HWND hWnd);\r
+\r
+ void AddTmpDC(CDC* pDC);\r
+ void AddTmpGDI(CGDIObject* pObject);\r
+ CMenu* AddTmpMenu(HMENU hMenu);\r
+ CWnd* AddTmpWnd(HWND hWnd);\r
+ void CleanupTemps();\r
+ DWORD GetTlsIndex() const {return m_dwTlsIndex;}\r
+ void SetCallback();\r
+ TLSData* SetTlsIndex();\r
+ static CWinApp* SetnGetThis(CWinApp* pThis = 0);\r
+\r
+ std::map<HDC, CDC*, CompareHDC> m_mapHDC; // maps device context handles to CDC objects\r
+ std::map<HGDIOBJ, CGDIObject*, CompareGDI> m_mapGDI; // maps GDI handles to CGDIObjects.\r
+ std::map<HMENU, CMenu*, CompareHMENU> m_mapHMENU; // maps menu handles to CMenu objects\r
+ std::map<HWND, CWnd*, CompareHWND> m_mapHWND; // maps window handles to CWnd objects\r
+ std::vector<TLSDataPtr> m_vTLSData; // vector of TLSData smart pointers, one for each thread\r
+ CCriticalSection m_csMapLock; // thread synchronisation for m_mapHWND\r
+ CCriticalSection m_csTLSLock; // thread synchronisation for m_vTLSData\r
+ CCriticalSection m_csAppStart; // thread synchronisation for application startup\r
+ HINSTANCE m_hInstance; // handle to the applications instance\r
+ HINSTANCE m_hResource; // handle to the applications resources\r
+ DWORD m_dwTlsIndex; // Thread Local Storage index\r
+ WNDPROC m_Callback; // callback address of CWnd::StaticWndowProc\r
+ HACCEL m_hAccel; // handle to the accelerator table\r
+ CWnd* m_pWndAccel; // handle to the window for accelerator keys\r
+\r
+ };\r
+\r
+}\r
+\r
+#include "winutils.h"\r
+#include "cstring.h"\r
+\r
+\r
+namespace Win32xx\r
+{\r
+ ////////////////////////////////\r
+ // Declaration of the CWnd class\r
+ //\r
+ class CWnd\r
+ {\r
+ friend class CMDIChild;\r
+ friend class CDialog;\r
+ friend class CPropertyPage;\r
+ friend class CTaskDialog;\r
+ friend class CWinApp;\r
+\r
+ public:\r
+ CWnd(); // Constructor\r
+ CWnd(HWND hWnd) // Constructor\r
+ {\r
+ if (hWnd == HWND_TOP || hWnd == HWND_TOPMOST || hWnd == HWND_BOTTOM || hWnd == HWND_NOTOPMOST)\r
+ {\r
+ m_hWnd = hWnd;\r
+ }\r
+ else\r
+ Attach(hWnd);\r
+ }\r
+ virtual ~CWnd(); // Destructor\r
+\r
+ // These virtual functions can be overridden\r
+ virtual BOOL Attach(HWND hWnd);\r
+ virtual BOOL AttachDlgItem(UINT nID, CWnd* pParent);\r
+ virtual void CenterWindow() const;\r
+ virtual HWND Create(CWnd* pParent = NULL);\r
+ 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
+ virtual HWND CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rc, CWnd* pParent, CMenu* pMenu, LPVOID lpParam = NULL);\r
+ virtual void Destroy();\r
+ virtual HWND Detach();\r
+ virtual HICON SetIconLarge(int nIcon);\r
+ virtual HICON SetIconSmall(int nIcon);\r
+\r
+ // Attributes\r
+ HWND GetHwnd() const { return m_hWnd; }\r
+ WNDPROC GetPrevWindowProc() const { return m_PrevWindowProc; }\r
+\r
+ // Wrappers for Win32 API functions\r
+ // These functions aren't virtual, and shouldn't be overridden\r
+ CDC* BeginPaint(PAINTSTRUCT& ps) const;\r
+ BOOL BringWindowToTop() const;\r
+ LRESULT CallWindowProc(WNDPROC lpPrevWndFunc, UINT Msg, WPARAM wParam, LPARAM lParam) const;\r
+ BOOL CheckDlgButton(int nIDButton, UINT uCheck) const;\r
+ BOOL CheckRadioButton(int nIDFirstButton, int nIDLastButton, int nIDCheckButton) const;\r
+ CWnd* ChildWindowFromPoint(POINT pt) const;\r
+ BOOL ClientToScreen(POINT& pt) const;\r
+ BOOL ClientToScreen(RECT& rc) const;\r
+ LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) const;\r
+ HDWP DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const;\r
+ HDWP DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, const RECT& rc, UINT uFlags) const;\r
+ BOOL DrawMenuBar() const;\r
+ BOOL EnableWindow(BOOL bEnable = TRUE) const;\r
+ BOOL EndPaint(PAINTSTRUCT& ps) const;\r
+ CWnd* GetActiveWindow() const;\r
+ CWnd* GetAncestor(UINT gaFlag = 3 /*= GA_ROOTOWNER*/) const;\r
+ CWnd* GetCapture() const;\r
+ ULONG_PTR GetClassLongPtr(int nIndex) const;\r
+ CString GetClassName() const;\r
+ CRect GetClientRect() const;\r
+ CDC* GetDC() const;\r
+ CDC* GetDCEx(HRGN hrgnClip, DWORD flags) const;\r
+ CWnd* GetDesktopWindow() const;\r
+ CWnd* GetDlgItem(int nIDDlgItem) const;\r
+ UINT GetDlgItemInt(int nIDDlgItem, BOOL* lpTranslated, BOOL bSigned) const;\r
+ CString GetDlgItemText(int nIDDlgItem) const;\r
+ CWnd* GetFocus() const;\r
+ CFont* GetFont() const;\r
+ HICON GetIcon(BOOL bBigIcon) const;\r
+ CWnd* GetNextDlgGroupItem(CWnd* pCtl, BOOL bPrevious) const;\r
+ CWnd* GetNextDlgTabItem(CWnd* pCtl, BOOL bPrevious) const;\r
+ CWnd* GetParent() const;\r
+ BOOL GetScrollInfo(int fnBar, SCROLLINFO& si) const;\r
+ CRect GetUpdateRect(BOOL bErase) const;\r
+ int GetUpdateRgn(CRgn* pRgn, BOOL bErase) const;\r
+ CWnd* GetWindow(UINT uCmd) const;\r
+ CDC* GetWindowDC() const;\r
+ LONG_PTR GetWindowLongPtr(int nIndex) const;\r
+ CRect GetWindowRect() const;\r
+ CString GetWindowText() const;\r
+ int GetWindowTextLength() const;\r
+ void Invalidate(BOOL bErase = TRUE) const;\r
+ BOOL InvalidateRect(LPCRECT lpRect, BOOL bErase = TRUE) const;\r
+ BOOL InvalidateRgn(CRgn* pRgn, BOOL bErase = TRUE) const;\r
+ BOOL IsChild(CWnd* pChild) const;\r
+ BOOL IsDialogMessage(LPMSG lpMsg) const;\r
+ UINT IsDlgButtonChecked(int nIDButton) const;\r
+ BOOL IsWindow() const;\r
+ BOOL IsWindowEnabled() const;\r
+ BOOL IsWindowVisible() const;\r
+ BOOL KillTimer(UINT_PTR uIDEvent) const;\r
+ int MessageBox(LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) const;\r
+ void MapWindowPoints(CWnd* pWndTo, POINT& pt) const;\r
+ void MapWindowPoints(CWnd* pWndTo, RECT& rc) const;\r
+ void MapWindowPoints(CWnd* pWndTo, LPPOINT ptArray, UINT nCount) const;\r
+ BOOL MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE) const;\r
+ BOOL MoveWindow(const RECT& rc, BOOL bRepaint = TRUE) const;\r
+ BOOL PostMessage(UINT uMsg, WPARAM wParam = 0L, LPARAM lParam = 0L) const;\r
+ BOOL PostMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const;\r
+ BOOL RedrawWindow(LPCRECT lpRectUpdate = NULL, CRgn* pRgn = NULL, UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN) const;\r
+ int ReleaseDC(CDC* pDC) const;\r
+ BOOL ScreenToClient(POINT& Point) const;\r
+ BOOL ScreenToClient(RECT& rc) const;\r
+ LRESULT SendDlgItemMessage(int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam) const;\r
+ LRESULT SendMessage(UINT uMsg, WPARAM wParam = 0L, LPARAM lParam = 0L) const;\r
+ LRESULT SendMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const;\r
+ BOOL SendNotifyMessage(UINT Msg, WPARAM wParam, LPARAM lParam) const;\r
+ CWnd* SetActiveWindow() const;\r
+ CWnd* SetCapture() const;\r
+ ULONG_PTR SetClassLongPtr(int nIndex, LONG_PTR dwNewLong) const;\r
+ BOOL SetDlgItemInt(int nIDDlgItem, UINT uValue, BOOL bSigned) const;\r
+ BOOL SetDlgItemText(int nIDDlgItem, LPCTSTR lpString) const;\r
+ CWnd* SetFocus() const;\r
+ void SetFont(CFont* pFont, BOOL bRedraw = TRUE) const;\r
+ BOOL SetForegroundWindow() const;\r
+ HICON SetIcon(HICON hIcon, BOOL bBigIcon) const;\r
+ CWnd* SetParent(CWnd* pWndParent) const;\r
+ BOOL SetRedraw(BOOL bRedraw = TRUE) const;\r
+ int SetScrollInfo(int fnBar, const SCROLLINFO& si, BOOL fRedraw) const;\r
+ UINT_PTR SetTimer(UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc) const;\r
+ LONG_PTR SetWindowLongPtr(int nIndex, LONG_PTR dwNewLong) const;\r
+ BOOL SetWindowPos(const CWnd* pInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const;\r
+ BOOL SetWindowPos(const CWnd* pInsertAfter, const RECT& rc, UINT uFlags) const;\r
+ int SetWindowRgn(CRgn* pRgn, BOOL bRedraw = TRUE) const;\r
+ BOOL SetWindowText(LPCTSTR lpString) const;\r
+ HRESULT SetWindowTheme(LPCWSTR pszSubAppName, LPCWSTR pszSubIdList) const;\r
+ BOOL ShowWindow(int nCmdShow = SW_SHOWNORMAL) const;\r
+ BOOL UpdateWindow() const;\r
+ BOOL ValidateRect(LPCRECT prc) const;\r
+ BOOL ValidateRgn(CRgn* pRgn) const;\r
+ static CWnd* WindowFromPoint(POINT pt);\r
+\r
+ #ifndef _WIN32_WCE\r
+ BOOL CloseWindow() const;\r
+ int DlgDirList(LPTSTR lpPathSpec, int nIDListBox, int nIDStaticPath, UINT uFileType) const;\r
+ int DlgDirListComboBox(LPTSTR lpPathSpec, int nIDComboBox, int nIDStaticPath, UINT uFiletype) const;\r
+ BOOL DlgDirSelectEx(LPTSTR lpString, int nCount, int nIDListBox) const;\r
+ BOOL DlgDirSelectComboBoxEx(LPTSTR lpString, int nCount, int nIDComboBox) const;\r
+ BOOL DrawAnimatedRects(int idAni, RECT& rcFrom, RECT& rcTo) const;\r
+ BOOL DrawCaption(CDC* pDC, RECT& rc, UINT uFlags) const;\r
+ BOOL EnableScrollBar(UINT uSBflags, UINT uArrows) const;\r
+ CWnd* GetLastActivePopup() const;\r
+ CMenu* GetMenu() const;\r
+ int GetScrollPos(int nBar) const;\r
+ BOOL GetScrollRange(int nBar, int& MinPos, int& MaxPos) const;\r
+ CMenu* GetSystemMenu(BOOL bRevert) const;\r
+ CWnd* GetTopWindow() const;\r
+ BOOL GetWindowPlacement(WINDOWPLACEMENT& pWndpl) const;\r
+ BOOL HiliteMenuItem(CMenu* pMenu, UINT uItemHilite, UINT uHilite) const;\r
+ BOOL IsIconic() const;\r
+ BOOL IsZoomed() const;\r
+ BOOL LockWindowUpdate() const;\r
+ BOOL OpenIcon() const;\r
+ void Print(CDC* pDC, DWORD dwFlags) const;\r
+ BOOL SetMenu(CMenu* pMenu) const;\r
+ BOOL ScrollWindow(int XAmount, int YAmount, LPCRECT lprcScroll, LPCRECT lprcClip) const;\r
+ int ScrollWindowEx(int dx, int dy, LPCRECT lprcScroll, LPCRECT lprcClip, CRgn* prgnUpdate, LPRECT lprcUpdate, UINT flags) const;\r
+ int SetScrollPos(int nBar, int nPos, BOOL bRedraw) const;\r
+ BOOL SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw) const;\r
+ BOOL SetWindowPlacement(const WINDOWPLACEMENT& wndpl) const;\r
+ BOOL ShowOwnedPopups(BOOL fShow) const;\r
+ BOOL ShowScrollBar(int nBar, BOOL bShow) const;\r
+ BOOL ShowWindowAsync(int nCmdShow) const;\r
+ BOOL UnLockWindowUpdate() const;\r
+ CWnd* WindowFromDC(CDC* pDC) const;\r
+\r
+ #ifndef WIN32_LEAN_AND_MEAN\r
+ void DragAcceptFiles(BOOL fAccept) const;\r
+ #endif\r
+ #endif\r
+\r
+ static LRESULT CALLBACK StaticWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
+ operator HWND() const { return m_hWnd; }\r
+\r
+ protected:\r
+ // Override these functions as required\r
+ virtual LRESULT FinalWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
+ virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);\r
+ virtual void OnCreate();\r
+ virtual void OnDraw(CDC* pDC);\r
+ virtual BOOL OnEraseBkgnd(CDC* pDC);\r
+ virtual void OnInitialUpdate();\r
+ virtual void OnMenuUpdate(UINT nID);\r
+ virtual LRESULT OnMessageReflect(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
+ virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);\r
+ virtual LRESULT OnNotifyReflect(WPARAM wParam, LPARAM lParam);\r
+ virtual void PreCreate(CREATESTRUCT& cs);\r
+ virtual void PreRegisterClass(WNDCLASS& wc);\r
+ virtual BOOL PreTranslateMessage(MSG* pMsg);\r
+ virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
+ virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
+\r
+ HWND m_hWnd; // handle to this object's window\r
+\r
+ private:\r
+ CWnd(const CWnd&); // Disable copy construction\r
+ CWnd& operator = (const CWnd&); // Disable assignment operator\r
+ void AddToMap();\r
+ void Cleanup();\r
+ LRESULT MessageReflect(HWND hwndParent, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
+ BOOL RegisterClass(WNDCLASS& wc);\r
+ BOOL RemoveFromMap();\r
+ void Subclass(HWND hWnd);\r
+\r
+ Shared_Ptr<WNDCLASS> m_pwc; // defines initialisation parameters for PreRegisterClass\r
+ Shared_Ptr<CREATESTRUCT> m_pcs; // defines initialisation parameters for PreCreate and Create\r
+ WNDPROC m_PrevWindowProc; // pre-subclassed Window Procedure\r
+ BOOL m_IsTmpWnd; // True if this CWnd is a TmpWnd\r
+\r
+ }; // class CWnd\r
+\r
+ // Special CWnd objects used by SetWindowPos\r
+ static const CWnd wndTop(HWND_TOP);\r
+ static const CWnd wndTopMost(HWND_TOPMOST);\r
+ static const CWnd wndBottom(HWND_BOTTOM);\r
+ static const CWnd wndNoTopMost(HWND_NOTOPMOST);\r
+}\r
+\r
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+\r
+#include "gdi.h"\r
+#include "menu.h"\r
+\r
+namespace Win32xx\r
+{\r
+\r
+ //////////////////////////////////////////\r
+ // Definitions for the CWinException class\r
+ //\r
+ inline CWinException::CWinException(LPCTSTR pszText) throw () : m_Error(::GetLastError()), m_pszText(pszText)\r
+ {\r
+ memset(m_szErrorString, 0, MAX_STRING_SIZE * sizeof(TCHAR));\r
+\r
+ if (m_Error != 0)\r
+ {\r
+ DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;\r
+ ::FormatMessage(dwFlags, NULL, m_Error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), m_szErrorString, MAX_STRING_SIZE-1, NULL);\r
+ }\r
+ }\r
+\r
+ inline DWORD CWinException::GetError() const throw ()\r
+ {\r
+ return m_Error;\r
+ }\r
+\r
+ inline LPCTSTR CWinException::GetErrorString() const throw ()\r
+ {\r
+ return m_szErrorString;\r
+ }\r
+\r
+ inline const char * CWinException::what() const throw ()\r
+ {\r
+ // Sends the last error string to the debugger (typically displayed in the IDE's output window).\r
+ ::OutputDebugString(m_szErrorString);\r
+ return "CWinException thrown";\r
+ }\r
+\r
+\r
+ ////////////////////////////////////\r
+ // Definitions for the CWinApp class\r
+ //\r
+\r
+ // To begin Win32++, inherit your application class from this one.\r
+ // You must run only one instance of the class inherited from this.\r
+ inline CWinApp::CWinApp() : m_Callback(NULL), m_hAccel(0), m_pWndAccel(0)\r
+ {\r
+ try\r
+ {\r
+ m_csAppStart.Lock();\r
+ assert( 0 == SetnGetThis() ); // Test if this is the first instance of CWinApp\r
+\r
+ m_dwTlsIndex = ::TlsAlloc();\r
+ if (m_dwTlsIndex == TLS_OUT_OF_INDEXES)\r
+ {\r
+ // We only get here in the unlikely event that all TLS indexes are already allocated by this app\r
+ // At least 64 TLS indexes per process are allowed. Win32++ requires only one TLS index.\r
+ m_csAppStart.Release();\r
+ throw CWinException(_T("CWinApp::CWinApp Failed to allocate TLS Index"));\r
+ }\r
+\r
+ SetnGetThis(this);\r
+ m_csAppStart.Release();\r
+\r
+ // Set the instance handle\r
+ #ifdef _WIN32_WCE\r
+ m_hInstance = (HINSTANCE)GetModuleHandle(0);\r
+ #else\r
+ MEMORY_BASIC_INFORMATION mbi = {0};\r
+ VirtualQuery( (LPCVOID)SetnGetThis, &mbi, sizeof(mbi) );\r
+ assert(mbi.AllocationBase);\r
+ m_hInstance = (HINSTANCE)mbi.AllocationBase;\r
+ #endif\r
+\r
+ m_hResource = m_hInstance;\r
+ SetCallback();\r
+\r
+ // Assign the special CWnds used by SetWindowPos\r
+ m_csMapLock.Lock();\r
+ m_mapHWND.insert(std::make_pair(HWND_TOP, (CWnd*)&wndTop));\r
+ m_mapHWND.insert(std::make_pair(HWND_TOPMOST, (CWnd*)&wndTopMost));\r
+ m_mapHWND.insert(std::make_pair(HWND_NOTOPMOST, (CWnd*)&wndNoTopMost));\r
+ m_mapHWND.insert(std::make_pair(HWND_BOTTOM, (CWnd*)&wndBottom));\r
+ GetApp()->m_csMapLock.Release();\r
+ }\r
+\r
+ catch (const CWinException &e)\r
+ {\r
+ e.what();\r
+ throw;\r
+ }\r
+ }\r
+\r
+ inline CWinApp::~CWinApp()\r
+ {\r
+ std::vector<TLSDataPtr>::iterator iter;\r
+ for (iter = m_vTLSData.begin(); iter < m_vTLSData.end(); ++iter)\r
+ {\r
+ (*iter)->vTmpDCs.clear();\r
+#ifndef _WIN32_WCE\r
+ (*iter)->vTmpMenus.clear();\r
+#endif\r
+ (*iter)->vTmpWnds.clear();\r
+ }\r
+\r
+ // Check that all CWnd windows are destroyed\r
+ std::map<HWND, CWnd*, CompareHWND>::iterator m;\r
+ for (m = m_mapHWND.begin(); m != m_mapHWND.end(); ++m)\r
+ {\r
+ HWND hWnd = (*m).first;\r
+ if (::IsWindow(hWnd))\r
+ ::DestroyWindow(hWnd);\r
+ }\r
+ m_mapHWND.clear();\r
+ m_mapGDI.clear();\r
+ m_mapHDC.clear();\r
+ m_mapHMENU.clear();\r
+\r
+ // Do remaining tidy up\r
+ if (m_dwTlsIndex != TLS_OUT_OF_INDEXES)\r
+ {\r
+ ::TlsSetValue(GetTlsIndex(), NULL);\r
+ ::TlsFree(m_dwTlsIndex);\r
+ }\r
+\r
+ SetnGetThis((CWinApp*)-1);\r
+ }\r
+\r
+ inline void CWinApp::AddTmpDC(CDC* pDC)\r
+ {\r
+ // The TmpMenus are created by GetSybMenu.\r
+ // They are removed by CleanupTemps\r
+ assert(pDC);\r
+\r
+ // Ensure this thread has the TLS index set\r
+ TLSData* pTLSData = GetApp()->SetTlsIndex();\r
+ pTLSData->vTmpDCs.push_back(pDC); // save pDC as a smart pointer\r
+ }\r
+\r
+ inline void CWinApp::AddTmpGDI(CGDIObject* pObject)\r
+ {\r
+ // The temporary CGDIObjects are removed by CleanupTemps\r
+ assert(pObject);\r
+\r
+ // Ensure this thread has the TLS index set\r
+ TLSData* pTLSData = GetApp()->SetTlsIndex();\r
+ pTLSData->vTmpGDIs.push_back(pObject); // save pObject as a smart pointer\r
+ }\r
+\r
+#ifndef _WIN32_WCE\r
+ inline CMenu* CWinApp::AddTmpMenu(HMENU hMenu)\r
+ {\r
+ // The TmpMenus are created by GetSybMenu.\r
+ // They are removed by CleanupTemps\r
+ assert(::IsMenu(hMenu));\r
+ assert(!GetCMenuFromMap(hMenu));\r
+\r
+ CMenu* pMenu = new CMenu;\r
+ pMenu->m_hMenu = hMenu;\r
+ m_csMapLock.Lock();\r
+ m_mapHMENU.insert(std::make_pair(hMenu, pMenu));\r
+ m_csMapLock.Release();\r
+ pMenu->m_IsTmpMenu = TRUE;\r
+\r
+ // Ensure this thread has the TLS index set\r
+ TLSData* pTLSData = GetApp()->SetTlsIndex();\r
+ pTLSData->vTmpMenus.push_back(pMenu); // save pMenu as a smart pointer\r
+ return pMenu;\r
+ }\r
+#endif\r
+\r
+ inline CWnd* CWinApp::AddTmpWnd(HWND hWnd)\r
+ {\r
+ // TmpWnds are created if required to support functions like CWnd::GetParent.\r
+ // They are removed by CleanupTemps\r
+ // assert(::IsWindow(hWnd));\r
+ assert(!GetCWndFromMap(hWnd));\r
+\r
+ CWnd* pWnd = new CWnd;\r
+ pWnd->m_hWnd = hWnd;\r
+ pWnd->AddToMap();\r
+ pWnd->m_IsTmpWnd = TRUE;\r
+\r
+ // Ensure this thread has the TLS index set\r
+ TLSData* pTLSData = GetApp()->SetTlsIndex();\r
+ pTLSData->vTmpWnds.push_back(pWnd); // save pWnd as a smart pointer\r
+ return pWnd;\r
+ }\r
+\r
+ inline void CWinApp::CleanupTemps()\r
+ // Removes all Temporary CWnds and CMenus belonging to this thread\r
+ {\r
+ // Retrieve the pointer to the TLS Data\r
+ TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());\r
+ assert(pTLSData);\r
+\r
+ pTLSData->vTmpDCs.clear();\r
+ pTLSData->vTmpGDIs.clear();\r
+ pTLSData->vTmpWnds.clear();\r
+\r
+\r
+ #ifndef _WIN32_WCE\r
+ pTLSData->vTmpMenus.clear();\r
+ #endif\r
+ }\r
+\r
+ inline CDC* CWinApp::GetCDCFromMap(HDC hDC)\r
+ {\r
+ // Allocate an iterator for our HWND map\r
+ std::map<HDC, CDC*, CompareHDC>::iterator m;\r
+\r
+ // Find the CDC pointer mapped to this HDC\r
+ CDC* pDC = 0;\r
+ m_csMapLock.Lock();\r
+ m = m_mapHDC.find(hDC);\r
+\r
+ if (m != m_mapHDC.end())\r
+ pDC = m->second;\r
+\r
+ m_csMapLock.Release();\r
+ return pDC;\r
+ }\r
+\r
+ inline CGDIObject* CWinApp::GetCGDIObjectFromMap(HGDIOBJ hObject)\r
+ {\r
+ // Allocate an iterator for our HWND map\r
+ std::map<HGDIOBJ, CGDIObject*, CompareGDI>::iterator m;\r
+\r
+ // Find the CGDIObject pointer mapped to this HGDIOBJ\r
+ CGDIObject* pObject = 0;\r
+ m_csMapLock.Lock();\r
+ m = m_mapGDI.find(hObject);\r
+\r
+ if (m != m_mapGDI.end())\r
+ pObject = m->second;\r
+\r
+ m_csMapLock.Release();\r
+ return pObject;\r
+ }\r
+\r
+ inline CMenu* CWinApp::GetCMenuFromMap(HMENU hMenu)\r
+ {\r
+ std::map<HMENU, CMenu*, CompareHMENU>::iterator m;\r
+\r
+ // Find the CMenu pointer mapped to this HMENU\r
+ CMenu* pMenu = 0;\r
+ m_csMapLock.Lock();\r
+ m = m_mapHMENU.find(hMenu);\r
+\r
+ if (m != m_mapHMENU.end())\r
+ pMenu = m->second;\r
+\r
+ m_csMapLock.Release();\r
+ return pMenu;\r
+ }\r
+\r
+ inline CWnd* CWinApp::GetCWndFromMap(HWND hWnd)\r
+ {\r
+ // Allocate an iterator for our HWND map\r
+ std::map<HWND, CWnd*, CompareHWND>::iterator m;\r
+\r
+ // Find the CWnd pointer mapped to this HWND\r
+ CWnd* pWnd = 0;\r
+ m_csMapLock.Lock();\r
+ m = m_mapHWND.find(hWnd);\r
+\r
+ if (m != m_mapHWND.end())\r
+ pWnd = m->second;\r
+\r
+ m_csMapLock.Release();\r
+ return pWnd;\r
+ }\r
+\r
+ inline BOOL CWinApp::InitInstance()\r
+ {\r
+ // InitInstance contains the initialization code for your application\r
+ // You should override this function with the code to run when the application starts.\r
+\r
+ // return TRUE to indicate success. FALSE will end the application\r
+ return TRUE;\r
+ }\r
+\r
+ inline int CWinApp::MessageLoop()\r
+ {\r
+ // This gets any messages queued for the application, and dispatches them.\r
+ MSG Msg = {0};\r
+ int status = 1;\r
+ LONG lCount = 0;\r
+\r
+ while (status != 0)\r
+ {\r
+ // While idle, perform idle processing until OnIdle returns FALSE\r
+ while (!::PeekMessage(&Msg, 0, 0, 0, PM_NOREMOVE) && OnIdle(lCount) == TRUE)\r
+ {\r
+ ++lCount;\r
+ }\r
+\r
+ lCount = 0;\r
+\r
+ // Now wait until we get a message\r
+ if ((status = ::GetMessage(&Msg, NULL, 0, 0)) == -1)\r
+ return -1;\r
+\r
+ if (!PreTranslateMessage(Msg))\r
+ {\r
+ ::TranslateMessage(&Msg);\r
+ ::DispatchMessage(&Msg);\r
+ }\r
+ }\r
+\r
+ return LOWORD(Msg.wParam);\r
+ }\r
+\r
+ inline BOOL CWinApp::OnIdle(LONG lCount)\r
+ {\r
+ if (lCount == 0)\r
+ CleanupTemps();\r
+\r
+ return FALSE;\r
+ }\r
+\r
+ inline BOOL CWinApp::PreTranslateMessage(MSG Msg)\r
+ {\r
+ // This functions is called by the MessageLoop. It processes the\r
+ // keyboard accelerator keys and calls CWnd::PreTranslateMessage for\r
+ // keyboard and mouse events.\r
+\r
+ BOOL Processed = FALSE;\r
+\r
+ // only pre-translate mouse and keyboard input events\r
+ if ((Msg.message >= WM_KEYFIRST && Msg.message <= WM_KEYLAST) ||\r
+ (Msg.message >= WM_MOUSEFIRST && Msg.message <= WM_MOUSELAST))\r
+ {\r
+ // Process keyboard accelerators\r
+ if (m_pWndAccel && ::TranslateAccelerator(*m_pWndAccel, m_hAccel, &Msg))\r
+ Processed = TRUE;\r
+ else\r
+ {\r
+ // Search the chain of parents for pretranslated messages.\r
+ for (HWND hWnd = Msg.hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd))\r
+ {\r
+ CWnd* pWnd = GetCWndFromMap(hWnd);\r
+ if (pWnd)\r
+ {\r
+ Processed = pWnd->PreTranslateMessage(&Msg);\r
+ if(Processed)\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return Processed;\r
+ }\r
+\r
+ inline int CWinApp::Run()\r
+ {\r
+ // InitInstance runs the App's initialization code\r
+ if (InitInstance())\r
+ {\r
+ // Dispatch the window messages\r
+ return MessageLoop();\r
+ }\r
+ else\r
+ {\r
+ TRACE(_T("InitInstance failed! Terminating program\n"));\r
+ ::PostQuitMessage(-1);\r
+ return -1;\r
+ }\r
+ }\r
+\r
+ inline void CWinApp::SetAccelerators(HACCEL hAccel, CWnd* pWndAccel)\r
+ // nID is the resource ID of the accelerator table\r
+ // pWndAccel is the window pointer for translated messages\r
+ {\r
+ assert (hAccel);\r
+ assert (pWndAccel);\r
+\r
+ m_pWndAccel = pWndAccel;\r
+ m_hAccel = hAccel;\r
+ }\r
+\r
+ inline void CWinApp::SetCallback()\r
+ {\r
+ // Registers a temporary window class so we can get the callback\r
+ // address of CWnd::StaticWindowProc.\r
+ // This technique works for all Window versions, including WinCE.\r
+\r
+ WNDCLASS wcDefault = {0};\r
+\r
+ LPCTSTR szClassName = _T("Win32++ Temporary Window Class");\r
+ wcDefault.hInstance = GetInstanceHandle();\r
+ wcDefault.lpfnWndProc = CWnd::StaticWindowProc;\r
+ wcDefault.lpszClassName = szClassName;\r
+\r
+ ::RegisterClass(&wcDefault);\r
+\r
+ // Retrieve the class information\r
+ ZeroMemory(&wcDefault, sizeof(wcDefault));\r
+ ::GetClassInfo(GetInstanceHandle(), szClassName, &wcDefault);\r
+\r
+ // Save the callback address of CWnd::StaticWindowProc\r
+ assert(wcDefault.lpfnWndProc); // Assert fails when running UNICODE build on ANSI OS.\r
+ m_Callback = wcDefault.lpfnWndProc;\r
+ ::UnregisterClass(szClassName, GetInstanceHandle());\r
+ }\r
+\r
+ inline CWinApp* CWinApp::SetnGetThis(CWinApp* pThis /*= 0*/)\r
+ {\r
+ // This function stores the 'this' pointer in a static variable.\r
+ // Once stored, it can be used later to return the 'this' pointer.\r
+ // CWinApp's Destructor calls this function with a value of -1.\r
+\r
+ static CWinApp* pWinApp = 0;\r
+\r
+ if ((CWinApp*)-1 == pThis)\r
+ pWinApp = 0;\r
+ else if (0 == pWinApp)\r
+ pWinApp = pThis;\r
+\r
+ return pWinApp;\r
+ }\r
+\r
+ inline void CWinApp::SetResourceHandle(HINSTANCE hResource)\r
+ {\r
+ // This function can be used to load a resource dll.\r
+ // A resource dll can be used to define resources in different languages.\r
+ // To use this function, place code like this in InitInstance\r
+ //\r
+ // HINSTANCE hResource = LoadLibrary(_T("MyResourceDLL.dll"));\r
+ // SetResourceHandle(hResource);\r
+\r
+ m_hResource = hResource;\r
+ }\r
+\r
+ inline TLSData* CWinApp::SetTlsIndex()\r
+ {\r
+ TLSData* pTLSData = (TLSData*)::TlsGetValue(GetTlsIndex());\r
+ if (NULL == pTLSData)\r
+ {\r
+ pTLSData = new TLSData;\r
+\r
+ m_csTLSLock.Lock();\r
+ m_vTLSData.push_back(pTLSData); // store as a Shared_Ptr\r
+ m_csTLSLock.Release();\r
+\r
+ ::TlsSetValue(GetTlsIndex(), pTLSData);\r
+ }\r
+\r
+ return pTLSData;\r
+ }\r
+\r
+\r
+ ////////////////////////////////////////\r
+ // Definitions for the CWnd class\r
+ //\r
+ inline CWnd::CWnd() : m_hWnd(NULL), m_PrevWindowProc(NULL), m_IsTmpWnd(FALSE)\r
+ {\r
+ // Note: m_hWnd is set in CWnd::CreateEx(...)\r
+ m_pcs = new CREATESTRUCT; // store the CREATESTRICT in a smart pointer\r
+ m_pwc = new WNDCLASS; // store the WNDCLASS in a smart pointer\r
+ ::ZeroMemory(m_pcs.get(), sizeof(CREATESTRUCT));\r
+ ::ZeroMemory(m_pwc.get(), sizeof(WNDCLASS));\r
+ }\r
+\r
+ inline CWnd::~CWnd()\r
+ {\r
+ // Destroys the window for this object and cleans up resources.\r
+ Destroy();\r
+ }\r
+\r
+ inline void CWnd::AddToMap()\r
+ // Store the window handle and CWnd pointer in the HWND map\r
+ {\r
+ assert( GetApp() );\r
+ GetApp()->m_csMapLock.Lock();\r
+\r
+ // assert(::IsWindow(m_hWnd));\r
+ assert(!GetApp()->GetCWndFromMap(m_hWnd));\r
+\r
+ GetApp()->m_mapHWND.insert(std::make_pair(m_hWnd, this));\r
+ GetApp()->m_csMapLock.Release();\r
+ }\r
+\r
+ inline BOOL CWnd::Attach(HWND hWnd)\r
+ // Subclass an existing window and attach it to a CWnd\r
+ {\r
+ assert( GetApp() );\r
+ assert(::IsWindow(hWnd));\r
+\r
+ // Ensure this thread has the TLS index set\r
+ // Note: Perform the attach from the same thread as the window's message loop\r
+ GetApp()->SetTlsIndex();\r
+\r
+ // Cleanup any previous attachment\r
+ if (m_PrevWindowProc)\r
+ Detach();\r
+ CWnd* pWnd = GetApp()->GetCWndFromMap(hWnd);\r
+ if (pWnd)\r
+ pWnd->Cleanup();\r
+\r
+ Subclass(hWnd); // Set the window's callback to CWnd::StaticWindowProc\r
+ AddToMap(); // Store the CWnd pointer in the HWND map\r
+ OnCreate();\r
+ OnInitialUpdate();\r
+\r
+ return TRUE;\r
+ }\r
+\r
+ inline BOOL CWnd::AttachDlgItem(UINT nID, CWnd* pParent)\r
+ // Converts a dialog item to a CWnd object\r
+ {\r
+ assert(pParent->IsWindow());\r
+\r
+ HWND hWnd = ::GetDlgItem(pParent->GetHwnd(), nID);\r
+ return Attach(hWnd);\r
+ }\r
+\r
+ inline void CWnd::CenterWindow() const\r
+ // Centers this window over it's parent\r
+ {\r
+\r
+ // required for multi-monitor support with Dev-C++ and VC6\r
+ #ifndef _WIN32_WCE\r
+ #ifndef MONITOR_DEFAULTTONEAREST\r
+ #define MONITOR_DEFAULTTONEAREST 0x00000002\r
+ #endif\r
+ #ifndef HMONITOR\r
+ DECLARE_HANDLE(HMONITOR);\r
+ #endif\r
+ #ifndef MONITORINFO\r
+ typedef struct tagMONITORINFO\r
+ {\r
+ DWORD cbSize;\r
+ RECT rcMonitor;\r
+ RECT rcWork;\r
+ DWORD dwFlags;\r
+ } MONITORINFO, *LPMONITORINFO;\r
+ #endif // MONITOR_DEFAULTTONEAREST\r
+ #endif // _WIN32_WCE\r
+\r
+ assert(::IsWindow(m_hWnd));\r
+\r
+ CRect rc = GetWindowRect();\r
+ CRect rcParent;\r
+ CRect rcDesktop;\r
+\r
+ // Get screen dimensions excluding task bar\r
+ ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesktop, 0);\r
+\r
+ // Get the parent window dimensions (parent could be the desktop)\r
+ if (GetParent() != NULL) rcParent = GetParent()->GetWindowRect();\r
+ else rcParent = rcDesktop;\r
+\r
+ #ifndef _WIN32_WCE\r
+ // Import the GetMonitorInfo and MonitorFromWindow functions\r
+ HMODULE hUser32 = LoadLibrary(_T("USER32.DLL"));\r
+ typedef BOOL (WINAPI* LPGMI)(HMONITOR hMonitor, LPMONITORINFO lpmi);\r
+ typedef HMONITOR (WINAPI* LPMFW)(HWND hwnd, DWORD dwFlags);\r
+ LPMFW pfnMonitorFromWindow = (LPMFW)::GetProcAddress(hUser32, "MonitorFromWindow");\r
+ #ifdef _UNICODE\r
+ LPGMI pfnGetMonitorInfo = (LPGMI)::GetProcAddress(hUser32, "GetMonitorInfoW");\r
+ #else\r
+ LPGMI pfnGetMonitorInfo = (LPGMI)::GetProcAddress(hUser32, "GetMonitorInfoA");\r
+ #endif\r
+\r
+ // Take multi-monitor systems into account\r
+ if (pfnGetMonitorInfo && pfnMonitorFromWindow)\r
+ {\r
+ HMONITOR hActiveMonitor = pfnMonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);\r
+ MONITORINFO mi = { sizeof(mi), 0};\r
+\r
+ if(pfnGetMonitorInfo(hActiveMonitor, &mi))\r
+ {\r
+ rcDesktop = mi.rcWork;\r
+ if (GetParent() == NULL) rcParent = mi.rcWork;\r
+ }\r
+ }\r
+ FreeLibrary(hUser32);\r
+ #endif\r
+\r
+ // Calculate point to center the dialog over the portion of parent window on this monitor\r
+ rcParent.IntersectRect(rcParent, rcDesktop);\r
+ int x = rcParent.left + (rcParent.Width() - rc.Width())/2;\r
+ int y = rcParent.top + (rcParent.Height() - rc.Height())/2;\r
+\r
+ // Keep the dialog wholly on the monitor display\r
+ x = (x < rcDesktop.left)? rcDesktop.left : x;\r
+ x = (x > rcDesktop.right - rc.Width())? rcDesktop.right - rc.Width() : x;\r
+ y = (y < rcDesktop.top) ? rcDesktop.top: y;\r
+ y = (y > rcDesktop.bottom - rc.Height())? rcDesktop.bottom - rc.Height() : y;\r
+\r
+ SetWindowPos(0, x, y, 0, 0, SWP_NOSIZE);\r
+ }\r
+\r
+ inline void CWnd::Cleanup()\r
+ // Returns the CWnd to its default state\r
+ {\r
+ if ( GetApp() ) RemoveFromMap();\r
+ m_hWnd = NULL;\r
+ m_PrevWindowProc = NULL;\r
+ m_IsTmpWnd = FALSE;\r
+ }\r
+\r
+ inline HWND CWnd::Create(CWnd* pParent /* = NULL */)\r
+ // Creates the window. This is the default method of window creation.\r
+ {\r
+\r
+ // Test if Win32++ has been started\r
+ assert( GetApp() );\r
+\r
+ // Set the WNDCLASS parameters\r
+ PreRegisterClass(*m_pwc);\r
+ if (m_pwc->lpszClassName)\r
+ {\r
+ RegisterClass(*m_pwc);\r
+ m_pcs->lpszClass = m_pwc->lpszClassName;\r
+ }\r
+\r
+ // Set the CREATESTRUCT parameters\r
+ PreCreate(*m_pcs);\r
+\r
+ // Set the Window Class Name\r
+ if (!m_pcs->lpszClass)\r
+ m_pcs->lpszClass = _T("Win32++ Window");\r
+\r
+ // Set Parent\r
+ HWND hWndParent = pParent? pParent->GetHwnd() : 0;\r
+ if (!hWndParent && m_pcs->hwndParent)\r
+ hWndParent = m_pcs->hwndParent;\r
+\r
+ // Set the window style\r
+ DWORD dwStyle;\r
+ DWORD dwOverlappedStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;\r
+ if (m_pcs->style)\r
+ dwStyle = m_pcs->style;\r
+ else\r
+ dwStyle = WS_VISIBLE | ((hWndParent)? WS_CHILD : dwOverlappedStyle);\r
+\r
+ // Set window size and position\r
+ int x = (m_pcs->cx || m_pcs->cy)? m_pcs->x : CW_USEDEFAULT;\r
+ int cx = (m_pcs->cx || m_pcs->cy)? m_pcs->cx : CW_USEDEFAULT;\r
+ int y = (m_pcs->cx || m_pcs->cy)? m_pcs->y : CW_USEDEFAULT;\r
+ int cy = (m_pcs->cx || m_pcs->cy)? m_pcs->cy : CW_USEDEFAULT;\r
+\r
+ // Create the window\r
+#ifndef _WIN32_WCE\r
+ CreateEx(m_pcs->dwExStyle, m_pcs->lpszClass, m_pcs->lpszName, dwStyle, x, y,\r
+ cx, cy, pParent, FromHandle(m_pcs->hMenu), m_pcs->lpCreateParams);\r
+#else\r
+ CreateEx(m_pcs->dwExStyle, m_pcs->lpszClass, m_pcs->lpszName, dwStyle, x, y,\r
+ cx, cy, pParent, 0, m_pcs->lpCreateParams);\r
+#endif\r
+\r
+ return m_hWnd;\r
+ }\r
+\r
+ inline HWND CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rc, CWnd* pParent, CMenu* pMenu, LPVOID lpParam /*= NULL*/)\r
+ // Creates the window by specifying all the window creation parameters\r
+ {\r
+ int x = rc.left;\r
+ int y = rc.top;\r
+ int cx = rc.right - rc.left;\r
+ int cy = rc.bottom - rc.top;\r
+ return CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle, x, y, cx, cy, pParent, pMenu, lpParam);\r
+ }\r
+\r
+ 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
+ // Creates the window by specifying all the window creation parameters\r
+ {\r
+\r
+ assert( GetApp() ); // Test if Win32++ has been started\r
+ assert(!::IsWindow(m_hWnd)); // Only one window per CWnd instance allowed\r
+\r
+ try\r
+ {\r
+ // Prepare the CWnd if it has been reused\r
+ Destroy();\r
+\r
+ // Ensure a window class is registered\r
+ std::vector<TCHAR> vTChar( MAX_STRING_SIZE+1, _T('\0') );\r
+ TCHAR* ClassName = &vTChar[0];\r
+ if (0 == lpszClassName || 0 == lstrlen(lpszClassName) )\r
+ lstrcpyn (ClassName, _T("Win32++ Window"), MAX_STRING_SIZE);\r
+ else\r
+ // Create our own local copy of szClassName.\r
+ lstrcpyn(ClassName, lpszClassName, MAX_STRING_SIZE);\r
+\r
+ WNDCLASS wc = {0};\r
+ wc.lpszClassName = ClassName;\r
+ wc.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);\r
+ wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);\r
+\r
+ // Register the window class (if not already registered)\r
+ if (!RegisterClass(wc))\r
+ throw CWinException(_T("Failed to register window class"));\r
+\r
+ HWND hWndParent = pParent? pParent->GetHwnd() : 0;\r
+\r
+ // Ensure this thread has the TLS index set\r
+ TLSData* pTLSData = GetApp()->SetTlsIndex();\r
+\r
+ // Store the CWnd pointer in thread local storage\r
+ pTLSData->pCWnd = this;\r
+\r
+ // Create window\r
+#ifdef _WIN32_WCE\r
+ m_hWnd = ::CreateWindowEx(dwExStyle, ClassName, lpszWindowName, dwStyle, x, y, nWidth, nHeight,\r
+ hWndParent, 0, GetApp()->GetInstanceHandle(), lpParam);\r
+#else\r
+ HMENU hMenu = pMenu? pMenu->GetHandle() : NULL;\r
+ m_hWnd = ::CreateWindowEx(dwExStyle, ClassName, lpszWindowName, dwStyle, x, y, nWidth, nHeight,\r
+ hWndParent, hMenu, GetApp()->GetInstanceHandle(), lpParam);\r
+#endif\r
+\r
+ // Now handle window creation failure\r
+ if (!m_hWnd)\r
+ throw CWinException(_T("Failed to Create Window"));\r
+\r
+ // Automatically subclass predefined window class types\r
+ ::GetClassInfo(GetApp()->GetInstanceHandle(), lpszClassName, &wc);\r
+ if (wc.lpfnWndProc != GetApp()->m_Callback)\r
+ {\r
+ Subclass(m_hWnd);\r
+\r
+ // Send a message to force the HWND to be added to the map\r
+ SendMessage(WM_NULL, 0L, 0L);\r
+\r
+ OnCreate(); // We missed the WM_CREATE message, so call OnCreate now\r
+ }\r
+\r
+ // Clear the CWnd pointer from TLS\r
+ pTLSData->pCWnd = NULL;\r
+ }\r
+\r
+ catch (const CWinException &e)\r
+ {\r
+ TRACE(_T("\n*** Failed to create window ***\n"));\r
+ e.what(); // Display the last error message.\r
+\r
+ // eat the exception (don't rethrow)\r
+ }\r
+\r
+ // Window creation is complete. Now call OnInitialUpdate\r
+ OnInitialUpdate();\r
+\r
+ return m_hWnd;\r
+ }\r
+\r
+ inline void CWnd::Destroy()\r
+ // Destroys the window and returns the CWnd back to its default state, ready for reuse.\r
+ {\r
+ if (m_IsTmpWnd)\r
+ m_hWnd = NULL;\r
+\r
+ if (IsWindow())\r
+ ::DestroyWindow(m_hWnd);\r
+\r
+ // Return the CWnd to its default state\r
+ Cleanup();\r
+ }\r
+\r
+ inline HWND CWnd::Detach()\r
+ // Reverse an Attach\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(0 != m_PrevWindowProc); // Only a subclassed window can be detached\r
+\r
+ SetWindowLongPtr(GWLP_WNDPROC, (LONG_PTR)m_PrevWindowProc);\r
+ HWND hWnd = m_hWnd;\r
+ Cleanup();\r
+\r
+ return hWnd;\r
+ }\r
+\r
+ inline LRESULT CWnd::FinalWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+ // Pass messages on to the appropriate default window procedure\r
+ // CMDIChild and CMDIFrame override this function\r
+ {\r
+ return ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);\r
+ }\r
+\r
+ inline CWnd* CWnd::GetAncestor(UINT gaFlags /*= GA_ROOTOWNER*/) const\r
+ // The GetAncestor function retrieves a pointer to the ancestor (root parent)\r
+ // of the window. Supports Win95.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ HWND hWnd = m_hWnd;\r
+\r
+ // Load the User32 DLL\r
+ typedef HWND WINAPI GETANCESTOR(HWND, UINT);\r
+ GETANCESTOR* pfnGetAncestor = NULL;\r
+ HMODULE hModule = ::LoadLibrary(_T("USER32.DLL"));\r
+\r
+ if (hModule)\r
+ {\r
+ // Declare a pointer to the GetAncestor function\r
+#ifndef _WIN32_WCE\r
+ pfnGetAncestor = (GETANCESTOR*)::GetProcAddress(hModule, "GetAncestor");\r
+#else\r
+ pfnGetAncestor = (GETANCESTOR*)::GetProcAddress(hModule, L"GetAncestor");\r
+#endif\r
+\r
+ if (pfnGetAncestor)\r
+ hWnd = (*pfnGetAncestor)(m_hWnd, gaFlags);\r
+\r
+ ::FreeLibrary(hModule);\r
+ }\r
+\r
+ if (!pfnGetAncestor)\r
+ {\r
+ // Provide our own GetAncestor if necessary\r
+ HWND hWndParent = ::GetParent(hWnd);\r
+ while (::IsChild(hWndParent, hWnd))\r
+ {\r
+ hWnd = hWndParent;\r
+ hWndParent = ::GetParent(hWnd);\r
+ }\r
+ }\r
+\r
+ return FromHandle(hWnd);\r
+ }\r
+\r
+ inline CString CWnd::GetClassName() const\r
+ // Retrieves the name of the class to which the specified window belongs.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+\r
+ CString str;\r
+ LPTSTR szStr = str.GetBuffer(MAX_STRING_SIZE+1);\r
+ ::GetClassName(m_hWnd, szStr, MAX_STRING_SIZE+1);\r
+ str.ReleaseBuffer();\r
+ return str;\r
+ }\r
+\r
+ inline CString CWnd::GetDlgItemText(int nIDDlgItem) const\r
+ // Retrieves the title or text associated with a control in a dialog box.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+\r
+ int nLength = ::GetWindowTextLength(::GetDlgItem(m_hWnd, nIDDlgItem));\r
+ CString str;\r
+ LPTSTR szStr = str.GetBuffer(nLength+1);\r
+ ::GetDlgItemText(m_hWnd, nIDDlgItem, szStr, nLength+1);\r
+ str.ReleaseBuffer();\r
+ return str;\r
+ }\r
+\r
+ inline CString CWnd::GetWindowText() const\r
+ // Retrieves the text of the window's title bar.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+\r
+ int nLength = ::GetWindowTextLength(m_hWnd);\r
+ CString str;\r
+ LPTSTR szStr = str.GetBuffer(nLength+1);\r
+ ::GetWindowText(m_hWnd, szStr, nLength+1);\r
+ str.ReleaseBuffer();\r
+ return str;\r
+ }\r
+\r
+ inline BOOL CWnd::OnCommand(WPARAM wParam, LPARAM lParam)\r
+ {\r
+ UNREFERENCED_PARAMETER(wParam);\r
+ UNREFERENCED_PARAMETER(lParam);\r
+\r
+ // Override this to handle WM_COMMAND messages, for example\r
+\r
+ // switch (LOWORD(wParam))\r
+ // {\r
+ // case IDM_FILE_NEW:\r
+ // OnFileNew();\r
+ // TRUE; // return TRUE for handled commands\r
+ // }\r
+\r
+ // return FALSE for unhandled commands\r
+ return FALSE;\r
+ }\r
+\r
+ inline void CWnd::OnCreate()\r
+ {\r
+ // This function is called when a WM_CREATE message is recieved\r
+ // Override it in your derived class to automatically perform tasks\r
+ // during window creation.\r
+ }\r
+\r
+ inline void CWnd::OnDraw(CDC* pDC)\r
+ // Called when part of the client area of the window needs to be drawn\r
+ {\r
+ UNREFERENCED_PARAMETER(pDC);\r
+\r
+ // Override this function in your derived class to perform drawing tasks.\r
+ }\r
+\r
+ inline BOOL CWnd::OnEraseBkgnd(CDC* pDC)\r
+ // Called when the background of the window's client area needs to be erased.\r
+ {\r
+ UNREFERENCED_PARAMETER(pDC);\r
+\r
+ // Override this function in your derived class to perform drawing tasks.\r
+\r
+ // Return Value: Return FALSE to also permit default erasure of the background\r
+ // Return TRUE to prevent default erasure of the background\r
+\r
+ return FALSE;\r
+ }\r
+\r
+\r
+ inline void CWnd::OnInitialUpdate()\r
+ {\r
+ // This function is called automatically once the window is created\r
+ // Override it in your derived class to automatically perform tasks\r
+ // after window creation.\r
+ }\r
+\r
+ inline LRESULT CWnd::MessageReflect(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+ {\r
+ // A function used to call OnMessageReflect. You shouldn't need to call or\r
+ // override this function.\r
+\r
+ HWND hWnd = NULL;\r
+ switch (uMsg)\r
+ {\r
+ case WM_COMMAND:\r
+ case WM_CTLCOLORBTN:\r
+ case WM_CTLCOLOREDIT:\r
+ case WM_CTLCOLORDLG:\r
+ case WM_CTLCOLORLISTBOX:\r
+ case WM_CTLCOLORSCROLLBAR:\r
+ case WM_CTLCOLORSTATIC:\r
+ case WM_CHARTOITEM:\r
+ case WM_VKEYTOITEM:\r
+ case WM_HSCROLL:\r
+ case WM_VSCROLL:\r
+ hWnd = (HWND)lParam;\r
+ break;\r
+\r
+ case WM_DRAWITEM:\r
+ case WM_MEASUREITEM:\r
+ case WM_DELETEITEM:\r
+ case WM_COMPAREITEM:\r
+ hWnd = ::GetDlgItem(hWndParent, (int)wParam);\r
+ break;\r
+\r
+ case WM_PARENTNOTIFY:\r
+ switch(LOWORD(wParam))\r
+ {\r
+ case WM_CREATE:\r
+ case WM_DESTROY:\r
+ hWnd = (HWND)lParam;\r
+ break;\r
+ }\r
+ }\r
+\r
+ CWnd* Wnd = GetApp()->GetCWndFromMap(hWnd);\r
+\r
+ if (Wnd != NULL)\r
+ return Wnd->OnMessageReflect(uMsg, wParam, lParam);\r
+\r
+ return 0L;\r
+ }\r
+\r
+ inline LRESULT CWnd::OnMessageReflect(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+ {\r
+ UNREFERENCED_PARAMETER(uMsg);\r
+ UNREFERENCED_PARAMETER(wParam);\r
+ UNREFERENCED_PARAMETER(lParam);\r
+ // This function processes those special messages (see above) sent\r
+ // by some older controls, and reflects them back to the originating CWnd object.\r
+ // Override this function in your derrived class to handle these special messages.\r
+\r
+ // Your overriding function should look like this ...\r
+\r
+ // switch (uMsg)\r
+ // {\r
+ // Handle your reflected messages here\r
+ // }\r
+\r
+ // return 0L for unhandled messages\r
+ return 0L;\r
+ }\r
+\r
+ inline LRESULT CWnd::OnNotify(WPARAM wParam, LPARAM lParam)\r
+ {\r
+ UNREFERENCED_PARAMETER(wParam);\r
+ UNREFERENCED_PARAMETER(lParam);\r
+\r
+ // You can use either OnNotifyReflect or OnNotify to handle notifications\r
+ // Override OnNotifyReflect to handle notifications in the CWnd class that\r
+ // generated the notification. OR\r
+ // Override OnNotify to handle notifications in the PARENT of the CWnd class\r
+ // that generated the notification.\r
+\r
+ // Your overriding function should look like this ...\r
+\r
+ // switch (((LPNMHDR)lParam)->code)\r
+ // {\r
+ // Handle your notifications from the CHILD window here\r
+ // Return the value recommended by the Windows API documentation.\r
+ // For many notifications, the return value doesn't matter, but for some it does.\r
+ // }\r
+\r
+ // return 0L for unhandled notifications\r
+ return 0L;\r
+ }\r
+\r
+ inline LRESULT CWnd::OnNotifyReflect(WPARAM wParam, LPARAM lParam)\r
+ {\r
+ UNREFERENCED_PARAMETER(wParam);\r
+ UNREFERENCED_PARAMETER(lParam);\r
+\r
+ // Override OnNotifyReflect to handle notifications in the CWnd class that\r
+ // generated the notification.\r
+\r
+ // Your overriding function should look like this ...\r
+\r
+ // switch (((LPNMHDR)lParam)->code)\r
+ // {\r
+ // Handle your notifications from this window here\r
+ // Return the value recommended by the Windows API documentation.\r
+ // }\r
+\r
+ // return 0L for unhandled notifications\r
+ return 0L;\r
+ }\r
+\r
+ inline void CWnd::OnMenuUpdate(UINT nID)\r
+ // Called when menu items are about to be displayed\r
+ {\r
+ UNREFERENCED_PARAMETER(nID);\r
+\r
+ // Override this function to modify the behaviour of menu items,\r
+ // such as adding or removing checkmarks\r
+ }\r
+\r
+ inline void CWnd::PreCreate(CREATESTRUCT& cs)\r
+ // Called by CWnd::Create to set some window parameters\r
+ {\r
+ // Test if Win32++ has been started\r
+ assert(GetApp()); // Test if Win32++ has been started\r
+\r
+ m_pcs->cx = cs.cx;\r
+ m_pcs->cy = cs.cy;\r
+ m_pcs->dwExStyle = cs.dwExStyle;\r
+ m_pcs->hInstance = GetApp()->GetInstanceHandle();\r
+ m_pcs->hMenu = cs.hMenu;\r
+ m_pcs->hwndParent = cs.hwndParent;\r
+ m_pcs->lpCreateParams = cs.lpCreateParams;\r
+ m_pcs->lpszClass = cs.lpszClass;\r
+ m_pcs->lpszName = cs.lpszName;\r
+ m_pcs->style = cs.style;\r
+ m_pcs->x = cs.x;\r
+ m_pcs->y = cs.y;\r
+\r
+ // Overide this function in your derived class to set the\r
+ // CREATESTRUCT values prior to window creation.\r
+ // The cs.lpszClass parameter should NOT be specified if the\r
+ // PreRegisterClass function is used to create a window class.\r
+ }\r
+\r
+ inline void CWnd::PreRegisterClass(WNDCLASS& wc)\r
+ // Called by CWnd::Create to set some window parameters\r
+ // Useful for setting the background brush and cursor\r
+ {\r
+ // Test if Win32++ has been started\r
+ assert( GetApp() );\r
+\r
+ m_pwc->style = wc.style;\r
+ m_pwc->lpfnWndProc = CWnd::StaticWindowProc;\r
+ m_pwc->cbClsExtra = wc.cbClsExtra;\r
+ m_pwc->cbWndExtra = wc.cbWndExtra;\r
+ m_pwc->hInstance = GetApp()->GetInstanceHandle();\r
+ m_pwc->hIcon = wc.hIcon;\r
+ m_pwc->hCursor = wc.hCursor;\r
+ m_pwc->hbrBackground = wc.hbrBackground;\r
+ m_pwc->lpszMenuName = wc.lpszMenuName;\r
+ m_pwc->lpszClassName = wc.lpszClassName;\r
+\r
+ // Overide this function in your derived class to set the\r
+ // WNDCLASS values prior to window creation.\r
+\r
+ // ADDITIONAL NOTES:\r
+ // 1) The lpszClassName must be set for this function to take effect.\r
+ // 2) The lpfnWndProc is always CWnd::StaticWindowProc.\r
+ // 3) No other defaults are set, so the following settings might prove useful\r
+ // wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);\r
+ // wc.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);\r
+ // wc.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);\r
+ // 4) The styles that can be set here are WNDCLASS styles. These are a different\r
+ // set of styles to those set by CREATESTRUCT (used in PreCreate).\r
+ // 5) RegisterClassEx is not used because its not supported on WinCE.\r
+ // To set a small icon for the window, use SetIconSmall.\r
+ }\r
+\r
+ inline BOOL CWnd::PreTranslateMessage(MSG* pMsg)\r
+ {\r
+ UNREFERENCED_PARAMETER(pMsg);\r
+\r
+ // Override this function if your class requires input messages to be\r
+ // translated before normal processing. Function which translate messages\r
+ // include TranslateAccelerator, TranslateMDISysAccel and IsDialogMessage.\r
+ // Return TRUE if the message is translated.\r
+\r
+ return FALSE;\r
+ }\r
+\r
+ inline BOOL CWnd::RegisterClass(WNDCLASS& wc)\r
+ // A private function used by the PreRegisterClass function to register a\r
+ // window class prior to window creation\r
+ {\r
+ assert( GetApp() );\r
+ assert( (0 != lstrlen(wc.lpszClassName) && ( lstrlen(wc.lpszClassName) <= MAX_STRING_SIZE) ) );\r
+\r
+ // Check to see if this classname is already registered\r
+ WNDCLASS wcTest = {0};\r
+ BOOL Done = FALSE;\r
+\r
+ if (::GetClassInfo(GetApp()->GetInstanceHandle(), wc.lpszClassName, &wcTest))\r
+ {\r
+ wc = wcTest;\r
+ Done = TRUE;\r
+ }\r
+\r
+ if (!Done)\r
+ {\r
+ // Set defaults\r
+ wc.hInstance = GetApp()->GetInstanceHandle();\r
+ wc.lpfnWndProc = CWnd::StaticWindowProc;\r
+\r
+ // Register the WNDCLASS structure\r
+ if ( !::RegisterClass(&wc) )\r
+ throw CWinException(_T("Failed to register window class"));\r
+\r
+ Done = TRUE;\r
+ }\r
+\r
+ return Done;\r
+ }\r
+\r
+ inline BOOL CWnd::RemoveFromMap()\r
+ {\r
+ BOOL Success = FALSE;\r
+\r
+ if (GetApp())\r
+ {\r
+\r
+ // Allocate an iterator for our HWND map\r
+ std::map<HWND, CWnd*, CompareHWND>::iterator m;\r
+\r
+ CWinApp* pApp = GetApp();\r
+ if (pApp)\r
+ {\r
+ // Erase the CWnd pointer entry from the map\r
+ pApp->m_csMapLock.Lock();\r
+ for (m = pApp->m_mapHWND.begin(); m != pApp->m_mapHWND.end(); ++m)\r
+ {\r
+ if (this == m->second)\r
+ {\r
+ pApp->m_mapHWND.erase(m);\r
+ Success = TRUE;\r
+ break;\r
+ }\r
+ }\r
+\r
+ pApp->m_csMapLock.Release();\r
+ }\r
+ }\r
+\r
+ return Success;\r
+ }\r
+\r
+ inline HICON CWnd::SetIconLarge(int nIcon)\r
+ // Sets the large icon associated with the window\r
+ {\r
+ assert( GetApp() );\r
+ assert(::IsWindow(m_hWnd));\r
+\r
+ HICON hIconLarge = (HICON) (::LoadImage (GetApp()->GetResourceHandle(), MAKEINTRESOURCE (nIcon), IMAGE_ICON,\r
+ ::GetSystemMetrics (SM_CXICON), ::GetSystemMetrics (SM_CYICON), 0));\r
+\r
+ if (hIconLarge)\r
+ SendMessage (WM_SETICON, WPARAM (ICON_BIG), LPARAM (hIconLarge));\r
+ else\r
+ TRACE(_T("**WARNING** SetIconLarge Failed\n"));\r
+\r
+ return hIconLarge;\r
+ }\r
+\r
+ inline HICON CWnd::SetIconSmall(int nIcon)\r
+ // Sets the small icon associated with the window\r
+ {\r
+ assert( GetApp() );\r
+ assert(::IsWindow(m_hWnd));\r
+\r
+ HICON hIconSmall = (HICON) (::LoadImage (GetApp()->GetResourceHandle(), MAKEINTRESOURCE (nIcon), IMAGE_ICON,\r
+ ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0));\r
+\r
+ if (hIconSmall)\r
+ SendMessage (WM_SETICON, WPARAM (ICON_SMALL), LPARAM (hIconSmall));\r
+ else\r
+ TRACE(_T("**WARNING** SetIconSmall Failed\n"));\r
+\r
+ return hIconSmall;\r
+ }\r
+\r
+ inline LRESULT CALLBACK CWnd::StaticWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+ // All CWnd windows direct their messages here. This function redirects the message\r
+ // to the CWnd's WndProc function.\r
+ {\r
+ assert( GetApp() );\r
+\r
+ CWnd* w = GetApp()->GetCWndFromMap(hWnd);\r
+ if (0 == w)\r
+ {\r
+ // The CWnd pointer wasn't found in the map, so add it now\r
+\r
+ // Retrieve the pointer to the TLS Data\r
+ TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());\r
+ assert(pTLSData);\r
+\r
+ // Retrieve pointer to CWnd object from Thread Local Storage TLS\r
+ w = pTLSData->pCWnd;\r
+ assert(w); // pTLSData->pCWnd is assigned in CreateEx\r
+ pTLSData->pCWnd = NULL;\r
+\r
+ // Store the CWnd pointer in the HWND map\r
+ w->m_hWnd = hWnd;\r
+ w->AddToMap();\r
+ }\r
+\r
+ return w->WndProc(uMsg, wParam, lParam);\r
+\r
+ } // LRESULT CALLBACK StaticWindowProc(...)\r
+\r
+ inline void CWnd::Subclass(HWND hWnd)\r
+ // A private function used by CreateEx, Attach and AttachDlgItem\r
+ {\r
+ assert(::IsWindow(hWnd));\r
+\r
+ m_PrevWindowProc = (WNDPROC)::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)CWnd::StaticWindowProc);\r
+ m_hWnd = hWnd;\r
+ }\r
+\r
+ inline LRESULT CWnd::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+ {\r
+ // Override this function in your class derrived from CWnd to handle\r
+ // window messages. A typical function might look like this:\r
+\r
+ // switch (uMsg)\r
+ // {\r
+ // case MESSAGE1: // Some Windows API message\r
+ // OnMessage1(); // A user defined function\r
+ // break; // Also do default processing\r
+ // case MESSAGE2:\r
+ // OnMessage2();\r
+ // return x; // Don't do default processing, but instead return\r
+ // // a value recommended by the Windows API documentation\r
+ // }\r
+\r
+ // Always pass unhandled messages on to WndProcDefault\r
+ return WndProcDefault(uMsg, wParam, lParam);\r
+ }\r
+\r
+ inline LRESULT CWnd::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+ // All WndProc functions should pass unhandled window messages to this function\r
+ {\r
+ LRESULT lr = 0L;\r
+\r
+ switch (uMsg)\r
+ {\r
+ case UWM_CLEANUPTEMPS:\r
+ {\r
+ TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());\r
+ pTLSData->vTmpWnds.clear();\r
+ }\r
+ break;\r
+ case WM_COMMAND:\r
+ {\r
+ // Refelect this message if it's from a control\r
+ CWnd* pWnd = GetApp()->GetCWndFromMap((HWND)lParam);\r
+ if (pWnd != NULL)\r
+ lr = pWnd->OnCommand(wParam, lParam);\r
+\r
+ // Handle user commands\r
+ if (!lr)\r
+ lr = OnCommand(wParam, lParam);\r
+\r
+ if (lr) return 0L;\r
+ }\r
+ break; // Note: Some MDI commands require default processing\r
+ case WM_CREATE:\r
+ OnCreate();\r
+ break;\r
+ // An example of how to end the application when the window closes\r
+ // If needed, put this in the class you inherit from CWnd\r
+ // case WM_DESTROY:\r
+ // ::PostQuitMessage(0);\r
+ // return 0L;\r
+ case WM_NOTIFY:\r
+ {\r
+ // Do Notification reflection if it came from a CWnd object\r
+ HWND hwndFrom = ((LPNMHDR)lParam)->hwndFrom;\r
+ CWnd* pWndFrom = GetApp()->GetCWndFromMap(hwndFrom);\r
+\r
+ if (lstrcmp(GetClassName(), _T("ReBarWindow32")) != 0) // Skip notification reflection for rebars to avoid double handling\r
+ {\r
+ if (pWndFrom != NULL)\r
+ lr = pWndFrom->OnNotifyReflect(wParam, lParam);\r
+ else\r
+ {\r
+ // Some controls (eg ListView) have child windows.\r
+ // Reflect those notifications too.\r
+ CWnd* pWndFromParent = GetApp()->GetCWndFromMap(::GetParent(hwndFrom));\r
+ if (pWndFromParent != NULL)\r
+ lr = pWndFromParent->OnNotifyReflect(wParam, lParam);\r
+ }\r
+ }\r
+\r
+ // Handle user notifications\r
+ if (!lr) lr = OnNotify(wParam, lParam);\r
+ if (lr) return lr;\r
+ }\r
+ break;\r
+\r
+ case WM_PAINT:\r
+ {\r
+ // Subclassed controls expect to do their own painting.\r
+ // CustomDraw or OwnerDraw are normally used to modify the drawing of controls.\r
+ if (m_PrevWindowProc) break;\r
+\r
+ if (::GetUpdateRect(m_hWnd, NULL, FALSE))\r
+ {\r
+ CPaintDC dc(this);\r
+ OnDraw(&dc);\r
+ }\r
+ else\r
+ // RedrawWindow can require repainting without an update rect\r
+ {\r
+ CClientDC dc(this);\r
+ OnDraw(&dc);\r
+ }\r
+ }\r
+ return 0L;\r
+\r
+ case WM_ERASEBKGND:\r
+ {\r
+ CDC dc((HDC)wParam);\r
+ BOOL bResult = OnEraseBkgnd(&dc);\r
+ dc.Detach();\r
+ if (bResult) return TRUE;\r
+ }\r
+ break;\r
+\r
+ // A set of messages to be reflected back to the control that generated them\r
+ case WM_CTLCOLORBTN:\r
+ case WM_CTLCOLOREDIT:\r
+ case WM_CTLCOLORDLG:\r
+ case WM_CTLCOLORLISTBOX:\r
+ case WM_CTLCOLORSCROLLBAR:\r
+ case WM_CTLCOLORSTATIC:\r
+ case WM_DRAWITEM:\r
+ case WM_MEASUREITEM:\r
+ case WM_DELETEITEM:\r
+ case WM_COMPAREITEM:\r
+ case WM_CHARTOITEM:\r
+ case WM_VKEYTOITEM:\r
+ case WM_HSCROLL:\r
+ case WM_VSCROLL:\r
+ case WM_PARENTNOTIFY:\r
+ {\r
+ // if (m_PrevWindowProc) break; // Suppress for subclassed windows\r
+\r
+ LRESULT lr = MessageReflect(m_hWnd, uMsg, wParam, lParam);\r
+ if (lr) return lr; // Message processed so return\r
+ }\r
+ break; // Do default processing when message not already processed\r
+\r
+ case UWM_UPDATE_COMMAND:\r
+ OnMenuUpdate((UINT)wParam); // Perform menu updates\r
+ break;\r
+\r
+ } // switch (uMsg)\r
+\r
+ // Now hand all messages to the default procedure\r
+ if (m_PrevWindowProc)\r
+ return ::CallWindowProc(m_PrevWindowProc, m_hWnd, uMsg, wParam, lParam);\r
+ else\r
+ return FinalWindowProc(uMsg, wParam, lParam);\r
+\r
+ } // LRESULT CWnd::WindowProc(...)\r
+\r
+\r
+ //\r
+ // Wrappers for Win32 API functions\r
+ //\r
+\r
+ inline CDC* CWnd::BeginPaint(PAINTSTRUCT& ps) const\r
+ // The BeginPaint function prepares the specified window for painting and fills a PAINTSTRUCT structure with\r
+ // information about the painting.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle(::BeginPaint(m_hWnd, &ps));\r
+ }\r
+\r
+ inline BOOL CWnd::BringWindowToTop() const\r
+ // The BringWindowToTop function brings the specified window to the top\r
+ // of the Z order. If the window is a top-level window, it is activated.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::BringWindowToTop(m_hWnd);\r
+ }\r
+\r
+ inline LRESULT CWnd::CallWindowProc(WNDPROC lpPrevWndFunc, UINT Msg, WPARAM wParam, LPARAM lParam) const\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::CallWindowProc(lpPrevWndFunc, m_hWnd, Msg, wParam, lParam);\r
+ }\r
+\r
+ inline BOOL CWnd::CheckDlgButton(int nIDButton, UINT uCheck) const\r
+ // The CheckDlgButton function changes the check state of a button control.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::CheckDlgButton(m_hWnd, nIDButton, uCheck);\r
+ }\r
+\r
+ inline BOOL CWnd::CheckRadioButton(int nIDFirstButton, int nIDLastButton, int nIDCheckButton) const\r
+ // The CheckRadioButton function adds a check mark to (checks) a specified radio button in a group\r
+ // and removes a check mark from (clears) all other radio buttons in the group.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::CheckRadioButton(m_hWnd, nIDFirstButton, nIDLastButton, nIDCheckButton);\r
+ }\r
+\r
+ inline CWnd* CWnd::ChildWindowFromPoint(POINT pt) const\r
+ // determines which, if any, of the child windows belonging to a parent window contains\r
+ // the specified point. The search is restricted to immediate child windows.\r
+ // Grandchildren, and deeper descendant windows are not searched.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle(::ChildWindowFromPoint(m_hWnd, pt));\r
+ }\r
+\r
+ inline BOOL CWnd::ClientToScreen(POINT& pt) const\r
+ // The ClientToScreen function converts the client-area coordinates of a specified point to screen coordinates.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::ClientToScreen(m_hWnd, &pt);\r
+ }\r
+\r
+ inline BOOL CWnd::ClientToScreen(RECT& rc) const\r
+ // The ClientToScreen function converts the client-area coordinates of a specified RECT to screen coordinates.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return (BOOL)::MapWindowPoints(m_hWnd, NULL, (LPPOINT)&rc, 2);\r
+ }\r
+\r
+ inline HDWP CWnd::DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const\r
+ // The DeferWindowPos function updates the specified multiple-window \96 position structure for the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::DeferWindowPos(hWinPosInfo, m_hWnd, hWndInsertAfter, x, y, cx, cy, uFlags);\r
+ }\r
+\r
+ inline HDWP CWnd::DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, const RECT& rc, UINT uFlags) const\r
+ // The DeferWindowPos function updates the specified multiple-window \96 position structure for the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::DeferWindowPos(hWinPosInfo, m_hWnd, hWndInsertAfter, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, uFlags);\r
+ }\r
+\r
+ inline LRESULT CWnd::DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) const\r
+ // This function provides default processing for any window messages that an application does not process.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);\r
+ }\r
+\r
+ inline BOOL CWnd::DrawMenuBar() const\r
+ // The DrawMenuBar function redraws the menu bar of the specified window. If the menu bar changes after\r
+ // the system has created the window, this function must be called to draw the changed menu bar.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::DrawMenuBar(m_hWnd);\r
+ }\r
+\r
+ inline BOOL CWnd::EnableWindow(BOOL bEnable /*= TRUE*/) const\r
+ // The EnableWindow function enables or disables mouse and\r
+ // keyboard input to the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::EnableWindow(m_hWnd, bEnable);\r
+ }\r
+\r
+ inline BOOL CWnd::EndPaint(PAINTSTRUCT& ps) const\r
+ // The EndPaint function marks the end of painting in the specified window. This function is required for\r
+ // each call to the BeginPaint function, but only after painting is complete.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::EndPaint(m_hWnd, &ps);\r
+ }\r
+\r
+ inline CWnd* CWnd::GetActiveWindow() const\r
+ // The GetActiveWindow function retrieves a pointer to the active window attached to the calling\r
+ // thread's message queue.\r
+ {\r
+ return FromHandle( ::GetActiveWindow() );\r
+ }\r
+\r
+ inline CWnd* CWnd::GetCapture() const\r
+ // The GetCapture function retrieves a pointer to the window (if any) that has captured the mouse.\r
+ {\r
+ return FromHandle( ::GetCapture() );\r
+ }\r
+\r
+ inline ULONG_PTR CWnd::GetClassLongPtr(int nIndex) const\r
+ // The GetClassLongPtr function retrieves the specified value from the\r
+ // WNDCLASSEX structure associated with the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::GetClassLongPtr(m_hWnd, nIndex);\r
+ }\r
+\r
+ inline CRect CWnd::GetClientRect() const\r
+ // The GetClientRect function retrieves the coordinates of a window's client area.\r
+ // The client coordinates specify the upper-left and lower-right corners of the\r
+ // client area. Because client coordinates are relative to the upper-left corner\r
+ // of a window's client area, the coordinates of the upper-left corner are (0,0).\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ CRect rc;\r
+ ::GetClientRect(m_hWnd, &rc);\r
+ return rc;\r
+ }\r
+\r
+ inline CDC* CWnd::GetDC() const\r
+ // The GetDC function retrieves a handle to a display device context (DC) for the\r
+ // client area of the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return CDC::AddTempHDC(::GetDC(m_hWnd), m_hWnd);\r
+ }\r
+\r
+ inline CDC* CWnd::GetDCEx(HRGN hrgnClip, DWORD flags) const\r
+ // The GetDCEx function retrieves a handle to a display device context (DC) for the\r
+ // client area or entire area of a window\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return CDC::AddTempHDC(::GetDCEx(m_hWnd, hrgnClip, flags), m_hWnd);\r
+ }\r
+\r
+ inline CWnd* CWnd::GetDesktopWindow() const\r
+ // The GetDesktopWindow function retrieves a pointer to the desktop window.\r
+ {\r
+ return FromHandle( ::GetDesktopWindow() );\r
+ }\r
+\r
+ inline CWnd* CWnd::GetDlgItem(int nIDDlgItem) const\r
+ // The GetDlgItem function retrieves a handle to a control in the dialog box.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle( ::GetDlgItem(m_hWnd, nIDDlgItem) );\r
+ }\r
+\r
+ inline UINT CWnd::GetDlgItemInt(int nIDDlgItem, BOOL* lpTranslated, BOOL bSigned) const\r
+ // The GetDlgItemInt function translates the text of a specified control in a dialog box into an integer value.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::GetDlgItemInt(m_hWnd, nIDDlgItem, lpTranslated, bSigned);\r
+ }\r
+\r
+ inline CWnd* CWnd::GetFocus() const\r
+ // The GetFocus function retrieves a pointer to the window that has the keyboard focus, if the window\r
+ // is attached to the calling thread's message queue.\r
+ {\r
+ return FromHandle( ::GetFocus() );\r
+ }\r
+\r
+ inline CFont* CWnd::GetFont() const\r
+ // Retrieves the font with which the window is currently drawing its text.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle((HFONT)SendMessage(WM_GETFONT, 0, 0));\r
+ }\r
+\r
+ inline HICON CWnd::GetIcon(BOOL bBigIcon) const\r
+ // Retrieves a handle to the large or small icon associated with a window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return (HICON)SendMessage(WM_GETICON, (WPARAM)bBigIcon, 0);\r
+ }\r
+\r
+ inline CWnd* CWnd::GetNextDlgGroupItem(CWnd* pCtl, BOOL bPrevious) const\r
+ // The GetNextDlgGroupItem function retrieves a pointer to the first control in a group of controls that\r
+ // precedes (or follows) the specified control in a dialog box.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(pCtl);\r
+ return FromHandle(::GetNextDlgGroupItem(m_hWnd, pCtl->GetHwnd(), bPrevious));\r
+ }\r
+\r
+ inline CWnd* CWnd::GetNextDlgTabItem(CWnd* pCtl, BOOL bPrevious) const\r
+ // The GetNextDlgTabItem function retrieves a pointer to the first control that has the WS_TABSTOP style\r
+ // that precedes (or follows) the specified control.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(pCtl);\r
+ return FromHandle(::GetNextDlgTabItem(m_hWnd, pCtl->GetHwnd(), bPrevious));\r
+ }\r
+\r
+ inline CWnd* CWnd::GetParent() const\r
+ // The GetParent function retrieves a pointer to the specified window's parent or owner.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle( ::GetParent(m_hWnd) );\r
+ }\r
+\r
+ inline LONG_PTR CWnd::GetWindowLongPtr(int nIndex) const\r
+ // The GetWindowLongPtr function retrieves information about the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::GetWindowLongPtr(m_hWnd, nIndex);\r
+ }\r
+\r
+ inline BOOL CWnd::GetScrollInfo(int fnBar, SCROLLINFO& si) const\r
+ // The GetScrollInfo function retrieves the parameters of a scroll bar, including\r
+ // the minimum and maximum scrolling positions, the page size, and the position\r
+ // of the scroll box (thumb).\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::GetScrollInfo(m_hWnd, fnBar, &si);\r
+ }\r
+\r
+ inline CRect CWnd::GetUpdateRect(BOOL bErase) const\r
+ // The GetUpdateRect function retrieves the coordinates of the smallest rectangle that completely\r
+ // encloses the update region of the specified window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ CRect rc;\r
+ ::GetUpdateRect(m_hWnd, &rc, bErase);\r
+ return rc;\r
+ }\r
+\r
+ inline int CWnd::GetUpdateRgn(CRgn* pRgn, BOOL bErase) const\r
+ // The GetUpdateRgn function retrieves the update region of a window by copying it into the specified region.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(pRgn);\r
+ HRGN hRgn = (HRGN)pRgn->GetHandle();\r
+ return ::GetUpdateRgn(m_hWnd, hRgn, bErase);\r
+ }\r
+\r
+ inline CWnd* CWnd::GetWindow(UINT uCmd) const\r
+ // The GetWindow function retrieves a pointer to a window that has the specified\r
+ // relationship (Z-Order or owner) to the specified window.\r
+ // Possible uCmd values: GW_CHILD, GW_ENABLEDPOPUP, GW_HWNDFIRST, GW_HWNDLAST,\r
+ // GW_HWNDNEXT, GW_HWNDPREV, GW_OWNER\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle( ::GetWindow(m_hWnd, uCmd) );\r
+ }\r
+\r
+ inline CDC* CWnd::GetWindowDC() const\r
+ // The GetWindowDC function retrieves the device context (DC) for the entire\r
+ // window, including title bar, menus, and scroll bars.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return CDC::AddTempHDC(::GetWindowDC(m_hWnd), m_hWnd);\r
+ }\r
+\r
+ inline CRect CWnd::GetWindowRect() const\r
+ // retrieves the dimensions of the bounding rectangle of the window.\r
+ // The dimensions are given in screen coordinates that are relative to the\r
+ // upper-left corner of the screen.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ CRect rc;\r
+ ::GetWindowRect(m_hWnd, &rc);\r
+ return rc;\r
+ }\r
+\r
+ inline int CWnd::GetWindowTextLength() const\r
+ // The GetWindowTextLength function retrieves the length, in characters, of the specified window's\r
+ // title bar text (if the window has a title bar).\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::GetWindowTextLength(m_hWnd);\r
+ }\r
+\r
+ inline void CWnd::Invalidate(BOOL bErase /*= TRUE*/) const\r
+ // The Invalidate function adds the entire client area the window's update region.\r
+ // The update region represents the portion of the window's client area that must be redrawn.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ ::InvalidateRect(m_hWnd, NULL, bErase);\r
+ }\r
+\r
+ inline BOOL CWnd::InvalidateRect(LPCRECT lpRect, BOOL bErase /*= TRUE*/) const\r
+ // The InvalidateRect function adds a rectangle to the window's update region.\r
+ // The update region represents the portion of the window's client area that must be redrawn.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::InvalidateRect(m_hWnd, lpRect, bErase);\r
+ }\r
+\r
+ inline BOOL CWnd::InvalidateRgn(CRgn* pRgn, BOOL bErase /*= TRUE*/) const\r
+ // The InvalidateRgn function invalidates the client area within the specified region\r
+ // by adding it to the current update region of a window. The invalidated region,\r
+ // along with all other areas in the update region, is marked for painting when the\r
+ // next WM_PAINT message occurs.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;\r
+ return ::InvalidateRgn(m_hWnd, hRgn, bErase);\r
+ }\r
+\r
+ inline BOOL CWnd::IsChild(CWnd* pChild) const\r
+ // The IsChild function tests whether a window is a child window or descendant window\r
+ // of a parent window's CWnd.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::IsChild(m_hWnd, pChild->GetHwnd());\r
+ }\r
+\r
+ inline BOOL CWnd::IsDialogMessage(LPMSG lpMsg) const\r
+ // The IsDialogMessage function determines whether a message is intended for the specified dialog box and,\r
+ // if it is, processes the message.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::IsDialogMessage(m_hWnd, lpMsg);\r
+ }\r
+\r
+ inline UINT CWnd::IsDlgButtonChecked(int nIDButton) const\r
+ // The IsDlgButtonChecked function determines whether a button control has a check mark next to it\r
+ // or whether a three-state button control is grayed, checked, or neither.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::IsDlgButtonChecked(m_hWnd, nIDButton);\r
+ }\r
+\r
+ inline BOOL CWnd::IsWindowEnabled() const\r
+ // The IsWindowEnabled function determines whether the window is enabled\r
+ // for mouse and keyboard input.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::IsWindowEnabled(m_hWnd);\r
+ }\r
+\r
+ inline BOOL CWnd::IsWindowVisible() const\r
+ // The IsWindowVisible function retrieves the visibility state of the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::IsWindowVisible(m_hWnd);\r
+ }\r
+\r
+ inline BOOL CWnd::IsWindow() const\r
+ // The IsWindow function determines whether the window exists.\r
+ {\r
+ return ::IsWindow(m_hWnd);\r
+ }\r
+\r
+ inline void CWnd::MapWindowPoints(CWnd* pWndTo, POINT& pt) const\r
+ // The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one\r
+ // window to a coordinate space relative to another window.\r
+ {\r
+ assert (m_hWnd);\r
+ if(pWndTo)\r
+ {\r
+ assert (pWndTo->GetHwnd());\r
+ ::MapWindowPoints(m_hWnd, pWndTo->GetHwnd(), &pt, 1);\r
+ }\r
+ else\r
+ ::MapWindowPoints(m_hWnd, NULL, &pt, 1);\r
+ }\r
+\r
+ inline void CWnd::MapWindowPoints(CWnd* pWndTo, RECT& rc) const\r
+ // The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one\r
+ // window to a coordinate space relative to another window.\r
+ {\r
+ assert (m_hWnd);\r
+ if(pWndTo)\r
+ {\r
+ assert (pWndTo->GetHwnd());\r
+ ::MapWindowPoints(m_hWnd, pWndTo->GetHwnd(), (LPPOINT)&rc, 2);\r
+ }\r
+ else\r
+ ::MapWindowPoints(m_hWnd, NULL, (LPPOINT)&rc, 2);\r
+ }\r
+\r
+ inline void CWnd::MapWindowPoints(CWnd* pWndTo, LPPOINT ptArray, UINT nCount) const\r
+ // The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one\r
+ // window to a coordinate space relative to another window.\r
+ {\r
+ assert (m_hWnd);\r
+ if (pWndTo)\r
+ {\r
+ assert (pWndTo->GetHwnd());\r
+ ::MapWindowPoints(m_hWnd, pWndTo->GetHwnd(), (LPPOINT)ptArray, nCount);\r
+ }\r
+ else\r
+ ::MapWindowPoints(m_hWnd, NULL, (LPPOINT)ptArray, nCount);\r
+ }\r
+\r
+ inline int CWnd::MessageBox(LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) const\r
+ // The MessageBox function creates, displays, and operates a message box.\r
+ // Possible combinations of uType values include: MB_OK, MB_HELP, MB_OKCANCEL, MB_RETRYCANCEL,\r
+ // MB_YESNO, MB_YESNOCANCEL, MB_ICONEXCLAMATION, MB_ICONWARNING, MB_ICONERROR (+ many others).\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::MessageBox(m_hWnd, lpText, lpCaption, uType);\r
+ }\r
+\r
+ inline BOOL CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint /* = TRUE*/) const\r
+ // The MoveWindow function changes the position and dimensions of the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint = TRUE);\r
+ }\r
+\r
+ inline BOOL CWnd::MoveWindow(const RECT& rc, BOOL bRepaint /* = TRUE*/) const\r
+ // The MoveWindow function changes the position and dimensions of the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::MoveWindow(m_hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, bRepaint);\r
+ }\r
+\r
+ inline BOOL CWnd::PostMessage(UINT uMsg, WPARAM wParam /*= 0L*/, LPARAM lParam /*= 0L*/) const\r
+ // The PostMessage function places (posts) a message in the message queue\r
+ // associated with the thread that created the window and returns without\r
+ // waiting for the thread to process the message.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::PostMessage(m_hWnd, uMsg, wParam, lParam);\r
+ }\r
+\r
+ inline BOOL CWnd::PostMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const\r
+ // Required by by some macros\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::PostMessage(hWnd, uMsg, wParam, lParam);\r
+ }\r
+\r
+ inline BOOL CWnd::RedrawWindow(LPCRECT lpRectUpdate, CRgn* pRgn, UINT flags) const\r
+ // The RedrawWindow function updates the specified rectangle or region in a window's client area.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;\r
+ return ::RedrawWindow(m_hWnd, lpRectUpdate, hRgn, flags);\r
+ }\r
+\r
+ inline int CWnd::ReleaseDC(CDC* pDC) const\r
+ // The ReleaseDC function releases a device context (DC), freeing it for use\r
+ // by other applications.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(pDC);\r
+ return ::ReleaseDC(m_hWnd, pDC->GetHDC());\r
+ }\r
+\r
+ inline BOOL CWnd::ScreenToClient(POINT& Point) const\r
+ // The ScreenToClient function converts the screen coordinates of a specified point on the screen to client-area coordinates.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::ScreenToClient(m_hWnd, &Point);\r
+ }\r
+\r
+ inline BOOL CWnd::ScreenToClient(RECT& rc) const\r
+ // The ScreenToClient function converts the screen coordinates of a specified RECT on the screen to client-area coordinates.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return (BOOL)::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rc, 2);\r
+ }\r
+\r
+ inline LRESULT CWnd::SendDlgItemMessage(int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam) const\r
+ // The SendDlgItemMessage function sends a message to the specified control in a dialog box.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SendDlgItemMessage(m_hWnd, nIDDlgItem, Msg, wParam, lParam);\r
+ }\r
+\r
+ inline LRESULT CWnd::SendMessage(UINT uMsg, WPARAM wParam /*= 0L*/, LPARAM lParam /*= 0L*/) const\r
+ // The SendMessage function sends the specified message to a window or windows.\r
+ // It calls the window procedure for the window and does not return until the\r
+ // window procedure has processed the message.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SendMessage(m_hWnd, uMsg, wParam, lParam);\r
+ }\r
+\r
+ inline LRESULT CWnd::SendMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const\r
+ // Required by by some macros\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SendMessage(hWnd, uMsg, wParam, lParam);\r
+ }\r
+\r
+ inline BOOL CWnd::SendNotifyMessage(UINT Msg, WPARAM wParam, LPARAM lParam) const\r
+ // The SendNotifyMessage function sends the specified message to a window or windows. If the window was created by the\r
+ // calling thread, SendNotifyMessage calls the window procedure for the window and does not return until the window procedure\r
+ // has processed the message. If the window was created by a different thread, SendNotifyMessage passes the message to the\r
+ // window procedure and returns immediately; it does not wait for the window procedure to finish processing the message.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SendNotifyMessage(m_hWnd, Msg, wParam, lParam);\r
+ }\r
+\r
+ inline CWnd* CWnd::SetActiveWindow() const\r
+ // The SetActiveWindow function activates the window, but\r
+ // not if the application is in the background.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle( ::SetActiveWindow(m_hWnd) );\r
+ }\r
+\r
+ inline CWnd* CWnd::SetCapture() const\r
+ // The SetCapture function sets the mouse capture to the window.\r
+ // SetCapture captures mouse input either when the mouse is over the capturing\r
+ // window, or when the mouse button was pressed while the mouse was over the\r
+ // capturing window and the button is still down.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle( ::SetCapture(m_hWnd) );\r
+ }\r
+\r
+ inline ULONG_PTR CWnd::SetClassLongPtr(int nIndex, LONG_PTR dwNewLong) const\r
+ // The SetClassLongPtr function replaces the specified value at the specified offset in the\r
+ // extra class memory or the WNDCLASSEX structure for the class to which the window belongs.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetClassLongPtr(m_hWnd, nIndex, dwNewLong);\r
+ }\r
+\r
+ inline CWnd* CWnd::SetFocus() const\r
+ // The SetFocus function sets the keyboard focus to the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle( ::SetFocus(m_hWnd) );\r
+ }\r
+\r
+ inline void CWnd::SetFont(CFont* pFont, BOOL bRedraw /* = TRUE*/) const\r
+ // Specifies the font that the window will use when drawing text.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(pFont);\r
+ SendMessage(WM_SETFONT, (WPARAM)pFont->GetHandle(), (LPARAM)bRedraw);\r
+ }\r
+\r
+ inline HICON CWnd::SetIcon(HICON hIcon, BOOL bBigIcon) const\r
+ // Associates a new large or small icon with a window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return (HICON)SendMessage(WM_SETICON, (WPARAM)bBigIcon, (LPARAM)hIcon);\r
+ }\r
+\r
+ inline BOOL CWnd::SetForegroundWindow() const\r
+ // The SetForegroundWindow function puts the thread that created the window into the\r
+ // foreground and activates the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetForegroundWindow(m_hWnd);\r
+ }\r
+\r
+ inline CWnd* CWnd::SetParent(CWnd* pWndParent) const\r
+ // The SetParent function changes the parent window of the child window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ if (pWndParent)\r
+ {\r
+ HWND hParent = pWndParent->GetHwnd();\r
+ return FromHandle(::SetParent(m_hWnd, hParent));\r
+ }\r
+ else\r
+ return FromHandle(::SetParent(m_hWnd, 0));\r
+ }\r
+\r
+ inline BOOL CWnd::SetRedraw(BOOL bRedraw /*= TRUE*/) const\r
+ // This function allows changes in that window to be redrawn or prevents changes\r
+ // in that window from being redrawn.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return (BOOL)::SendMessage(m_hWnd, WM_SETREDRAW, (WPARAM)bRedraw, 0L);\r
+ }\r
+\r
+ inline LONG_PTR CWnd::SetWindowLongPtr(int nIndex, LONG_PTR dwNewLong) const\r
+ // The SetWindowLongPtr function changes an attribute of the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetWindowLongPtr(m_hWnd, nIndex, dwNewLong);\r
+ }\r
+\r
+ inline BOOL CWnd::SetWindowPos(const CWnd* pInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const\r
+ // The SetWindowPos function changes the size, position, and Z order of a child, pop-up,\r
+ // or top-level window.\r
+ // The pInsertAfter can one of: &wndTop, &wndTopMost, &wndBottom, or &wndNoTopMost\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ HWND hWndInsertAfter = pInsertAfter? pInsertAfter->GetHwnd() : (HWND)0;\r
+ return ::SetWindowPos(m_hWnd, hWndInsertAfter, x, y, cx, cy, uFlags);\r
+ }\r
+\r
+ inline BOOL CWnd::SetWindowPos(const CWnd* pInsertAfter, const RECT& rc, UINT uFlags) const\r
+ // The SetWindowPos function changes the size, position, and Z order of a child, pop-up,\r
+ // or top-level window.\r
+ // The SetWindowPos function changes the size, position, and Z order of a child, pop-up,\r
+ // or top-level window.\r
+ // The pInsertAfter can one of: &wndTop, &wndTopMost, &wndBottom, or &wndNoTopMost\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ HWND hWndInsertAfter = pInsertAfter? pInsertAfter->GetHwnd() : (HWND)0;\r
+ return ::SetWindowPos(m_hWnd, hWndInsertAfter, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, uFlags);\r
+ }\r
+\r
+ inline int CWnd::SetWindowRgn(CRgn* pRgn, BOOL bRedraw /*= TRUE*/) const\r
+ // The SetWindowRgn function sets the window region of the window.\r
+ // The window region determines the area within the window where the system permits drawing.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;\r
+ int iResult = ::SetWindowRgn(m_hWnd, hRgn, bRedraw);\r
+ if (iResult && pRgn)\r
+ pRgn->Detach(); // The system owns the region now\r
+ return iResult;\r
+ }\r
+\r
+ inline BOOL CWnd::SetDlgItemInt(int nIDDlgItem, UINT uValue, BOOL bSigned) const\r
+ // The SetDlgItemInt function sets the text of a control in a dialog box to the string representation of a specified integer value.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetDlgItemInt(m_hWnd, nIDDlgItem, uValue, bSigned);\r
+ }\r
+\r
+ inline BOOL CWnd::SetDlgItemText(int nIDDlgItem, LPCTSTR lpString) const\r
+ // The SetDlgItemText function sets the title or text of a control in a dialog box.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetDlgItemText(m_hWnd, nIDDlgItem, lpString);\r
+ }\r
+\r
+ inline UINT_PTR CWnd::SetTimer(UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc) const\r
+ // Creates a timer with the specified time-out value.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetTimer(m_hWnd, nIDEvent, uElapse, lpTimerFunc);\r
+ }\r
+\r
+ inline BOOL CWnd::SetWindowText(LPCTSTR lpString) const\r
+ // The SetWindowText function changes the text of the window's title bar (if it has one).\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetWindowText(m_hWnd, lpString);\r
+ }\r
+\r
+ inline HRESULT CWnd::SetWindowTheme(LPCWSTR pszSubAppName, LPCWSTR pszSubIdList) const\r
+ // Set the XP Theme for a window.\r
+ // Exampes:\r
+ // SetWindowTheme(NULL, NULL); // Reverts the window's XP theme back to default\r
+ // SetWindowTheme(L" ", L" "); // Disables XP theme for the window\r
+ {\r
+ HRESULT hr = E_NOTIMPL;\r
+\r
+#ifndef _WIN32_WCE\r
+\r
+ HMODULE hMod = ::LoadLibrary(_T("uxtheme.dll"));\r
+ if(hMod)\r
+ {\r
+ typedef HRESULT (__stdcall *PFNSETWINDOWTHEME)(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);\r
+ PFNSETWINDOWTHEME pfn = (PFNSETWINDOWTHEME)GetProcAddress(hMod, "SetWindowTheme");\r
+\r
+ hr = (*pfn)(m_hWnd, pszSubAppName, pszSubIdList);\r
+\r
+ ::FreeLibrary(hMod);\r
+ }\r
+\r
+#endif\r
+\r
+ return hr;\r
+ }\r
+\r
+ inline BOOL CWnd::ShowWindow(int nCmdShow /*= SW_SHOWNORMAL*/) const\r
+ // The ShowWindow function sets the window's show state.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::ShowWindow(m_hWnd, nCmdShow);\r
+ }\r
+\r
+ inline BOOL CWnd::UpdateWindow() const\r
+ // The UpdateWindow function updates the client area of the window by sending a\r
+ // WM_PAINT message to the window if the window's update region is not empty.\r
+ // If the update region is empty, no message is sent.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::UpdateWindow(m_hWnd);\r
+ }\r
+\r
+ inline BOOL CWnd::ValidateRect(LPCRECT prc) const\r
+ // The ValidateRect function validates the client area within a rectangle by\r
+ // removing the rectangle from the update region of the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::ValidateRect(m_hWnd, prc);\r
+ }\r
+\r
+ inline BOOL CWnd::ValidateRgn(CRgn* pRgn) const\r
+ // The ValidateRgn function validates the client area within a region by\r
+ // removing the region from the current update region of the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ HRGN hRgn = pRgn? (HRGN)pRgn->GetHandle() : NULL;\r
+ return ::ValidateRgn(m_hWnd, hRgn);\r
+ }\r
+\r
+ inline CWnd* CWnd::WindowFromPoint(POINT pt)\r
+ // Retrieves the window that contains the specified point (in screen coodinates).\r
+ {\r
+ return FromHandle(::WindowFromPoint(pt));\r
+ }\r
+\r
+ //\r
+ // These functions aren't supported on WinCE\r
+ //\r
+ #ifndef _WIN32_WCE\r
+ inline BOOL CWnd::CloseWindow() const\r
+ // The CloseWindow function minimizes (but does not destroy) the window.\r
+ // To destroy a window, an application can use the Destroy function.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::CloseWindow(m_hWnd);\r
+ }\r
+\r
+ inline int CWnd::DlgDirList(LPTSTR lpPathSpec, int nIDListBox, int nIDStaticPath, UINT uFileType) const\r
+ // The DlgDirList function replaces the contents of a list box with the names of the subdirectories and files\r
+ // in a specified directory. You can filter the list of names by specifying a set of file attributes.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::DlgDirList(m_hWnd, lpPathSpec, nIDListBox, nIDStaticPath, uFileType);\r
+ }\r
+\r
+ inline int CWnd::DlgDirListComboBox(LPTSTR lpPathSpec, int nIDComboBox, int nIDStaticPath, UINT uFiletype) const\r
+ // The DlgDirListComboBox function replaces the contents of a combo box with the names of the subdirectories\r
+ // and files in a specified directory. You can filter the list of names by specifying a set of file attributes.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::DlgDirListComboBox(m_hWnd, lpPathSpec, nIDComboBox, nIDStaticPath, uFiletype);\r
+ }\r
+\r
+ inline BOOL CWnd::DlgDirSelectEx(LPTSTR lpString, int nCount, int nIDListBox) const\r
+ // The DlgDirSelectEx function retrieves the current selection from a single-selection list box. It assumes that the list box\r
+ // has been filled by the DlgDirList function and that the selection is a drive letter, filename, or directory name.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::DlgDirSelectEx(m_hWnd, lpString, nCount, nIDListBox);\r
+ }\r
+\r
+ inline BOOL CWnd::DlgDirSelectComboBoxEx(LPTSTR lpString, int nCount, int nIDComboBox) const\r
+ // The DlgDirSelectComboBoxEx function retrieves the current selection from a combo box filled by using the\r
+ // DlgDirListComboBox function. The selection is interpreted as a drive letter, a file, or a directory name.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::DlgDirSelectComboBoxEx(m_hWnd, lpString, nCount, nIDComboBox);\r
+ }\r
+\r
+ #ifndef WIN32_LEAN_AND_MEAN\r
+ inline void CWnd::DragAcceptFiles(BOOL fAccept) const\r
+ // Registers whether a window accepts dropped files.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ ::DragAcceptFiles(m_hWnd, fAccept);\r
+ }\r
+ #endif\r
+\r
+ inline BOOL CWnd::DrawAnimatedRects(int idAni, RECT& rcFrom, RECT& rcTo) const\r
+ // The DrawAnimatedRects function draws a wire-frame rectangle and animates it to indicate the opening of\r
+ // an icon or the minimizing or maximizing of a window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::DrawAnimatedRects(m_hWnd, idAni, &rcFrom, &rcTo);\r
+ }\r
+\r
+ inline BOOL CWnd::DrawCaption(CDC* pDC, RECT& rc, UINT uFlags) const\r
+ // The DrawCaption function draws a window caption.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(pDC);\r
+ return ::DrawCaption(m_hWnd, pDC->GetHDC(), &rc, uFlags);\r
+ }\r
+\r
+ inline BOOL CWnd::EnableScrollBar(UINT uSBflags, UINT uArrows) const\r
+ // The EnableScrollBar function enables or disables one or both scroll bar arrows.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::EnableScrollBar(m_hWnd, uSBflags, uArrows);\r
+ }\r
+\r
+ inline CWnd* CWnd::GetLastActivePopup() const\r
+ // The GetLastActivePopup function determines which pop-up window owned by the specified window was most recently active.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle( ::GetLastActivePopup(m_hWnd) );\r
+ }\r
+\r
+ inline CMenu* CWnd::GetMenu() const\r
+ // The GetMenu function retrieves a handle to the menu assigned to the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle(::GetMenu(m_hWnd));\r
+ }\r
+\r
+ inline int CWnd::GetScrollPos(int nBar) const\r
+ // The GetScrollPos function retrieves the current position of the scroll box\r
+ // (thumb) in the specified scroll bar.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::GetScrollPos(m_hWnd, nBar);\r
+ }\r
+\r
+ inline BOOL CWnd::GetScrollRange(int nBar, int& MinPos, int& MaxPos) const\r
+ // The GetScrollRange function retrieves the current minimum and maximum scroll box\r
+ // (thumb) positions for the specified scroll bar.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::GetScrollRange(m_hWnd, nBar, &MinPos, &MaxPos );\r
+ }\r
+\r
+ inline CMenu* CWnd::GetSystemMenu(BOOL bRevert) const\r
+ // The GetSystemMenu function allows the application to access the window menu (also known as the system menu\r
+ // or the control menu) for copying and modifying.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle(::GetSystemMenu(m_hWnd, bRevert));\r
+ }\r
+\r
+ inline CWnd* CWnd::GetTopWindow() const\r
+ // The GetTopWindow function examines the Z order of the child windows associated with the parent window and\r
+ // retrieves a handle to the child window at the top of the Z order.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return FromHandle( ::GetTopWindow(m_hWnd) );\r
+ }\r
+\r
+ inline BOOL CWnd::GetWindowPlacement(WINDOWPLACEMENT& wndpl) const\r
+ // The GetWindowPlacement function retrieves the show state and the restored,\r
+ // minimized, and maximized positions of the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::GetWindowPlacement(m_hWnd, &wndpl);\r
+ }\r
+\r
+ inline BOOL CWnd::HiliteMenuItem(CMenu* pMenu, UINT uItemHilite, UINT uHilite) const\r
+ // The HiliteMenuItem function highlights or removes the highlighting from an item in a menu bar.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(pMenu);\r
+ return ::HiliteMenuItem(m_hWnd, pMenu->GetHandle(), uItemHilite, uHilite);\r
+ }\r
+\r
+ inline BOOL CWnd::IsIconic() const\r
+ // The IsIconic function determines whether the window is minimized (iconic).\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::IsIconic(m_hWnd);\r
+ }\r
+\r
+ inline BOOL CWnd::IsZoomed() const\r
+ // The IsZoomed function determines whether the window is maximized.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::IsZoomed(m_hWnd);\r
+ }\r
+\r
+ inline BOOL CWnd::KillTimer(UINT_PTR uIDEvent) const\r
+ // Destroys the specified timer.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::KillTimer(m_hWnd, uIDEvent);\r
+ }\r
+\r
+ inline BOOL CWnd::LockWindowUpdate() const\r
+ // Disables drawing in the window. Only one window can be locked at a time.\r
+ // Use UnLockWindowUpdate to re-enable drawing in the window\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::LockWindowUpdate(m_hWnd);\r
+ }\r
+\r
+ inline BOOL CWnd::OpenIcon() const\r
+ // The OpenIcon function restores a minimized (iconic) window to its previous size and position.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::OpenIcon(m_hWnd);\r
+ }\r
+\r
+ inline void CWnd::Print(CDC* pDC, DWORD dwFlags) const\r
+ // Requests that the window draw itself in the specified device context, most commonly in a printer device context.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(pDC);\r
+ SendMessage(m_hWnd, WM_PRINT, (WPARAM)pDC, (LPARAM)dwFlags);\r
+ }\r
+\r
+ inline BOOL CWnd::ScrollWindow(int XAmount, int YAmount, LPCRECT lprcScroll, LPCRECT lprcClip) const\r
+ // The ScrollWindow function scrolls the contents of the specified window's client area.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::ScrollWindow(m_hWnd, XAmount, YAmount, lprcScroll, lprcClip);\r
+ }\r
+\r
+ inline int CWnd::ScrollWindowEx(int dx, int dy, LPCRECT lprcScroll, LPCRECT lprcClip, CRgn* prgnUpdate, LPRECT lprcUpdate, UINT flags) const\r
+ // The ScrollWindow function scrolls the contents of the window's client area.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ HRGN hrgnUpdate = prgnUpdate? (HRGN)prgnUpdate->GetHandle() : NULL;\r
+ return ::ScrollWindowEx(m_hWnd, dx, dy, lprcScroll, lprcClip, hrgnUpdate, lprcUpdate, flags);\r
+ }\r
+\r
+ inline BOOL CWnd::SetMenu(CMenu* pMenu) const\r
+ // The SetMenu function assigns a menu to the specified window.\r
+ // A hMenu of NULL removes the menu.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetMenu(m_hWnd, pMenu? pMenu->GetHandle() : NULL);\r
+ }\r
+\r
+ inline int CWnd::SetScrollInfo(int fnBar, const SCROLLINFO& si, BOOL fRedraw) const\r
+ // The SetScrollInfo function sets the parameters of a scroll bar, including\r
+ // the minimum and maximum scrolling positions, the page size, and the\r
+ // position of the scroll box (thumb).\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetScrollInfo(m_hWnd, fnBar, &si, fRedraw);\r
+ }\r
+\r
+ inline int CWnd::SetScrollPos(int nBar, int nPos, BOOL bRedraw) const\r
+ // The SetScrollPos function sets the position of the scroll box (thumb) in\r
+ // the specified scroll bar.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetScrollPos(m_hWnd, nBar, nPos, bRedraw);\r
+ }\r
+\r
+ inline BOOL CWnd::SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw) const\r
+ // The SetScrollRange function sets the minimum and maximum scroll box positions for the scroll bar.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetScrollRange(m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);\r
+ }\r
+\r
+ inline BOOL CWnd::SetWindowPlacement(const WINDOWPLACEMENT& wndpl) const\r
+ // The SetWindowPlacement function sets the show state and the restored, minimized,\r
+ // and maximized positions of the window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::SetWindowPlacement(m_hWnd, &wndpl);\r
+ }\r
+\r
+ inline BOOL CWnd::ShowOwnedPopups(BOOL fShow) const\r
+ // The ShowOwnedPopups function shows or hides all pop-up windows owned by the specified window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::ShowOwnedPopups(m_hWnd, fShow);\r
+ }\r
+\r
+ inline BOOL CWnd::ShowScrollBar(int nBar, BOOL bShow) const\r
+ // The ShowScrollBar function shows or hides the specified scroll bar.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::ShowScrollBar(m_hWnd, nBar, bShow);\r
+ }\r
+\r
+ inline BOOL CWnd::ShowWindowAsync(int nCmdShow) const\r
+ // The ShowWindowAsync function sets the show state of a window created by a different thread.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::ShowWindowAsync(m_hWnd, nCmdShow);\r
+ }\r
+\r
+ inline BOOL CWnd::UnLockWindowUpdate() const\r
+ // Enables drawing in the window. Only one window can be locked at a time.\r
+ // Use LockWindowUpdate to disable drawing in the window\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return ::LockWindowUpdate(0);\r
+ }\r
+\r
+ inline CWnd* CWnd::WindowFromDC(CDC* pDC) const\r
+ // The WindowFromDC function returns a handle to the window associated with the specified display device context (DC).\r
+ {\r
+ assert(pDC);\r
+ return FromHandle( ::WindowFromDC(pDC->GetHDC()) );\r
+ }\r
+\r
+\r
+ #endif\r
+\r
+}; // namespace Win32xx\r
+\r
+\r
+#endif // _WIN32XX_WINCORE_H_\r
+\r