Merge branch 'master' of git.ucc.asn.au:/matches/honours
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / include / wceframe.h
1 // Win32++   Version 7.3\r
2 // Released: 30th November 2011\r
3 //\r
4 //      David Nash\r
5 //      email: [email protected]\r
6 //      url: https://sourceforge.net/projects/win32-framework\r
7 //\r
8 //\r
9 // Copyright (c) 2005-2011  David Nash\r
10 //\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
20 //\r
21 // The above copyright notice and this permission notice\r
22 // shall be included in all copies or substantial portions\r
23 // of the Software.\r
24 //\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
34 //\r
35 ////////////////////////////////////////////////////////\r
36 \r
37 \r
38 //////////////////////////////////////////////////////\r
39 // WceFrame.h\r
40 // Definitions for the CCmdBar and CWceFrame\r
41 \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
45 //\r
46 // Use the PocketPCWceFrame generic application as the starting point for your own\r
47 // frame based applications on the Pocket PC.\r
48 //\r
49 // Refer to the Scribble demo application for an example of how these classes\r
50 // can be used.\r
51 \r
52 \r
53 #ifndef _WIN32XX_WCEFRAME_H_\r
54 #define _WIN32XX_WCEFRAME_H_\r
55 \r
56 \r
57 #include "wincore.h"\r
58 #include <commctrl.h>\r
59 #include <vector>\r
60 #include "default_resource.h"\r
61 \r
62 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)\r
63   #define SHELL_AYGSHELL\r
64 #endif\r
65 \r
66 #ifdef SHELL_AYGSHELL\r
67   #include <aygshell.h>\r
68   #pragma comment(lib, "aygshell.lib")\r
69 #endif // SHELL_AYGSHELL\r
70 \r
71 #if (_WIN32_WCE < 0x500 && defined(SHELL_AYGSHELL)) || _WIN32_WCE == 420\r
72   #pragma comment(lib, "ccrtrtti.lib")\r
73 #endif\r
74 \r
75 \r
76 namespace Win32xx\r
77 {\r
78 \r
79         ////////////////////////////////////\r
80         // Declaration of the CCmdBar class\r
81         //\r
82         class CCmdBar : public CWnd\r
83         {\r
84         public:\r
85                 CCmdBar();\r
86                 virtual ~CCmdBar();\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
95 \r
96         private:\r
97 \r
98 #ifdef SHELL_AYGSHELL\r
99                 SHMENUBARINFO m_mbi;\r
100 #endif\r
101 \r
102         };\r
103 \r
104 \r
105         //////////////////////////////////////\r
106         // Declaration of the CWceFrame class\r
107         //  A mini frame based on CCmdBar\r
108         class CWceFrame : public CWnd\r
109         {\r
110         public:\r
111                 CWceFrame();\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
122 \r
123         protected:\r
124                 std::vector<UINT> m_ToolBarData;\r
125 \r
126         private:\r
127                 CCmdBar m_MenuBar;\r
128                 CString m_strAppName;\r
129 \r
130 #ifdef SHELL_AYGSHELL\r
131                 SHACTIVATEINFO m_sai;\r
132 #endif\r
133 \r
134         };\r
135 \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
141         {\r
142         }\r
143 \r
144         inline CCmdBar::~CCmdBar()\r
145         {\r
146                 if (IsWindow())\r
147                         ::CommandBar_Destroy(m_hWnd);\r
148         }\r
149 \r
150 \r
151         inline BOOL CCmdBar::AddAdornments(DWORD dwFlags)\r
152         {\r
153                 BOOL bReturn = CommandBar_AddAdornments(m_hWnd, dwFlags, 0);\r
154 \r
155                 if (!bReturn)\r
156                         throw CWinException(_T("AddAdornments failed"));\r
157 \r
158                 return bReturn;\r
159         }\r
160 \r
161         inline int CCmdBar::AddBitmap(int idBitmap, int iNumImages, int iImageWidth, int iImageHeight)\r
162         {\r
163                 HINSTANCE hInst = GetApp()->GetInstanceHandle();\r
164                 return  CommandBar_AddBitmap(m_hWnd, hInst, idBitmap, iNumImages, iImageWidth, iImageHeight);\r
165         }\r
166 \r
167         inline BOOL CCmdBar::AddButtons(int nButtons, TBBUTTON* pTBButton)\r
168         {\r
169                  BOOL bReturn = CommandBar_AddButtons(m_hWnd, nButtons, pTBButton);\r
170                  if (!bReturn)\r
171                          throw CWinException(_T("Failed to add buttons to commandbar"));\r
172 \r
173                  return bReturn;\r
174         }\r
175 \r
176         inline HWND CCmdBar::Create(HWND hParent)\r
177         {\r
178 #ifdef SHELL_AYGSHELL\r
179                 SHMENUBARINFO mbi;\r
180 \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
186                 mbi.nBmpId     = 0;\r
187                 mbi.cBmpImages = 0;\r
188 \r
189                 if (SHCreateMenuBar(&mbi))\r
190                 {\r
191                         m_hWnd = mbi.hwndMB;\r
192                 }\r
193                 else\r
194                         throw CWinException(_T("Failed to create MenuBar"));\r
195                 \r
196 #else\r
197                 m_hWnd = CommandBar_Create(GetApp()->GetInstanceHandle(), hParent, IDW_MENUBAR);\r
198 \r
199                 if (m_hWnd == NULL)\r
200                         throw CWinException(_T("Failed to create CommandBar"));\r
201 \r
202                 CommandBar_InsertMenubar(m_hWnd, GetApp()->GetInstanceHandle(), IDW_MAIN, 0);\r
203 #endif\r
204                 return m_hWnd;\r
205         }\r
206 \r
207         inline int CCmdBar::GetHeight() const\r
208         {\r
209                 return CommandBar_Height(m_hWnd);\r
210         }\r
211 \r
212         inline HWND CCmdBar::InsertComboBox(int iWidth, UINT dwStyle, WORD idComboBox, WORD iButton)\r
213         {\r
214                 HINSTANCE hInst = GetApp()->GetInstanceHandle();\r
215                 HWND hWnd = CommandBar_InsertComboBox(m_hWnd, hInst, iWidth, dwStyle, idComboBox, iButton);\r
216 \r
217                 if (!hWnd)\r
218                         throw CWinException(_T("InsertComboBox failed"));\r
219 \r
220                 return hWnd;\r
221         }\r
222 \r
223         inline BOOL CCmdBar::IsVisible()\r
224         {\r
225                 return ::CommandBar_IsVisible(m_hWnd);\r
226         }\r
227 \r
228         inline BOOL CCmdBar::Show(BOOL fShow)\r
229         {\r
230                 return ::CommandBar_Show(m_hWnd, fShow);\r
231         }\r
232 \r
233 \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
238         {\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
243 #endif\r
244         }\r
245 \r
246         inline CWceFrame::~CWceFrame()\r
247         {\r
248         }\r
249 \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
253         {\r
254                 m_ToolBarData.push_back(nID);\r
255         }\r
256 \r
257         inline CRect CWceFrame::GetViewRect() const\r
258         {\r
259                 CRect r;\r
260                 ::GetClientRect(m_hWnd, &r);\r
261 \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
265 #endif\r
266 \r
267                 return r;\r
268         }\r
269 \r
270         inline void CWceFrame::OnCreate()\r
271         {\r
272                 // Create the Commandbar\r
273                 m_MenuBar.Create(m_hWnd);\r
274 \r
275                 // Set the keyboard accelerators\r
276                 HACCEL hAccel = LoadAccelerators(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(IDW_MAIN));\r
277                 GetApp()->SetAccelerators(hAccel, this);\r
278 \r
279                 // Add the toolbar buttons\r
280                 if (m_ToolBarData.size() > 0)\r
281                         SetButtons(m_ToolBarData);\r
282 \r
283 #ifndef SHELL_AYGSHELL\r
284                 // Add close button\r
285                 m_MenuBar.AddAdornments(0);\r
286 #endif\r
287 \r
288         }\r
289 \r
290         inline void CWceFrame::OnActivate(WPARAM wParam, LPARAM lParam)\r
291         {\r
292 #ifdef SHELL_AYGSHELL\r
293                 // Notify shell of our activate message\r
294                 SHHandleWMActivate(m_hWnd, wParam, lParam, &m_sai, FALSE);\r
295 \r
296                 UINT fActive = LOWORD(wParam);\r
297                 if ((fActive == WA_ACTIVE) || (fActive == WA_CLICKACTIVE))\r
298                 {\r
299                         // Reposition the window when it's activated\r
300                         RecalcLayout();\r
301                 }\r
302 #endif\r
303         }\r
304 \r
305         inline void CWceFrame::PreCreate(CREATESTRUCT &cs)\r
306         {\r
307                 cs.style = WS_VISIBLE;\r
308                 m_strAppName = _T("Win32++ Application");\r
309 \r
310                 // Choose a unique class name for this app\r
311                 if (LoadString(IDW_MAIN) != _T(""))\r
312                 {\r
313                         m_strAppName = LoadString(IDW_MAIN);\r
314                 }\r
315                         \r
316                 cs.lpszClass = m_strAppName;\r
317         }\r
318 \r
319         inline void CWceFrame::RecalcLayout()\r
320         {\r
321                 HWND hwndCB = m_MenuBar.GetHwnd();\r
322                 if (hwndCB)\r
323                 {\r
324                         CRect rc;                       // Desktop window size\r
325                         CRect rcMenuBar;        // MenuBar window size\r
326 \r
327                         ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);\r
328                         ::GetWindowRect(hwndCB, &rcMenuBar);\r
329                         rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);\r
330 \r
331                         MoveWindow(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);\r
332                 }\r
333 \r
334                 ShowWindow(TRUE);\r
335                 UpdateWindow();\r
336         }\r
337 \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
345 \r
346         {\r
347                 int iImages = 0;\r
348                 int iNumButtons = (int)ToolBarData.size();\r
349 \r
350 \r
351                 if (iNumButtons > 0)\r
352                 {\r
353                         // Create the TBBUTTON array for each button\r
354                         std::vector<TBBUTTON> vTBB(iNumButtons);\r
355                         TBBUTTON* tbbArray = &vTBB.front();\r
356 \r
357                         for (int j = 0 ; j < iNumButtons; j++)\r
358                         {\r
359                                 ZeroMemory(&tbbArray[j], sizeof(TBBUTTON));\r
360 \r
361                                 if (ToolBarData[j] == 0)\r
362                                 {\r
363                                         tbbArray[j].fsStyle = TBSTYLE_SEP;\r
364                                 }\r
365                                 else\r
366                                 {\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
372                                 }\r
373                         }\r
374 \r
375                         // Add the bitmap\r
376                         GetMenuBar().AddBitmap(IDW_MAIN, iImages , 16, 16);\r
377 \r
378                         // Add the buttons\r
379                         GetMenuBar().AddButtons(iNumButtons, tbbArray);\r
380                 }\r
381         }\r
382 \r
383         inline LRESULT CWceFrame::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
384         {\r
385                 switch (uMsg)\r
386                 {\r
387                         case WM_DESTROY:\r
388                                 PostQuitMessage(0);\r
389                                 break;\r
390                         case WM_ACTIVATE:\r
391                                 OnActivate(wParam, lParam);\r
392                         break;\r
393 \r
394 #ifdef SHELL_AYGSHELL\r
395 \r
396                         case WM_SETTINGCHANGE:\r
397                                 SHHandleWMSettingChange(m_hWnd, wParam, lParam, &m_sai);\r
398                         break;\r
399 #endif\r
400 \r
401                 }\r
402                 return CWnd::WndProcDefault(uMsg, wParam, lParam);\r
403         }\r
404 \r
405 \r
406 } // namespace Win32xx\r
407 \r
408 #endif // _WIN32XX_WCEFRAME_H_\r
409 \r

UCC git Repository :: git.ucc.asn.au