--- /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
+// WceFrame.h\r
+// Definitions for the CCmdBar and CWceFrame\r
+\r
+// These classes are provide a frame window for use on Window CE devices such\r
+// as Pocket PCs. The frame uses CommandBar (a control unique to the Windows CE\r
+// operating systems) to display the menu and toolbar.\r
+//\r
+// Use the PocketPCWceFrame generic application as the starting point for your own\r
+// frame based applications on the Pocket PC.\r
+//\r
+// Refer to the Scribble demo application for an example of how these classes\r
+// can be used.\r
+\r
+\r
+#ifndef _WIN32XX_WCEFRAME_H_\r
+#define _WIN32XX_WCEFRAME_H_\r
+\r
+\r
+#include "wincore.h"\r
+#include <commctrl.h>\r
+#include <vector>\r
+#include "default_resource.h"\r
+\r
+#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)\r
+ #define SHELL_AYGSHELL\r
+#endif\r
+\r
+#ifdef SHELL_AYGSHELL\r
+ #include <aygshell.h>\r
+ #pragma comment(lib, "aygshell.lib")\r
+#endif // SHELL_AYGSHELL\r
+\r
+#if (_WIN32_WCE < 0x500 && defined(SHELL_AYGSHELL)) || _WIN32_WCE == 420\r
+ #pragma comment(lib, "ccrtrtti.lib")\r
+#endif\r
+\r
+\r
+namespace Win32xx\r
+{\r
+\r
+ ////////////////////////////////////\r
+ // Declaration of the CCmdBar class\r
+ //\r
+ class CCmdBar : public CWnd\r
+ {\r
+ public:\r
+ CCmdBar();\r
+ virtual ~CCmdBar();\r
+ virtual BOOL AddAdornments(DWORD dwFlags);\r
+ virtual int AddBitmap(int idBitmap, int iNumImages, int iImageWidth, int iImageHeight);\r
+ virtual BOOL AddButtons(int nButtons, TBBUTTON* pTBButton);\r
+ virtual HWND Create(HWND hwndParent);\r
+ virtual int GetHeight() const;\r
+ virtual HWND InsertComboBox(int iWidth, UINT dwStyle, WORD idComboBox, WORD iButton);\r
+ virtual BOOL IsVisible();\r
+ virtual BOOL Show(BOOL fShow);\r
+\r
+ private:\r
+\r
+#ifdef SHELL_AYGSHELL\r
+ SHMENUBARINFO m_mbi;\r
+#endif\r
+\r
+ };\r
+\r
+\r
+ //////////////////////////////////////\r
+ // Declaration of the CWceFrame class\r
+ // A mini frame based on CCmdBar\r
+ class CWceFrame : public CWnd\r
+ {\r
+ public:\r
+ CWceFrame();\r
+ virtual ~CWceFrame();\r
+ virtual void AddToolBarButton(UINT nID);\r
+ CRect GetViewRect() const;\r
+ CCmdBar& GetMenuBar() const {return (CCmdBar&)m_MenuBar;}\r
+ virtual void OnActivate(WPARAM wParam, LPARAM lParam);\r
+ virtual void OnCreate(); \r
+ virtual void PreCreate(CREATESTRUCT &cs);\r
+ virtual void RecalcLayout();\r
+ virtual void SetButtons(const std::vector<UINT> ToolBarData);\r
+ virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
+\r
+ protected:\r
+ std::vector<UINT> m_ToolBarData;\r
+\r
+ private:\r
+ CCmdBar m_MenuBar;\r
+ CString m_strAppName;\r
+\r
+#ifdef SHELL_AYGSHELL\r
+ SHACTIVATEINFO m_sai;\r
+#endif\r
+\r
+ };\r
+\r
+ //////////////////////////////////////////\r
+ // Definitions for the CCmdBar class\r
+ // This class wraps CommandBar_Create which\r
+ // creates a CommandBar at the top of the window\r
+ inline CCmdBar::CCmdBar()\r
+ {\r
+ }\r
+\r
+ inline CCmdBar::~CCmdBar()\r
+ {\r
+ if (IsWindow())\r
+ ::CommandBar_Destroy(m_hWnd);\r
+ }\r
+\r
+\r
+ inline BOOL CCmdBar::AddAdornments(DWORD dwFlags)\r
+ {\r
+ BOOL bReturn = CommandBar_AddAdornments(m_hWnd, dwFlags, 0);\r
+\r
+ if (!bReturn)\r
+ throw CWinException(_T("AddAdornments failed"));\r
+\r
+ return bReturn;\r
+ }\r
+\r
+ inline int CCmdBar::AddBitmap(int idBitmap, int iNumImages, int iImageWidth, int iImageHeight)\r
+ {\r
+ HINSTANCE hInst = GetApp()->GetInstanceHandle();\r
+ return CommandBar_AddBitmap(m_hWnd, hInst, idBitmap, iNumImages, iImageWidth, iImageHeight);\r
+ }\r
+\r
+ inline BOOL CCmdBar::AddButtons(int nButtons, TBBUTTON* pTBButton)\r
+ {\r
+ BOOL bReturn = CommandBar_AddButtons(m_hWnd, nButtons, pTBButton);\r
+ if (!bReturn)\r
+ throw CWinException(_T("Failed to add buttons to commandbar"));\r
+\r
+ return bReturn;\r
+ }\r
+\r
+ inline HWND CCmdBar::Create(HWND hParent)\r
+ {\r
+#ifdef SHELL_AYGSHELL\r
+ SHMENUBARINFO mbi;\r
+\r
+ memset(&mbi, 0, sizeof(SHMENUBARINFO));\r
+ mbi.cbSize = sizeof(SHMENUBARINFO);\r
+ mbi.hwndParent = hParent;\r
+ mbi.nToolBarId = IDW_MAIN;\r
+ mbi.hInstRes = GetApp()->GetInstanceHandle();\r
+ mbi.nBmpId = 0;\r
+ mbi.cBmpImages = 0;\r
+\r
+ if (SHCreateMenuBar(&mbi))\r
+ {\r
+ m_hWnd = mbi.hwndMB;\r
+ }\r
+ else\r
+ throw CWinException(_T("Failed to create MenuBar"));\r
+ \r
+#else\r
+ m_hWnd = CommandBar_Create(GetApp()->GetInstanceHandle(), hParent, IDW_MENUBAR);\r
+\r
+ if (m_hWnd == NULL)\r
+ throw CWinException(_T("Failed to create CommandBar"));\r
+\r
+ CommandBar_InsertMenubar(m_hWnd, GetApp()->GetInstanceHandle(), IDW_MAIN, 0);\r
+#endif\r
+ return m_hWnd;\r
+ }\r
+\r
+ inline int CCmdBar::GetHeight() const\r
+ {\r
+ return CommandBar_Height(m_hWnd);\r
+ }\r
+\r
+ inline HWND CCmdBar::InsertComboBox(int iWidth, UINT dwStyle, WORD idComboBox, WORD iButton)\r
+ {\r
+ HINSTANCE hInst = GetApp()->GetInstanceHandle();\r
+ HWND hWnd = CommandBar_InsertComboBox(m_hWnd, hInst, iWidth, dwStyle, idComboBox, iButton);\r
+\r
+ if (!hWnd)\r
+ throw CWinException(_T("InsertComboBox failed"));\r
+\r
+ return hWnd;\r
+ }\r
+\r
+ inline BOOL CCmdBar::IsVisible()\r
+ {\r
+ return ::CommandBar_IsVisible(m_hWnd);\r
+ }\r
+\r
+ inline BOOL CCmdBar::Show(BOOL fShow)\r
+ {\r
+ return ::CommandBar_Show(m_hWnd, fShow);\r
+ }\r
+\r
+\r
+ /////////////////////////////////////////\r
+ // Definitions for the CWceFrame class\r
+ // This class creates a simple frame using CCmdBar\r
+ inline CWceFrame::CWceFrame()\r
+ {\r
+#ifdef SHELL_AYGSHELL\r
+ // Initialize the shell activate info structure\r
+ memset (&m_sai, 0, sizeof (m_sai));\r
+ m_sai.cbSize = sizeof (m_sai);\r
+#endif\r
+ }\r
+\r
+ inline CWceFrame::~CWceFrame()\r
+ {\r
+ }\r
+\r
+ inline void CWceFrame::AddToolBarButton(UINT nID)\r
+ // Adds Resource IDs to toolbar buttons.\r
+ // A resource ID of 0 is a separator\r
+ {\r
+ m_ToolBarData.push_back(nID);\r
+ }\r
+\r
+ inline CRect CWceFrame::GetViewRect() const\r
+ {\r
+ CRect r;\r
+ ::GetClientRect(m_hWnd, &r);\r
+\r
+#ifndef SHELL_AYGSHELL\r
+ // Reduce the size of the client rectange, by the commandbar height\r
+ r.top += m_MenuBar.GetHeight();\r
+#endif\r
+\r
+ return r;\r
+ }\r
+\r
+ inline void CWceFrame::OnCreate()\r
+ {\r
+ // Create the Commandbar\r
+ m_MenuBar.Create(m_hWnd);\r
+\r
+ // Set the keyboard accelerators\r
+ HACCEL hAccel = LoadAccelerators(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(IDW_MAIN));\r
+ GetApp()->SetAccelerators(hAccel, this);\r
+\r
+ // Add the toolbar buttons\r
+ if (m_ToolBarData.size() > 0)\r
+ SetButtons(m_ToolBarData);\r
+\r
+#ifndef SHELL_AYGSHELL\r
+ // Add close button\r
+ m_MenuBar.AddAdornments(0);\r
+#endif\r
+\r
+ }\r
+\r
+ inline void CWceFrame::OnActivate(WPARAM wParam, LPARAM lParam)\r
+ {\r
+#ifdef SHELL_AYGSHELL\r
+ // Notify shell of our activate message\r
+ SHHandleWMActivate(m_hWnd, wParam, lParam, &m_sai, FALSE);\r
+\r
+ UINT fActive = LOWORD(wParam);\r
+ if ((fActive == WA_ACTIVE) || (fActive == WA_CLICKACTIVE))\r
+ {\r
+ // Reposition the window when it's activated\r
+ RecalcLayout();\r
+ }\r
+#endif\r
+ }\r
+\r
+ inline void CWceFrame::PreCreate(CREATESTRUCT &cs)\r
+ {\r
+ cs.style = WS_VISIBLE;\r
+ m_strAppName = _T("Win32++ Application");\r
+\r
+ // Choose a unique class name for this app\r
+ if (LoadString(IDW_MAIN) != _T(""))\r
+ {\r
+ m_strAppName = LoadString(IDW_MAIN);\r
+ }\r
+ \r
+ cs.lpszClass = m_strAppName;\r
+ }\r
+\r
+ inline void CWceFrame::RecalcLayout()\r
+ {\r
+ HWND hwndCB = m_MenuBar.GetHwnd();\r
+ if (hwndCB)\r
+ {\r
+ CRect rc; // Desktop window size\r
+ CRect rcMenuBar; // MenuBar window size\r
+\r
+ ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);\r
+ ::GetWindowRect(hwndCB, &rcMenuBar);\r
+ rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);\r
+\r
+ MoveWindow(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);\r
+ }\r
+\r
+ ShowWindow(TRUE);\r
+ UpdateWindow();\r
+ }\r
+\r
+ inline void CWceFrame::SetButtons(const std::vector<UINT> ToolBarData)\r
+ // Define the resource IDs for the toolbar like this in the Frame's constructor\r
+ // m_ToolBarData.push_back ( 0 ); // Separator\r
+ // m_ToolBarData.clear();\r
+ // m_ToolBarData.push_back ( IDM_FILE_NEW );\r
+ // m_ToolBarData.push_back ( IDM_FILE_OPEN );\r
+ // m_ToolBarData.push_back ( IDM_FILE_SAVE );\r
+\r
+ {\r
+ int iImages = 0;\r
+ int iNumButtons = (int)ToolBarData.size();\r
+\r
+\r
+ if (iNumButtons > 0)\r
+ {\r
+ // Create the TBBUTTON array for each button\r
+ std::vector<TBBUTTON> vTBB(iNumButtons);\r
+ TBBUTTON* tbbArray = &vTBB.front();\r
+\r
+ for (int j = 0 ; j < iNumButtons; j++)\r
+ {\r
+ ZeroMemory(&tbbArray[j], sizeof(TBBUTTON));\r
+\r
+ if (ToolBarData[j] == 0)\r
+ {\r
+ tbbArray[j].fsStyle = TBSTYLE_SEP;\r
+ }\r
+ else\r
+ {\r
+ tbbArray[j].iBitmap = iImages++;\r
+ tbbArray[j].idCommand = ToolBarData[j];\r
+ tbbArray[j].fsState = TBSTATE_ENABLED;\r
+ tbbArray[j].fsStyle = TBSTYLE_BUTTON;\r
+ tbbArray[j].iString = -1;\r
+ }\r
+ }\r
+\r
+ // Add the bitmap\r
+ GetMenuBar().AddBitmap(IDW_MAIN, iImages , 16, 16);\r
+\r
+ // Add the buttons\r
+ GetMenuBar().AddButtons(iNumButtons, tbbArray);\r
+ }\r
+ }\r
+\r
+ inline LRESULT CWceFrame::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+ {\r
+ switch (uMsg)\r
+ {\r
+ case WM_DESTROY:\r
+ PostQuitMessage(0);\r
+ break;\r
+ case WM_ACTIVATE:\r
+ OnActivate(wParam, lParam);\r
+ break;\r
+\r
+#ifdef SHELL_AYGSHELL\r
+\r
+ case WM_SETTINGCHANGE:\r
+ SHHandleWMSettingChange(m_hWnd, wParam, lParam, &m_sai);\r
+ break;\r
+#endif\r
+\r
+ }\r
+ return CWnd::WndProcDefault(uMsg, wParam, lParam);\r
+ }\r
+\r
+\r
+} // namespace Win32xx\r
+\r
+#endif // _WIN32XX_WCEFRAME_H_\r
+\r