1 // Win32++ Version 7.3
\r
2 // Released: 30th November 2011
\r
6 // url: https://sourceforge.net/projects/win32-framework
\r
9 // Copyright (c) 2005-2011 David Nash
\r
11 // Permission is hereby granted, free of charge, to
\r
12 // any person obtaining a copy of this software and
\r
13 // associated documentation files (the "Software"),
\r
14 // to deal in the Software without restriction, including
\r
15 // without limitation the rights to use, copy, modify,
\r
16 // merge, publish, distribute, sublicense, and/or sell
\r
17 // copies of the Software, and to permit persons to whom
\r
18 // the Software is furnished to do so, subject to the
\r
19 // following conditions:
\r
21 // The above copyright notice and this permission notice
\r
22 // shall be included in all copies or substantial portions
\r
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
\r
26 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
\r
27 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
\r
28 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
\r
29 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
\r
30 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
31 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
32 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
\r
33 // OR OTHER DEALINGS IN THE SOFTWARE.
\r
35 ////////////////////////////////////////////////////////
\r
38 //////////////////////////////////////////////////////
\r
40 // Definitions for the CCmdBar and CWceFrame
\r
42 // These classes are provide a frame window for use on Window CE devices such
\r
43 // as Pocket PCs. The frame uses CommandBar (a control unique to the Windows CE
\r
44 // operating systems) to display the menu and toolbar.
\r
46 // Use the PocketPCWceFrame generic application as the starting point for your own
\r
47 // frame based applications on the Pocket PC.
\r
49 // Refer to the Scribble demo application for an example of how these classes
\r
53 #ifndef _WIN32XX_WCEFRAME_H_
\r
54 #define _WIN32XX_WCEFRAME_H_
\r
57 #include "wincore.h"
\r
58 #include <commctrl.h>
\r
60 #include "default_resource.h"
\r
62 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
\r
63 #define SHELL_AYGSHELL
\r
66 #ifdef SHELL_AYGSHELL
\r
67 #include <aygshell.h>
\r
68 #pragma comment(lib, "aygshell.lib")
\r
69 #endif // SHELL_AYGSHELL
\r
71 #if (_WIN32_WCE < 0x500 && defined(SHELL_AYGSHELL)) || _WIN32_WCE == 420
\r
72 #pragma comment(lib, "ccrtrtti.lib")
\r
79 ////////////////////////////////////
\r
80 // Declaration of the CCmdBar class
\r
82 class CCmdBar : public CWnd
\r
87 virtual BOOL AddAdornments(DWORD dwFlags);
\r
88 virtual int AddBitmap(int idBitmap, int iNumImages, int iImageWidth, int iImageHeight);
\r
89 virtual BOOL AddButtons(int nButtons, TBBUTTON* pTBButton);
\r
90 virtual HWND Create(HWND hwndParent);
\r
91 virtual int GetHeight() const;
\r
92 virtual HWND InsertComboBox(int iWidth, UINT dwStyle, WORD idComboBox, WORD iButton);
\r
93 virtual BOOL IsVisible();
\r
94 virtual BOOL Show(BOOL fShow);
\r
98 #ifdef SHELL_AYGSHELL
\r
99 SHMENUBARINFO m_mbi;
\r
105 //////////////////////////////////////
\r
106 // Declaration of the CWceFrame class
\r
107 // A mini frame based on CCmdBar
\r
108 class CWceFrame : public CWnd
\r
112 virtual ~CWceFrame();
\r
113 virtual void AddToolBarButton(UINT nID);
\r
114 CRect GetViewRect() const;
\r
115 CCmdBar& GetMenuBar() const {return (CCmdBar&)m_MenuBar;}
\r
116 virtual void OnActivate(WPARAM wParam, LPARAM lParam);
\r
117 virtual void OnCreate();
\r
118 virtual void PreCreate(CREATESTRUCT &cs);
\r
119 virtual void RecalcLayout();
\r
120 virtual void SetButtons(const std::vector<UINT> ToolBarData);
\r
121 virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);
\r
124 std::vector<UINT> m_ToolBarData;
\r
128 CString m_strAppName;
\r
130 #ifdef SHELL_AYGSHELL
\r
131 SHACTIVATEINFO m_sai;
\r
136 //////////////////////////////////////////
\r
137 // Definitions for the CCmdBar class
\r
138 // This class wraps CommandBar_Create which
\r
139 // creates a CommandBar at the top of the window
\r
140 inline CCmdBar::CCmdBar()
\r
144 inline CCmdBar::~CCmdBar()
\r
147 ::CommandBar_Destroy(m_hWnd);
\r
151 inline BOOL CCmdBar::AddAdornments(DWORD dwFlags)
\r
153 BOOL bReturn = CommandBar_AddAdornments(m_hWnd, dwFlags, 0);
\r
156 throw CWinException(_T("AddAdornments failed"));
\r
161 inline int CCmdBar::AddBitmap(int idBitmap, int iNumImages, int iImageWidth, int iImageHeight)
\r
163 HINSTANCE hInst = GetApp()->GetInstanceHandle();
\r
164 return CommandBar_AddBitmap(m_hWnd, hInst, idBitmap, iNumImages, iImageWidth, iImageHeight);
\r
167 inline BOOL CCmdBar::AddButtons(int nButtons, TBBUTTON* pTBButton)
\r
169 BOOL bReturn = CommandBar_AddButtons(m_hWnd, nButtons, pTBButton);
\r
171 throw CWinException(_T("Failed to add buttons to commandbar"));
\r
176 inline HWND CCmdBar::Create(HWND hParent)
\r
178 #ifdef SHELL_AYGSHELL
\r
181 memset(&mbi, 0, sizeof(SHMENUBARINFO));
\r
182 mbi.cbSize = sizeof(SHMENUBARINFO);
\r
183 mbi.hwndParent = hParent;
\r
184 mbi.nToolBarId = IDW_MAIN;
\r
185 mbi.hInstRes = GetApp()->GetInstanceHandle();
\r
187 mbi.cBmpImages = 0;
\r
189 if (SHCreateMenuBar(&mbi))
\r
191 m_hWnd = mbi.hwndMB;
\r
194 throw CWinException(_T("Failed to create MenuBar"));
\r
197 m_hWnd = CommandBar_Create(GetApp()->GetInstanceHandle(), hParent, IDW_MENUBAR);
\r
199 if (m_hWnd == NULL)
\r
200 throw CWinException(_T("Failed to create CommandBar"));
\r
202 CommandBar_InsertMenubar(m_hWnd, GetApp()->GetInstanceHandle(), IDW_MAIN, 0);
\r
207 inline int CCmdBar::GetHeight() const
\r
209 return CommandBar_Height(m_hWnd);
\r
212 inline HWND CCmdBar::InsertComboBox(int iWidth, UINT dwStyle, WORD idComboBox, WORD iButton)
\r
214 HINSTANCE hInst = GetApp()->GetInstanceHandle();
\r
215 HWND hWnd = CommandBar_InsertComboBox(m_hWnd, hInst, iWidth, dwStyle, idComboBox, iButton);
\r
218 throw CWinException(_T("InsertComboBox failed"));
\r
223 inline BOOL CCmdBar::IsVisible()
\r
225 return ::CommandBar_IsVisible(m_hWnd);
\r
228 inline BOOL CCmdBar::Show(BOOL fShow)
\r
230 return ::CommandBar_Show(m_hWnd, fShow);
\r
234 /////////////////////////////////////////
\r
235 // Definitions for the CWceFrame class
\r
236 // This class creates a simple frame using CCmdBar
\r
237 inline CWceFrame::CWceFrame()
\r
239 #ifdef SHELL_AYGSHELL
\r
240 // Initialize the shell activate info structure
\r
241 memset (&m_sai, 0, sizeof (m_sai));
\r
242 m_sai.cbSize = sizeof (m_sai);
\r
246 inline CWceFrame::~CWceFrame()
\r
250 inline void CWceFrame::AddToolBarButton(UINT nID)
\r
251 // Adds Resource IDs to toolbar buttons.
\r
252 // A resource ID of 0 is a separator
\r
254 m_ToolBarData.push_back(nID);
\r
257 inline CRect CWceFrame::GetViewRect() const
\r
260 ::GetClientRect(m_hWnd, &r);
\r
262 #ifndef SHELL_AYGSHELL
\r
263 // Reduce the size of the client rectange, by the commandbar height
\r
264 r.top += m_MenuBar.GetHeight();
\r
270 inline void CWceFrame::OnCreate()
\r
272 // Create the Commandbar
\r
273 m_MenuBar.Create(m_hWnd);
\r
275 // Set the keyboard accelerators
\r
276 HACCEL hAccel = LoadAccelerators(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(IDW_MAIN));
\r
277 GetApp()->SetAccelerators(hAccel, this);
\r
279 // Add the toolbar buttons
\r
280 if (m_ToolBarData.size() > 0)
\r
281 SetButtons(m_ToolBarData);
\r
283 #ifndef SHELL_AYGSHELL
\r
284 // Add close button
\r
285 m_MenuBar.AddAdornments(0);
\r
290 inline void CWceFrame::OnActivate(WPARAM wParam, LPARAM lParam)
\r
292 #ifdef SHELL_AYGSHELL
\r
293 // Notify shell of our activate message
\r
294 SHHandleWMActivate(m_hWnd, wParam, lParam, &m_sai, FALSE);
\r
296 UINT fActive = LOWORD(wParam);
\r
297 if ((fActive == WA_ACTIVE) || (fActive == WA_CLICKACTIVE))
\r
299 // Reposition the window when it's activated
\r
305 inline void CWceFrame::PreCreate(CREATESTRUCT &cs)
\r
307 cs.style = WS_VISIBLE;
\r
308 m_strAppName = _T("Win32++ Application");
\r
310 // Choose a unique class name for this app
\r
311 if (LoadString(IDW_MAIN) != _T(""))
\r
313 m_strAppName = LoadString(IDW_MAIN);
\r
316 cs.lpszClass = m_strAppName;
\r
319 inline void CWceFrame::RecalcLayout()
\r
321 HWND hwndCB = m_MenuBar.GetHwnd();
\r
324 CRect rc; // Desktop window size
\r
325 CRect rcMenuBar; // MenuBar window size
\r
327 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
\r
328 ::GetWindowRect(hwndCB, &rcMenuBar);
\r
329 rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
\r
331 MoveWindow(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
\r
338 inline void CWceFrame::SetButtons(const std::vector<UINT> ToolBarData)
\r
339 // Define the resource IDs for the toolbar like this in the Frame's constructor
\r
340 // m_ToolBarData.push_back ( 0 ); // Separator
\r
341 // m_ToolBarData.clear();
\r
342 // m_ToolBarData.push_back ( IDM_FILE_NEW );
\r
343 // m_ToolBarData.push_back ( IDM_FILE_OPEN );
\r
344 // m_ToolBarData.push_back ( IDM_FILE_SAVE );
\r
348 int iNumButtons = (int)ToolBarData.size();
\r
351 if (iNumButtons > 0)
\r
353 // Create the TBBUTTON array for each button
\r
354 std::vector<TBBUTTON> vTBB(iNumButtons);
\r
355 TBBUTTON* tbbArray = &vTBB.front();
\r
357 for (int j = 0 ; j < iNumButtons; j++)
\r
359 ZeroMemory(&tbbArray[j], sizeof(TBBUTTON));
\r
361 if (ToolBarData[j] == 0)
\r
363 tbbArray[j].fsStyle = TBSTYLE_SEP;
\r
367 tbbArray[j].iBitmap = iImages++;
\r
368 tbbArray[j].idCommand = ToolBarData[j];
\r
369 tbbArray[j].fsState = TBSTATE_ENABLED;
\r
370 tbbArray[j].fsStyle = TBSTYLE_BUTTON;
\r
371 tbbArray[j].iString = -1;
\r
376 GetMenuBar().AddBitmap(IDW_MAIN, iImages , 16, 16);
\r
379 GetMenuBar().AddButtons(iNumButtons, tbbArray);
\r
383 inline LRESULT CWceFrame::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
388 PostQuitMessage(0);
\r
391 OnActivate(wParam, lParam);
\r
394 #ifdef SHELL_AYGSHELL
\r
396 case WM_SETTINGCHANGE:
\r
397 SHHandleWMSettingChange(m_hWnd, wParam, lParam, &m_sai);
\r
402 return CWnd::WndProcDefault(uMsg, wParam, lParam);
\r
406 } // namespace Win32xx
\r
408 #endif // _WIN32XX_WCEFRAME_H_
\r