aboutsummaryrefslogtreecommitdiff
path: root/mmc_updater/depends/win32cpp/wincore.h
diff options
context:
space:
mode:
Diffstat (limited to 'mmc_updater/depends/win32cpp/wincore.h')
-rw-r--r--mmc_updater/depends/win32cpp/wincore.h2977
1 files changed, 2977 insertions, 0 deletions
diff --git a/mmc_updater/depends/win32cpp/wincore.h b/mmc_updater/depends/win32cpp/wincore.h
new file mode 100644
index 00000000..d6b1f9b6
--- /dev/null
+++ b/mmc_updater/depends/win32cpp/wincore.h
@@ -0,0 +1,2977 @@
+// Win32++ Version 7.2
+// Released: 5th AUgust 2011
+//
+// David Nash
+// email: dnash@bigpond.net.au
+// url: https://sourceforge.net/projects/win32-framework
+//
+//
+// Copyright (c) 2005-2011 David Nash
+//
+// Permission is hereby granted, free of charge, to
+// any person obtaining a copy of this software and
+// associated documentation files (the "Software"),
+// to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify,
+// merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom
+// the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice
+// shall be included in all copies or substantial portions
+// of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
+// OR OTHER DEALINGS IN THE SOFTWARE.
+//
+////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////
+// wincore.h
+// Declaration of the following classes:
+// CWinApp, CWnd, CWinException, CCriticalSection,
+// CPoint, CRect, and CSize
+//
+// This file contains the declarations for the core set of classes required to
+// create simple windows using Win32++.
+//
+// 1) CCriticalSection: This class is used internally to manage thread access
+// to shared resources. You can also use this class to lock and
+// release your own critical sections.
+//
+// 2) CWinException: This class is used internally by Win32++ to handle
+// exceptions. You can also use it to throw and catch exceptions.
+//
+// 3) WinApp: This class is used start Win32++ and run the message loop. You
+// should inherit from this class to start Win32++ in your own
+// application.
+//
+// 4) CWnd: This class is used to represent a window. It provides a means
+// of creating the window, and handling its messages. Inherit
+// from this class to define and control windows.
+//
+//
+// Note: This header file (or another Win32++ header file which includes it)
+// should be included before all other header files. It sets some
+// important macros which need to be set before including Windows.h
+// Including this file first also allows it to disable some pointless
+// warning messages (see below).
+
+
+
+#ifndef _WIN32XX_WINCORE_H_
+#define _WIN32XX_WINCORE_H_
+
+
+// Remove pointless warning messages
+#ifdef _MSC_VER
+ #pragma warning (disable : 4996) // function or variable may be unsafe (deprecated)
+ #ifndef _CRT_SECURE_NO_WARNINGS
+ #define _CRT_SECURE_NO_WARNINGS // eliminate deprecation warnings for VS2005/VS2010
+ #endif
+ #if _MSC_VER < 1500
+ #pragma warning (disable : 4511) // copy operator could not be generated
+ #pragma warning (disable : 4512) // assignment operator could not be generated
+ #pragma warning (disable : 4702) // unreachable code (bugs in Microsoft's STL)
+ #pragma warning (disable : 4786) // identifier was truncated
+ #endif
+#endif
+
+#ifdef __BORLANDC__
+ #pragma option -w-8019 // code has no effect
+ #pragma option -w-8026 // functions with exception specifiations are not expanded inline
+ #pragma option -w-8027 // function not expanded inline
+ #define STRICT 1
+#endif
+
+#ifdef __GNUC__
+ #pragma GCC diagnostic ignored "-Wmissing-braces"
+ #pragma GCC diagnostic ignored "-Wunused-value"
+#endif
+
+#ifdef _WIN32_WCE
+ #include "wcestddef.h"
+#endif
+
+#define _WINSOCKAPI_ // Prevent winsock.h #include's.
+
+#include <assert.h>
+#include <vector>
+#include <algorithm>
+#include <string>
+#include <map>
+#include <windows.h>
+#include <commctrl.h>
+#include <stdio.h>
+#include <tchar.h>
+#include <shlwapi.h>
+#include "shared_ptr.h"
+//#include "winutils.h" // included later in this file
+//#include "cstring.h" // included later in this file
+//#include "gdi.h" // included later in this file
+//#include "menu.h" // included later in this file
+
+// For compilers lacking Win64 support
+#ifndef GetWindowLongPtr
+ #define GetWindowLongPtr GetWindowLong
+ #define SetWindowLongPtr SetWindowLong
+ #define GWLP_WNDPROC GWL_WNDPROC
+ #define GWLP_HINSTANCE GWL_HINSTANCE
+ #define GWLP_ID GWL_ID
+ #define GWLP_USERDATA GWL_USERDATA
+ #define DWLP_DLGPROC DWL_DLGPROC
+ #define DWLP_MSGRESULT DWL_MSGRESULT
+ #define DWLP_USER DWL_USER
+ #define DWORD_PTR DWORD
+ #define LONG_PTR LONG
+ #define ULONG_PTR LONG
+#endif
+#ifndef GetClassLongPtr
+ #define GetClassLongPtr GetClassLong
+ #define SetClassLongPtr SetClassLong
+ #define GCLP_HBRBACKGROUND GCL_HBRBACKGROUND
+ #define GCLP_HCURSOR GCL_HCURSOR
+ #define GCLP_HICON GCL_HICON
+ #define GCLP_HICONSM GCL_HICONSM
+ #define GCLP_HMODULE GCL_HMODULE
+ #define GCLP_MENUNAME GCL_MENUNAME
+ #define GCLP_WNDPROC GCL_WNDPROC
+#endif
+
+
+// Messages defined by Win32++
+#define UWM_POPUPMENU (WM_APP + 1) // Message - creates the menubar popup menu
+#define UWM_DOCK_START (WM_APP + 2) // Notification - about to start undocking
+#define UWM_DOCK_MOVE (WM_APP + 3) // Notification - undocked docker is being moved
+#define UWM_DOCK_END (WM_APP + 4) // Notification - docker has been docked
+#define UWM_BAR_START (WM_APP + 5) // Notification - docker bar selected for move
+#define UWM_BAR_MOVE (WM_APP + 6) // Notification - docker bar moved
+#define UWM_BAR_END (WM_APP + 7) // Notification - end of docker bar move
+#define UWM_UNDOCKED (WM_APP + 8) // Notification - sent by docker when undocked
+#define UWM_FRAMELOSTFOCUS (WM_APP + 9) // Notification - sent by frame to view window when focus lost
+#define UWM_FRAMEGOTFOCUS (WM_APP + 10) // Notification - sent by frame to view window when focus acquired
+#define UWM_DOCK_DESTROYED (WM_APP + 11) // Message - posted when docker is destroyed
+#define UWM_TAB_CHANGED (WM_APP + 12) // Notification - tab layout changed
+#define UWM_TOOLBAR_RESIZE (WM_APP + 13) // Message - sent by toolbar to parent. Used by the rebar
+#define UWM_UPDATE_COMMAND (WM_APP + 14) // Message - sent before a menu is displayed. Used by OnUpdate
+#define UWM_DOCK_ACTIVATED (WM_APP + 15) // Message - sent to dock ancestor when a docker is activated or deactivated.
+#define UWM_GETMENUTHEME (WM_APP + 16) // Message - returns a pointer to MenuTheme
+#define UWM_GETREBARTHEME (WM_APP + 17) // Message - returns a pointer to CToolBar
+#define UWM_GETTOOLBARTHEME (WM_APP + 18) // Message - returns a pointer to ToolBarTheme
+#define UWM_CLEANUPTEMPS (WM_APP + 19) // Message - posted to cleanup temporary CDCs
+
+
+// Automatically include the Win32xx namespace
+// define NO_USING_NAMESPACE to skip this step
+namespace Win32xx {}
+#ifndef NO_USING_NAMESPACE
+ using namespace Win32xx;
+#endif
+
+// Required for WinCE
+#ifndef TLS_OUT_OF_INDEXES
+ #define TLS_OUT_OF_INDEXES ((DWORD_PTR) -1)
+#endif
+#ifndef WM_PARENTNOTIFY
+ #define WM_PARENTNOTIFY 0x0210
+#endif
+
+
+namespace Win32xx
+{
+
+ ////////////////////////////////////////////////
+ // Forward declarations.
+ // These classes are defined later or elsewhere
+ class CDC;
+ class CGDIObject;
+ class CMenu;
+ class CWinApp;
+ class CWnd;
+ class CBitmap;
+ class CBrush;
+ class CFont;
+ class CPalette;
+ class CPen;
+ class CRgn;
+
+ // tString is a TCHAR std::string
+ typedef std::basic_string<TCHAR> tString;
+
+ // tStringStream is a TCHAR std::stringstream
+ typedef std::basic_stringstream<TCHAR> tStringStream;
+
+ // Some useful smart pointers
+ typedef Shared_Ptr<CDC> DCPtr;
+ typedef Shared_Ptr<CGDIObject> GDIPtr;
+ typedef Shared_Ptr<CMenu> MenuPtr;
+ typedef Shared_Ptr<CWnd> WndPtr;
+ typedef Shared_Ptr<CBitmap> BitmapPtr;
+ typedef Shared_Ptr<CBrush> BrushPtr;
+ typedef Shared_Ptr<CFont> FontPtr;
+ typedef Shared_Ptr<CPalette> PalettePtr;
+ typedef Shared_Ptr<CPen> PenPtr;
+ typedef Shared_Ptr<CRgn> RgnPtr;
+
+ enum Constants // Defines the maximum size for TCHAR strings
+ {
+ MAX_MENU_STRING = 80,
+ MAX_STRING_SIZE = 255,
+ };
+
+ struct CompareHDC // The comparison function object used by CWinApp::m_mapHDC
+ {
+ bool operator()(HDC const a, const HDC b) const
+ {return ((DWORD_PTR)a < (DWORD_PTR)b);}
+ };
+
+ struct CompareGDI // The comparison function object used by CWinApp::m_mapGDI
+ {
+ bool operator()(HGDIOBJ const a, const HGDIOBJ b) const
+ {return ((DWORD_PTR)a < (DWORD_PTR)b);}
+ };
+
+ struct CompareHMENU // The comparison function object used by CWinApp::m_mapHMENU
+ {
+ bool operator()(HMENU const a, const HMENU b) const
+ {return ((DWORD_PTR)a < (DWORD_PTR)b);}
+ };
+
+ struct CompareHWND // The comparison function object used by CWinApp::m_mapHWND
+ {
+ bool operator()(HWND const a, const HWND b) const
+ {return ((DWORD_PTR)a < (DWORD_PTR)b);}
+ };
+
+ struct TLSData // Used for Thread Local Storage (TLS)
+ {
+ CWnd* pCWnd; // pointer to CWnd object for Window creation
+ CWnd* pMenuBar; // pointer to CMenuBar object used for the WH_MSGFILTER hook
+ HHOOK hHook; // WH_MSGFILTER hook for CMenuBar and Modeless Dialogs
+
+ std::vector<DCPtr> vTmpDCs; // A vector of temporary CDC pointers
+ std::vector<GDIPtr> vTmpGDIs; // A vector of temporary CGDIObject pointers
+ std::vector<WndPtr> vTmpWnds; // A vector of temporary CWnd pointers
+ TLSData() : pCWnd(0), pMenuBar(0), hHook(0) {}
+
+#ifndef _WIN32_WCE
+ std::vector<MenuPtr> vTmpMenus; // A vector of temporary CMenu pointers
+#endif
+ };
+
+
+ /////////////////////////////////////////
+ // Declarations for the CCriticalSection class
+ // This class is used for thread synchronisation
+ class CCriticalSection
+ {
+ public:
+ CCriticalSection() { ::InitializeCriticalSection(&m_cs); }
+ ~CCriticalSection() { ::DeleteCriticalSection(&m_cs); }
+
+ void Lock() { ::EnterCriticalSection(&m_cs); }
+ void Release() { ::LeaveCriticalSection(&m_cs); }
+
+ private:
+ CCriticalSection ( const CCriticalSection& );
+ CCriticalSection& operator = ( const CCriticalSection& );
+
+ CRITICAL_SECTION m_cs;
+ };
+
+
+ ////////////////////////////////////////
+ // Declaration of the CWinException class
+ //
+ // Note: Each function guarantees not to throw an exception
+
+ class CWinException : public std::exception
+ {
+ public:
+ CWinException(LPCTSTR pszText) throw ();
+ ~CWinException() throw() {}
+ DWORD GetError() const throw ();
+ LPCTSTR GetErrorString() const throw ();
+ const char * what () const throw ();
+
+ private:
+ DWORD m_Error;
+ LPCTSTR m_pszText;
+ TCHAR m_szErrorString[MAX_STRING_SIZE];
+ };
+
+
+ ///////////////////////////////////
+ // Declaration of the CWinApp class
+ //
+ class CWinApp
+ {
+ // Provide these access to CWinApp's private members:
+ friend class CDC;
+ friend class CDialog;
+ friend class CGDIObject;
+ friend class CMenu;
+ friend class CMenuBar;
+ friend class CPropertyPage;
+ friend class CPropertySheet;
+ friend class CTaskDialog;
+ friend class CWnd;
+ friend CWinApp* GetApp();
+ friend CGDIObject* FromHandle(HGDIOBJ hObject);
+ friend CBitmap* FromHandle(HBITMAP hBitmap);
+ friend CBrush* FromHandle(HBRUSH hBrush);
+ friend CFont* FromHandle(HFONT hFont);
+ friend CPalette* FromHandle(HPALETTE hPalette);
+ friend CPen* FromHandle(HPEN hPen);
+ friend CRgn* FromHandle(HRGN hRgn);
+ friend CDC* FromHandle(HDC hDC);
+ friend CWnd* FromHandle(HWND hWnd);
+#ifndef _WIN32_WCE
+ friend CMenu* FromHandle(HMENU hMenu);
+#endif
+
+ typedef Shared_Ptr<TLSData> TLSDataPtr;
+
+ public:
+ CWinApp();
+ virtual ~CWinApp();
+
+ HACCEL GetAccelerators() const { return m_hAccel; }
+ HINSTANCE GetInstanceHandle() const { return m_hInstance; }
+ HINSTANCE GetResourceHandle() const { return (m_hResource ? m_hResource : m_hInstance); }
+ void SetAccelerators(HACCEL hAccel, CWnd* pWndAccel);
+ void SetResourceHandle(HINSTANCE hResource);
+
+ // These are the functions you might wish to override
+ virtual BOOL InitInstance();
+ virtual int MessageLoop();
+ virtual int Run();
+
+ protected:
+ virtual BOOL OnIdle(LONG lCount);
+ virtual BOOL PreTranslateMessage(MSG Msg);
+
+ private:
+ CWinApp(const CWinApp&); // Disable copy construction
+ CWinApp& operator = (const CWinApp&); // Disable assignment operator
+ CDC* GetCDCFromMap(HDC hDC);
+ CGDIObject* GetCGDIObjectFromMap(HGDIOBJ hObject);
+ CMenu* GetCMenuFromMap(HMENU hMenu);
+ CWnd* GetCWndFromMap(HWND hWnd);
+
+ void AddTmpDC(CDC* pDC);
+ void AddTmpGDI(CGDIObject* pObject);
+ CMenu* AddTmpMenu(HMENU hMenu);
+ CWnd* AddTmpWnd(HWND hWnd);
+ void CleanupTemps();
+ DWORD GetTlsIndex() const {return m_dwTlsIndex;}
+ void SetCallback();
+ TLSData* SetTlsIndex();
+ static CWinApp* SetnGetThis(CWinApp* pThis = 0);
+
+ std::map<HDC, CDC*, CompareHDC> m_mapHDC; // maps device context handles to CDC objects
+ std::map<HGDIOBJ, CGDIObject*, CompareGDI> m_mapGDI; // maps GDI handles to CGDIObjects.
+ std::map<HMENU, CMenu*, CompareHMENU> m_mapHMENU; // maps menu handles to CMenu objects
+ std::map<HWND, CWnd*, CompareHWND> m_mapHWND; // maps window handles to CWnd objects
+ std::vector<TLSDataPtr> m_vTLSData; // vector of TLSData smart pointers, one for each thread
+ CCriticalSection m_csMapLock; // thread synchronisation for m_mapHWND
+ CCriticalSection m_csTLSLock; // thread synchronisation for m_vTLSData
+ CCriticalSection m_csAppStart; // thread synchronisation for application startup
+ HINSTANCE m_hInstance; // handle to the applications instance
+ HINSTANCE m_hResource; // handle to the applications resources
+ DWORD m_dwTlsIndex; // Thread Local Storage index
+ WNDPROC m_Callback; // callback address of CWnd::StaticWndowProc
+ HACCEL m_hAccel; // handle to the accelerator table
+ CWnd* m_pWndAccel; // handle to the window for accelerator keys
+
+ };
+
+}
+
+#include "winutils.h"
+#include "cstring.h"
+
+
+namespace Win32xx
+{
+ ////////////////////////////////
+ // Declaration of the CWnd class
+ //
+ class CWnd
+ {
+ friend class CMDIChild;
+ friend class CDialog;
+ friend class CPropertyPage;
+ friend class CTaskDialog;
+ friend class CWinApp;
+
+ public:
+ CWnd(); // Constructor
+ virtual ~CWnd(); // Destructor
+
+ // These virtual functions can be overridden
+ virtual BOOL Attach(HWND hWnd);
+ virtual BOOL AttachDlgItem(UINT nID, CWnd* pParent);
+ virtual void CenterWindow() const;
+ virtual HWND Create(CWnd* pParent = NULL);
+ 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);
+ virtual HWND CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rc, CWnd* pParent, CMenu* pMenu, LPVOID lpParam = NULL);
+ virtual void Destroy();
+ virtual HWND Detach();
+ virtual HICON SetIconLarge(int nIcon);
+ virtual HICON SetIconSmall(int nIcon);
+
+ // Attributes
+ HWND GetHwnd() const { return m_hWnd; }
+ WNDPROC GetPrevWindowProc() const { return m_PrevWindowProc; }
+
+ // Wrappers for Win32 API functions
+ // These functions aren't virtual, and shouldn't be overridden
+ CDC* BeginPaint(PAINTSTRUCT& ps) const;
+ BOOL BringWindowToTop() const;
+ LRESULT CallWindowProc(WNDPROC lpPrevWndFunc, UINT Msg, WPARAM wParam, LPARAM lParam) const;
+ BOOL CheckDlgButton(int nIDButton, UINT uCheck) const;
+ BOOL CheckRadioButton(int nIDFirstButton, int nIDLastButton, int nIDCheckButton) const;
+ CWnd* ChildWindowFromPoint(POINT pt) const;
+ BOOL ClientToScreen(POINT& pt) const;
+ BOOL ClientToScreen(RECT& rc) const;
+ LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) const;
+ HDWP DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const;
+ HDWP DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, const RECT& rc, UINT uFlags) const;
+ BOOL DrawMenuBar() const;
+ BOOL EnableWindow(BOOL bEnable = TRUE) const;
+ BOOL EndPaint(PAINTSTRUCT& ps) const;
+ CWnd* GetActiveWindow() const;
+ CWnd* GetAncestor(UINT gaFlag = 3 /*= GA_ROOTOWNER*/) const;
+ CWnd* GetCapture() const;
+ ULONG_PTR GetClassLongPtr(int nIndex) const;
+ CString GetClassName() const;
+ CRect GetClientRect() const;
+ CDC* GetDC() const;
+ CDC* GetDCEx(HRGN hrgnClip, DWORD flags) const;
+ CWnd* GetDesktopWindow() const;
+ CWnd* GetDlgItem(int nIDDlgItem) const;
+ UINT GetDlgItemInt(int nIDDlgItem, BOOL* lpTranslated, BOOL bSigned) const;
+ CString GetDlgItemText(int nIDDlgItem) const;
+ CWnd* GetFocus() const;
+ CFont* GetFont() const;
+ HICON GetIcon(BOOL bBigIcon) const;
+ CWnd* GetNextDlgGroupItem(CWnd* pCtl, BOOL bPrevious) const;
+ CWnd* GetNextDlgTabItem(CWnd* pCtl, BOOL bPrevious) const;
+ CWnd* GetParent() const;
+ BOOL GetScrollInfo(int fnBar, SCROLLINFO& si) const;
+ CRect GetUpdateRect(BOOL bErase) const;
+ int GetUpdateRgn(CRgn* pRgn, BOOL bErase) const;
+ CWnd* GetWindow(UINT uCmd) const;
+ CDC* GetWindowDC() const;
+ LONG_PTR GetWindowLongPtr(int nIndex) const;
+ CRect GetWindowRect() const;
+ CString GetWindowText() const;
+ int GetWindowTextLength() const;
+ void Invalidate(BOOL bErase = TRUE) const;
+ BOOL InvalidateRect(LPCRECT lpRect, BOOL bErase = TRUE) const;
+ BOOL InvalidateRgn(CRgn* pRgn, BOOL bErase = TRUE) const;
+ BOOL IsChild(CWnd* pChild) const;
+ BOOL IsDialogMessage(LPMSG lpMsg) const;
+ UINT IsDlgButtonChecked(int nIDButton) const;
+ BOOL IsWindow() const;
+ BOOL IsWindowEnabled() const;
+ BOOL IsWindowVisible() const;
+ BOOL KillTimer(UINT_PTR uIDEvent) const;
+ int MessageBox(LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) const;
+ void MapWindowPoints(CWnd* pWndTo, POINT& pt) const;
+ void MapWindowPoints(CWnd* pWndTo, RECT& rc) const;
+ void MapWindowPoints(CWnd* pWndTo, LPPOINT ptArray, UINT nCount) const;
+ BOOL MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE) const;
+ BOOL MoveWindow(const RECT& rc, BOOL bRepaint = TRUE) const;
+ BOOL PostMessage(UINT uMsg, WPARAM wParam = 0L, LPARAM lParam = 0L) const;
+ BOOL PostMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const;
+ BOOL RedrawWindow(LPCRECT lpRectUpdate = NULL, CRgn* pRgn = NULL, UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN) const;
+ int ReleaseDC(CDC* pDC) const;
+ BOOL ScreenToClient(POINT& Point) const;
+ BOOL ScreenToClient(RECT& rc) const;
+ LRESULT SendDlgItemMessage(int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam) const;
+ LRESULT SendMessage(UINT uMsg, WPARAM wParam = 0L, LPARAM lParam = 0L) const;
+ LRESULT SendMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) const;
+ BOOL SendNotifyMessage(UINT Msg, WPARAM wParam, LPARAM lParam) const;
+ CWnd* SetActiveWindow() const;
+ CWnd* SetCapture() const;
+ ULONG_PTR SetClassLongPtr(int nIndex, LONG_PTR dwNewLong) const;
+ BOOL SetDlgItemInt(int nIDDlgItem, UINT uValue, BOOL bSigned) const;
+ BOOL SetDlgItemText(int nIDDlgItem, LPCTSTR lpString) const;
+ CWnd* SetFocus() const;
+ void SetFont(CFont* pFont, BOOL bRedraw = TRUE) const;
+ BOOL SetForegroundWindow() const;
+ HICON SetIcon(HICON hIcon, BOOL bBigIcon) const;
+ CWnd* SetParent(CWnd* pWndParent) const;
+ BOOL SetRedraw(BOOL bRedraw = TRUE) const;
+ int SetScrollInfo(int fnBar, const SCROLLINFO& si, BOOL fRedraw) const;
+ UINT_PTR SetTimer(UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc) const;
+ LONG_PTR SetWindowLongPtr(int nIndex, LONG_PTR dwNewLong) const;
+ BOOL SetWindowPos(HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags) const;
+ BOOL SetWindowPos(HWND hWndInsertAfter, const RECT& rc, UINT uFlags) const;
+ int SetWindowRgn(CRgn* pRgn, BOOL bRedraw = TRUE) const;
+ BOOL SetWindowText(LPCTSTR lpString) const;
+ HRESULT SetWindowTheme(LPCWSTR pszSubAppName, LPCWSTR pszSubIdList) const;
+ BOOL ShowWindow(int nCmdShow = SW_SHOWNORMAL) const;
+ BOOL UpdateWindow() const;
+ BOOL ValidateRect(LPCRECT prc) const;
+ BOOL ValidateRgn(CRgn* pRgn) const;
+ static CWnd* WindowFromPoint(POINT pt);
+
+ #ifndef _WIN32_WCE
+ BOOL CloseWindow() const;
+ int DlgDirList(LPTSTR lpPathSpec, int nIDListBox, int nIDStaticPath, UINT uFileType) const;
+ int DlgDirListComboBox(LPTSTR lpPathSpec, int nIDComboBox, int nIDStaticPath, UINT uFiletype) const;
+ BOOL DlgDirSelectEx(LPTSTR lpString, int nCount, int nIDListBox) const;
+ BOOL DlgDirSelectComboBoxEx(LPTSTR lpString, int nCount, int nIDComboBox) const;
+ BOOL DrawAnimatedRects(int idAni, RECT& rcFrom, RECT& rcTo) const;
+ BOOL DrawCaption(CDC* pDC, RECT& rc, UINT uFlags) const;
+ BOOL EnableScrollBar(UINT uSBflags, UINT uArrows) const;
+ CWnd* GetLastActivePopup() const;
+ CMenu* GetMenu() const;
+ int GetScrollPos(int nBar) const;
+ BOOL GetScrollRange(int nBar, int& MinPos, int& MaxPos) const;
+ CMenu* GetSystemMenu(BOOL bRevert) const;
+ CWnd* GetTopWindow() const;
+ BOOL GetWindowPlacement(WINDOWPLACEMENT& pWndpl) const;
+ BOOL HiliteMenuItem(CMenu* pMenu, UINT uItemHilite, UINT uHilite) const;
+ BOOL IsIconic() const;
+ BOOL IsZoomed() const;
+ BOOL LockWindowUpdate() const;
+ BOOL OpenIcon() const;
+ void Print(CDC* pDC, DWORD dwFlags) const;
+ BOOL SetMenu(CMenu* pMenu) const;
+ BOOL ScrollWindow(int XAmount, int YAmount, LPCRECT lprcScroll, LPCRECT lprcClip) const;
+ int ScrollWindowEx(int dx, int dy, LPCRECT lprcScroll, LPCRECT lprcClip, CRgn* prgnUpdate, LPRECT lprcUpdate, UINT flags) const;
+ int SetScrollPos(int nBar, int nPos, BOOL bRedraw) const;
+ BOOL SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw) const;
+ BOOL SetWindowPlacement(const WINDOWPLACEMENT& wndpl) const;
+ BOOL ShowOwnedPopups(BOOL fShow) const;
+ BOOL ShowScrollBar(int nBar, BOOL bShow) const;
+ BOOL ShowWindowAsync(int nCmdShow) const;
+ BOOL UnLockWindowUpdate() const;
+ CWnd* WindowFromDC(CDC* pDC) const;
+
+ #ifndef WIN32_LEAN_AND_MEAN
+ void DragAcceptFiles(BOOL fAccept) const;
+ #endif
+ #endif
+
+ static LRESULT CALLBACK StaticWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ operator HWND() const { return m_hWnd; }
+
+ protected:
+ // Override these functions as required
+ virtual LRESULT FinalWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
+ virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
+ virtual void OnCreate();
+ virtual void OnDraw(CDC* pDC);
+ virtual BOOL OnEraseBkgnd(CDC* pDC);
+ virtual void OnInitialUpdate();
+ virtual void OnMenuUpdate(UINT nID);
+ virtual LRESULT OnMessageReflect(UINT uMsg, WPARAM wParam, LPARAM lParam);
+ virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam);
+ virtual LRESULT OnNotifyReflect(WPARAM wParam, LPARAM lParam);
+ virtual void PreCreate(CREATESTRUCT& cs);
+ virtual void PreRegisterClass(WNDCLASS& wc);
+ virtual BOOL PreTranslateMessage(MSG* pMsg);
+ virtual LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
+ virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);
+
+ HWND m_hWnd; // handle to this object's window
+
+ private:
+ CWnd(const CWnd&); // Disable copy construction
+ CWnd& operator = (const CWnd&); // Disable assignment operator
+ void AddToMap();
+ void Cleanup();
+ LRESULT MessageReflect(HWND hwndParent, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ BOOL RegisterClass(WNDCLASS& wc);
+ BOOL RemoveFromMap();
+ void Subclass(HWND hWnd);
+
+ Shared_Ptr<WNDCLASS> m_pwc; // defines initialisation parameters for PreRegisterClass
+ Shared_Ptr<CREATESTRUCT> m_pcs; // defines initialisation parameters for PreCreate and Create
+ WNDPROC m_PrevWindowProc; // pre-subclassed Window Procedure
+ BOOL m_IsTmpWnd; // True if this CWnd is a TmpWnd
+
+ }; // class CWnd
+
+}
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+#include "gdi.h"
+#include "menu.h"
+
+namespace Win32xx
+{
+
+ //////////////////////////////////////////
+ // Definitions for the CWinException class
+ //
+ inline CWinException::CWinException(LPCTSTR pszText) throw () : m_Error(::GetLastError()), m_pszText(pszText)
+ {
+ memset(m_szErrorString, 0, MAX_STRING_SIZE * sizeof(TCHAR));
+
+ if (m_Error != 0)
+ {
+ DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
+ ::FormatMessage(dwFlags, NULL, m_Error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), m_szErrorString, MAX_STRING_SIZE-1, NULL);
+ }
+ }
+
+ inline DWORD CWinException::GetError() const throw ()
+ {
+ return m_Error;
+ }
+
+ inline LPCTSTR CWinException::GetErrorString() const throw ()
+ {
+ return m_szErrorString;
+ }
+
+ inline const char * CWinException::what() const throw ()
+ {
+ // Sends the last error string to the debugger (typically displayed in the IDE's output window).
+ ::OutputDebugString(m_szErrorString);
+ return "CWinException thrown";
+ }
+
+
+ ////////////////////////////////////
+ // Definitions for the CWinApp class
+ //
+
+ // To begin Win32++, inherit your application class from this one.
+ // You must run only one instance of the class inherited from this.
+ inline CWinApp::CWinApp() : m_Callback(NULL), m_hAccel(0), m_pWndAccel(0)
+ {
+ try
+ {
+ m_csAppStart.Lock();
+ assert( 0 == SetnGetThis() ); // Test if this is the first instance of CWinApp
+
+ m_dwTlsIndex = ::TlsAlloc();
+ if (m_dwTlsIndex == TLS_OUT_OF_INDEXES)
+ {
+ // We only get here in the unlikely event that all TLS indexes are already allocated by this app
+ // At least 64 TLS indexes per process are allowed. Win32++ requires only one TLS index.
+ m_csAppStart.Release();
+ throw CWinException(_T("CWinApp::CWinApp Failed to allocate TLS Index"));
+ }
+
+ SetnGetThis(this);
+ m_csAppStart.Release();
+
+ // Set the instance handle
+ #ifdef _WIN32_WCE
+ m_hInstance = (HINSTANCE)GetModuleHandle(0);
+ #else
+ MEMORY_BASIC_INFORMATION mbi = {0};
+ VirtualQuery( (LPCVOID)SetnGetThis, &mbi, sizeof(mbi) );
+ assert(mbi.AllocationBase);
+ m_hInstance = (HINSTANCE)mbi.AllocationBase;
+ #endif
+
+ m_hResource = m_hInstance;
+ SetCallback();
+ }
+
+ catch (const CWinException &e)
+ {
+ e.what();
+ throw;
+ }
+ }
+
+ inline CWinApp::~CWinApp()
+ {
+ std::vector<TLSDataPtr>::iterator iter;
+ for (iter = m_vTLSData.begin(); iter < m_vTLSData.end(); ++iter)
+ {
+ (*iter)->vTmpDCs.clear();
+#ifndef _WIN32_WCE
+ (*iter)->vTmpMenus.clear();
+#endif
+ (*iter)->vTmpWnds.clear();
+ }
+
+ // Check that all CWnd windows are destroyed
+ std::map<HWND, CWnd*, CompareHWND>::iterator m;
+ for (m = m_mapHWND.begin(); m != m_mapHWND.end(); ++m)
+ {
+ HWND hWnd = (*m).first;
+ if (::IsWindow(hWnd))
+ ::DestroyWindow(hWnd);
+ }
+ m_mapHWND.clear();
+ m_mapGDI.clear();
+ m_mapHDC.clear();
+ m_mapHMENU.clear();
+
+ // Do remaining tidy up
+ if (m_dwTlsIndex != TLS_OUT_OF_INDEXES)
+ {
+ ::TlsSetValue(GetTlsIndex(), NULL);
+ ::TlsFree(m_dwTlsIndex);
+ }
+
+ SetnGetThis((CWinApp*)-1);
+ }
+
+ inline void CWinApp::AddTmpDC(CDC* pDC)
+ {
+ // The TmpMenus are created by GetSybMenu.
+ // They are removed by CleanupTemps
+ assert(pDC);
+
+ // Ensure this thread has the TLS index set
+ TLSData* pTLSData = GetApp()->SetTlsIndex();
+ pTLSData->vTmpDCs.push_back(pDC); // save pDC as a smart pointer
+ }
+
+ inline void CWinApp::AddTmpGDI(CGDIObject* pObject)
+ {
+ // The temporary CGDIObjects are removed by CleanupTemps
+ assert(pObject);
+
+ // Ensure this thread has the TLS index set
+ TLSData* pTLSData = GetApp()->SetTlsIndex();
+ pTLSData->vTmpGDIs.push_back(pObject); // save pObject as a smart pointer
+ }
+
+#ifndef _WIN32_WCE
+ inline CMenu* CWinApp::AddTmpMenu(HMENU hMenu)
+ {
+ // The TmpMenus are created by GetSybMenu.
+ // They are removed by CleanupTemps
+ assert(::IsMenu(hMenu));
+ assert(!GetCMenuFromMap(hMenu));
+
+ CMenu* pMenu = new CMenu;
+ pMenu->m_hMenu = hMenu;
+ m_csMapLock.Lock();
+ m_mapHMENU.insert(std::make_pair(hMenu, pMenu));
+ m_csMapLock.Release();
+ pMenu->m_IsTmpMenu = TRUE;
+
+ // Ensure this thread has the TLS index set
+ TLSData* pTLSData = GetApp()->SetTlsIndex();
+ pTLSData->vTmpMenus.push_back(pMenu); // save pMenu as a smart pointer
+ return pMenu;
+ }
+#endif
+
+ inline CWnd* CWinApp::AddTmpWnd(HWND hWnd)
+ {
+ // TmpWnds are created if required to support functions like CWnd::GetParent.
+ // They are removed by CleanupTemps
+ assert(::IsWindow(hWnd));
+ assert(!GetCWndFromMap(hWnd));
+
+ CWnd* pWnd = new CWnd;
+ pWnd->m_hWnd = hWnd;
+ pWnd->AddToMap();
+ pWnd->m_IsTmpWnd = TRUE;
+
+ // Ensure this thread has the TLS index set
+ TLSData* pTLSData = GetApp()->SetTlsIndex();
+ pTLSData->vTmpWnds.push_back(pWnd); // save pWnd as a smart pointer
+ return pWnd;
+ }
+
+ inline void CWinApp::CleanupTemps()
+ // Removes all Temporary CWnds and CMenus belonging to this thread
+ {
+ // Retrieve the pointer to the TLS Data
+ TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());
+ assert(pTLSData);
+
+ pTLSData->vTmpDCs.clear();
+ pTLSData->vTmpGDIs.clear();
+ pTLSData->vTmpWnds.clear();
+
+
+ #ifndef _WIN32_WCE
+ pTLSData->vTmpMenus.clear();
+ #endif
+ }
+
+ inline CDC* CWinApp::GetCDCFromMap(HDC hDC)
+ {
+ // Allocate an iterator for our HWND map
+ std::map<HDC, CDC*, CompareHDC>::iterator m;
+
+ // Find the CDC pointer mapped to this HDC
+ CDC* pDC = 0;
+ m_csMapLock.Lock();
+ m = m_mapHDC.find(hDC);
+
+ if (m != m_mapHDC.end())
+ pDC = m->second;
+
+ m_csMapLock.Release();
+ return pDC;
+ }
+
+ inline CGDIObject* CWinApp::GetCGDIObjectFromMap(HGDIOBJ hObject)
+ {
+ // Allocate an iterator for our HWND map
+ std::map<HGDIOBJ, CGDIObject*, CompareGDI>::iterator m;
+
+ // Find the CGDIObject pointer mapped to this HGDIOBJ
+ CGDIObject* pObject = 0;
+ m_csMapLock.Lock();
+ m = m_mapGDI.find(hObject);
+
+ if (m != m_mapGDI.end())
+ pObject = m->second;
+
+ m_csMapLock.Release();
+ return pObject;
+ }
+
+ inline CMenu* CWinApp::GetCMenuFromMap(HMENU hMenu)
+ {
+ std::map<HMENU, CMenu*, CompareHMENU>::iterator m;
+
+ // Find the CMenu pointer mapped to this HMENU
+ CMenu* pMenu = 0;
+ m_csMapLock.Lock();
+ m = m_mapHMENU.find(hMenu);
+
+ if (m != m_mapHMENU.end())
+ pMenu = m->second;
+
+ m_csMapLock.Release();
+ return pMenu;
+ }
+
+ inline CWnd* CWinApp::GetCWndFromMap(HWND hWnd)
+ {
+ // Allocate an iterator for our HWND map
+ std::map<HWND, CWnd*, CompareHWND>::iterator m;
+
+ // Find the CWnd pointer mapped to this HWND
+ CWnd* pWnd = 0;
+ m_csMapLock.Lock();
+ m = m_mapHWND.find(hWnd);
+
+ if (m != m_mapHWND.end())
+ pWnd = m->second;
+
+ m_csMapLock.Release();
+ return pWnd;
+ }
+
+ inline BOOL CWinApp::InitInstance()
+ {
+ // InitInstance contains the initialization code for your application
+ // You should override this function with the code to run when the application starts.
+
+ // return TRUE to indicate success. FALSE will end the application
+ return TRUE;
+ }
+
+ inline int CWinApp::MessageLoop()
+ {
+ // This gets any messages queued for the application, and dispatches them.
+ MSG Msg = {0};
+ int status = 1;
+ LONG lCount = 0;
+
+ while (status != 0)
+ {
+ // While idle, perform idle processing until OnIdle returns FALSE
+ while (!::PeekMessage(&Msg, 0, 0, 0, PM_NOREMOVE) && OnIdle(lCount) == TRUE)
+ {
+ ++lCount;
+ }
+
+ lCount = 0;
+
+ // Now wait until we get a message
+ if ((status = ::GetMessage(&Msg, NULL, 0, 0)) == -1)
+ return -1;
+
+ if (!PreTranslateMessage(Msg))
+ {
+ ::TranslateMessage(&Msg);
+ ::DispatchMessage(&Msg);
+ }
+ }
+
+ return LOWORD(Msg.wParam);
+ }
+
+ inline BOOL CWinApp::OnIdle(LONG lCount)
+ {
+ if (lCount == 0)
+ CleanupTemps();
+
+ return FALSE;
+ }
+
+ inline BOOL CWinApp::PreTranslateMessage(MSG Msg)
+ {
+ // This functions is called by the MessageLoop. It processes the
+ // keyboard accelerator keys and calls CWnd::PreTranslateMessage for
+ // keyboard and mouse events.
+
+ BOOL Processed = FALSE;
+
+ // only pre-translate mouse and keyboard input events
+ if ((Msg.message >= WM_KEYFIRST && Msg.message <= WM_KEYLAST) ||
+ (Msg.message >= WM_MOUSEFIRST && Msg.message <= WM_MOUSELAST))
+ {
+ // Process keyboard accelerators
+ if (m_pWndAccel && ::TranslateAccelerator(*m_pWndAccel, m_hAccel, &Msg))
+ Processed = TRUE;
+ else
+ {
+ // Search the chain of parents for pretranslated messages.
+ for (HWND hWnd = Msg.hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd))
+ {
+ CWnd* pWnd = GetCWndFromMap(hWnd);
+ if (pWnd)
+ {
+ Processed = pWnd->PreTranslateMessage(&Msg);
+ if(Processed)
+ break;
+ }
+ }
+ }
+ }
+
+ return Processed;
+ }
+
+ inline int CWinApp::Run()
+ {
+ // InitInstance runs the App's initialization code
+ if (InitInstance())
+ {
+ // Dispatch the window messages
+ return MessageLoop();
+ }
+ else
+ {
+ TRACE(_T("InitInstance failed! Terminating program\n"));
+ ::PostQuitMessage(-1);
+ return -1;
+ }
+ }
+
+ inline void CWinApp::SetAccelerators(HACCEL hAccel, CWnd* pWndAccel)
+ // nID is the resource ID of the accelerator table
+ // pWndAccel is the window pointer for translated messages
+ {
+ assert (hAccel);
+ assert (pWndAccel);
+
+ m_pWndAccel = pWndAccel;
+ m_hAccel = hAccel;
+ }
+
+ inline void CWinApp::SetCallback()
+ {
+ // Registers a temporary window class so we can get the callback
+ // address of CWnd::StaticWindowProc.
+ // This technique works for all Window versions, including WinCE.
+
+ WNDCLASS wcDefault = {0};
+
+ LPCTSTR szClassName = _T("Win32++ Temporary Window Class");
+ wcDefault.hInstance = GetInstanceHandle();
+ wcDefault.lpfnWndProc = CWnd::StaticWindowProc;
+ wcDefault.lpszClassName = szClassName;
+
+ ::RegisterClass(&wcDefault);
+
+ // Retrieve the class information
+ ZeroMemory(&wcDefault, sizeof(wcDefault));
+ ::GetClassInfo(GetInstanceHandle(), szClassName, &wcDefault);
+
+ // Save the callback address of CWnd::StaticWindowProc
+ assert(wcDefault.lpfnWndProc); // Assert fails when running UNICODE build on ANSI OS.
+ m_Callback = wcDefault.lpfnWndProc;
+ ::UnregisterClass(szClassName, GetInstanceHandle());
+ }
+
+ inline CWinApp* CWinApp::SetnGetThis(CWinApp* pThis /*= 0*/)
+ {
+ // This function stores the 'this' pointer in a static variable.
+ // Once stored, it can be used later to return the 'this' pointer.
+ // CWinApp's Destructor calls this function with a value of -1.
+
+ static CWinApp* pWinApp = 0;
+
+ if ((CWinApp*)-1 == pThis)
+ pWinApp = 0;
+ else if (0 == pWinApp)
+ pWinApp = pThis;
+
+ return pWinApp;
+ }
+
+ inline void CWinApp::SetResourceHandle(HINSTANCE hResource)
+ {
+ // This function can be used to load a resource dll.
+ // A resource dll can be used to define resources in different languages.
+ // To use this function, place code like this in InitInstance
+ //
+ // HINSTANCE hResource = LoadLibrary(_T("MyResourceDLL.dll"));
+ // SetResourceHandle(hResource);
+
+ m_hResource = hResource;
+ }
+
+ inline TLSData* CWinApp::SetTlsIndex()
+ {
+ TLSData* pTLSData = (TLSData*)::TlsGetValue(GetTlsIndex());
+ if (NULL == pTLSData)
+ {
+ pTLSData = new TLSData;
+
+ m_csTLSLock.Lock();
+ m_vTLSData.push_back(