Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / include / menu.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 // menu.h\r
40 //  Declaration of the CMenu class\r
41 \r
42 // Notes\r
43 //  1) Owner-drawn menus send the WM_MEASUREITEM and WM_DRAWITEM messages\r
44 //     to the window that owns the menu. To manage owner drawing for menus,\r
45 //     handle these two messages in the CWnd's WndProc function.\r
46 //\r
47 //  2) The CMenu pointer returned by FromHandle might be a temporary pointer. It\r
48 //     should be used immediately, not saved for later use.\r
49 //\r
50 //  3) The CMenu pointers returned by FromHandle or GetSubMenu do not need\r
51 //     to be deleted. They are automatically deleted by the Win32++.\r
52 //\r
53 //  4) CMenu pointers returned by GetSubMenu are deleted when the parent CMenu is\r
54 //     detached, destroyed or deconstructed.\r
55 //\r
56 //  5) The HMENU that is attached to a CMenu object (using the attach function) is \r
57 //     automatically deleted when the CMenu object goes out of scope. Detach the\r
58 //     HMENU to stop it being deleted when CMenu's destructor is called.\r
59 //\r
60 //  6) Pass CMenu objects by reference or by pointer when passing them as function \r
61 //     arguments.\r
62 //\r
63 //  7) In those functions that use a MENUITEMINFO structure, its cbSize member is \r
64 //     automatically set to the correct value.\r
65 \r
66 //  Program sample\r
67 //  --------------\r
68 //      void CView::CreatePopup()\r
69 //      {\r
70 //              CPoint pt = GetCursorPos();\r
71 //      \r
72 //              // Create the menu\r
73 //              CMenu Popup;\r
74 //              Popup.CreatePopupMenu();\r
75 // \r
76 //              // Add some menu items\r
77 //              Popup.AppendMenu(MF_STRING, 101, _T("Menu Item &1"));\r
78 //              Popup.AppendMenu(MF_STRING, 102, _T("Menu Item &2"));\r
79 //              Popup.AppendMenu(MF_STRING, 103, _T("Menu Item &3"));\r
80 //              Popup.AppendMenu(MF_SEPARATOR);\r
81 //              Popup.AppendMenu(MF_STRING, 104, _T("Menu Item &4"));\r
82 // \r
83 //              // Set menu item states\r
84 //              Popup.CheckMenuRadioItem(101, 101, 101, MF_BYCOMMAND);\r
85 //              Popup.CheckMenuItem(102, MF_BYCOMMAND | MF_CHECKED);\r
86 //              Popup.EnableMenuItem(103, MF_BYCOMMAND | MF_GRAYED);\r
87 //              Popup.SetDefaultItem(104);\r
88 //      \r
89 //              // Display the popup menu\r
90 //              Popup.TrackPopupMenu(0, pt.x, pt.y, this); \r
91 //      }\r
92 \r
93 \r
94 \r
95 #if !defined(_WIN32XX_MENU_H_) && !defined(_WIN32_WCE)\r
96 #define _WIN32XX_MENU_H_\r
97 \r
98 \r
99 #include "wincore.h"\r
100 #include "gdi.h"\r
101 \r
102 \r
103 namespace Win32xx\r
104 {\r
105 \r
106         // Forward declarations\r
107         class CBitmap;\r
108 \r
109         class CMenu\r
110         {\r
111                 friend class CWinApp;\r
112 \r
113         public:\r
114                 //Construction\r
115                 CMenu() : m_hMenu(0), m_IsTmpMenu(FALSE) {}\r
116                 CMenu(UINT nID) : m_IsTmpMenu(FALSE) \r
117                 {\r
118                         m_hMenu = ::LoadMenu(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(nID));\r
119                 }\r
120                 ~CMenu();\r
121 \r
122                 //Initialization\r
123                 void Attach(HMENU hMenu);\r
124                 void CreateMenu();\r
125                 void CreatePopupMenu();\r
126                 void DestroyMenu();\r
127                 HMENU Detach();\r
128                 HMENU GetHandle() const;\r
129                 BOOL LoadMenu(LPCTSTR lpszResourceName);\r
130                 BOOL LoadMenu(UINT uIDResource);\r
131                 BOOL LoadMenuIndirect(const void* lpMenuTemplate);\r
132 \r
133                 //Menu Operations\r
134                 BOOL TrackPopupMenu(UINT uFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect = 0);\r
135                 BOOL TrackPopupMenuEx(UINT uFlags, int x, int y, CWnd* pWnd, LPTPMPARAMS lptpm);\r
136 \r
137                 //Menu Item Operations\r
138                 BOOL AppendMenu(UINT uFlags, UINT_PTR uIDNewItem = 0, LPCTSTR lpszNewItem = NULL);\r
139                 BOOL AppendMenu(UINT uFlags, UINT_PTR uIDNewItem, const CBitmap* pBmp);\r
140                 UINT CheckMenuItem(UINT uIDCheckItem, UINT uCheck);\r
141                 BOOL CheckMenuRadioItem(UINT uIDFirst, UINT uIDLast, UINT uIDItem, UINT uFlags);\r
142                 BOOL DeleteMenu(UINT uPosition, UINT uFlags);\r
143                 UINT EnableMenuItem(UINT uIDEnableItem, UINT uEnable);\r
144                 UINT GetDefaultItem(UINT gmdiFlags, BOOL fByPos = FALSE);\r
145                 DWORD GetMenuContextHelpId() const;\r
146 \r
147 #if(WINVER >= 0x0500)   // Minimum OS required is Win2000\r
148                 BOOL GetMenuInfo(LPMENUINFO lpcmi) const;\r
149                 BOOL SetMenuInfo(LPCMENUINFO lpcmi);\r
150 #endif\r
151 \r
152                 UINT GetMenuItemCount() const;\r
153                 UINT GetMenuItemID(int nPos) const;\r
154                 BOOL GetMenuItemInfo(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos = FALSE);\r
155                 UINT GetMenuState(UINT uID, UINT uFlags) const;\r
156                 int GetMenuString(UINT uIDItem, LPTSTR lpString, int nMaxCount, UINT uFlags) const;\r
157                 int GetMenuString(UINT uIDItem, CString& rString, UINT uFlags) const;\r
158                 CMenu* GetSubMenu(int nPos);\r
159                 BOOL InsertMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem = 0, LPCTSTR lpszNewItem = NULL);\r
160                 BOOL InsertMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, const CBitmap* pBmp);\r
161                 BOOL InsertMenuItem(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos = FALSE);\r
162                 BOOL ModifyMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem = 0, LPCTSTR lpszNewItem = NULL);\r
163                 BOOL ModifyMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, const CBitmap* pBmp);\r
164                 BOOL RemoveMenu(UINT uPosition, UINT uFlags);\r
165                 BOOL SetDefaultItem(UINT uItem, BOOL fByPos = FALSE);\r
166                 BOOL SetMenuContextHelpId(DWORD dwContextHelpId);\r
167                 BOOL SetMenuItemBitmaps(UINT uPosition, UINT uFlags, const CBitmap* pBmpUnchecked, const CBitmap* pBmpChecked);\r
168                 BOOL SetMenuItemInfo(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos = FALSE);\r
169 \r
170                 //Operators\r
171                 BOOL operator != (const CMenu& menu) const;\r
172                 BOOL operator == (const CMenu& menu) const;\r
173                 operator HMENU () const;\r
174 \r
175         private:\r
176                 CMenu(const CMenu&);                            // Disable copy construction\r
177                 CMenu& operator = (const CMenu&);       // Disable assignment operator\r
178                 void AddToMap();\r
179                 BOOL RemoveFromMap();\r
180                 std::vector<MenuPtr> m_vSubMenus;       // A vector of smart pointers to CMenu\r
181                 HMENU m_hMenu;\r
182                 BOOL m_IsTmpMenu;\r
183         };\r
184 \r
185         inline CMenu::~CMenu()\r
186         {\r
187                 if (m_hMenu)\r
188                 {       \r
189                         if (!m_IsTmpMenu)\r
190                         {\r
191                                 ::DestroyMenu(m_hMenu);\r
192                         }\r
193                         \r
194                         RemoveFromMap();\r
195                 }\r
196 \r
197                 m_vSubMenus.clear();\r
198         }\r
199 \r
200         inline void CMenu::AddToMap()\r
201         // Store the HMENU and CMenu pointer in the HMENU map\r
202         {\r
203                 assert( GetApp() );\r
204                 assert(m_hMenu);\r
205                 \r
206                 GetApp()->m_csMapLock.Lock();\r
207                 GetApp()->m_mapHMENU.insert(std::make_pair(m_hMenu, this));\r
208                 GetApp()->m_csMapLock.Release();\r
209         }\r
210 \r
211         inline BOOL CMenu::RemoveFromMap()\r
212         {\r
213                 BOOL Success = FALSE;\r
214 \r
215                 if (GetApp())\r
216                 {\r
217                         // Allocate an iterator for our HDC map\r
218                         std::map<HMENU, CMenu*, CompareHMENU>::iterator m;\r
219 \r
220                         CWinApp* pApp = GetApp();\r
221                         if (pApp)\r
222                         {\r
223                                 // Erase the CDC pointer entry from the map\r
224                                 pApp->m_csMapLock.Lock();\r
225                                 for (m = pApp->m_mapHMENU.begin(); m != pApp->m_mapHMENU.end(); ++m)\r
226                                 {\r
227                                         if (this == m->second)\r
228                                         {\r
229                                                 pApp->m_mapHMENU.erase(m);\r
230                                                 Success = TRUE;\r
231                                                 break;\r
232                                         }\r
233                                 }\r
234 \r
235                                 pApp->m_csMapLock.Release();\r
236                         }\r
237                 }\r
238 \r
239                 return Success;\r
240         }\r
241         \r
242         \r
243         inline BOOL CMenu::AppendMenu(UINT uFlags, UINT_PTR uIDNewItem /*= 0*/, LPCTSTR lpszNewItem /*= NULL*/)\r
244         // Appends a new item to the end of the specified menu bar, drop-down menu, submenu, or shortcut menu.\r
245         {\r
246                 assert(IsMenu(m_hMenu));\r
247                 return ::AppendMenu(m_hMenu, uFlags, uIDNewItem, lpszNewItem);\r
248         }\r
249 \r
250         inline BOOL CMenu::AppendMenu(UINT uFlags, UINT_PTR uIDNewItem, const CBitmap* pBmp)\r
251         // Appends a new item to the end of the specified menu bar, drop-down menu, submenu, or shortcut menu.\r
252         {\r
253                 assert(IsMenu(m_hMenu));\r
254                 assert(pBmp);\r
255                 return ::AppendMenu(m_hMenu, uFlags, uIDNewItem, (LPCTSTR)pBmp->GetHandle());\r
256         }\r
257 \r
258         inline void CMenu::Attach(HMENU hMenu)\r
259         // Attaches an existing menu to this CMenu\r
260         {\r
261                 if (m_hMenu != NULL && m_hMenu != hMenu)\r
262                 {\r
263                         ::DestroyMenu(Detach());\r
264                 }\r
265 \r
266                 if (hMenu)\r
267                 {\r
268                         m_hMenu = hMenu;\r
269                         AddToMap();\r
270                 }\r
271         }\r
272         \r
273         inline UINT CMenu::CheckMenuItem(UINT uIDCheckItem, UINT uCheck)\r
274         // Sets the state of the specified menu item's check-mark attribute to either selected or clear.\r
275         {\r
276                 assert(IsMenu(m_hMenu));\r
277                 return ::CheckMenuItem(m_hMenu, uIDCheckItem, uCheck);\r
278         }\r
279 \r
280         inline BOOL CMenu::CheckMenuRadioItem(UINT uIDFirst, UINT uIDLast, UINT uIDItem, UINT uFlags)\r
281         // Checks a specified menu item and makes it a radio item. At the same time, the function clears \r
282         //  all other menu items in the associated group and clears the radio-item type flag for those items.\r
283         {\r
284                 assert(IsMenu(m_hMenu));\r
285                 return ::CheckMenuRadioItem(m_hMenu, uIDFirst, uIDLast, uIDItem, uFlags);\r
286         }       \r
287 \r
288         inline void CMenu::CreateMenu()\r
289         // Creates an empty menu.\r
290         {\r
291                 assert(NULL == m_hMenu);\r
292                 m_hMenu = ::CreateMenu();\r
293                 AddToMap();\r
294         }\r
295 \r
296         inline void CMenu::CreatePopupMenu()\r
297         // Creates a drop-down menu, submenu, or shortcut menu. The menu is initially empty.\r
298         {\r
299                 assert(NULL == m_hMenu);\r
300                 m_hMenu = ::CreatePopupMenu();\r
301                 AddToMap();\r
302         }\r
303         \r
304         inline BOOL CMenu::DeleteMenu(UINT uPosition, UINT uFlags)\r
305         // Deletes an item from the specified menu.\r
306         {\r
307                 assert(IsMenu(m_hMenu));\r
308                 return ::DeleteMenu(m_hMenu, uPosition, uFlags);\r
309         }       \r
310 \r
311         inline void CMenu::DestroyMenu()\r
312         // Destroys the menu and frees any memory that the menu occupies.\r
313         {\r
314                 if (::IsMenu(m_hMenu)) \r
315                         ::DestroyMenu(m_hMenu);\r
316                 \r
317                 m_hMenu = 0;\r
318                 RemoveFromMap();\r
319                 m_vSubMenus.clear();\r
320         }\r
321 \r
322         inline HMENU CMenu::Detach()\r
323         // Detaches the HMENU from this CMenu. If the HMENU is not detached it will be \r
324         // destroyed when this CMenu is deconstructed.\r
325         {\r
326                 assert(IsMenu(m_hMenu));\r
327                 HMENU hMenu = m_hMenu;\r
328                 m_hMenu = 0;\r
329                 RemoveFromMap();\r
330                 m_vSubMenus.clear();\r
331                 return hMenu;\r
332         }\r
333 \r
334         inline HMENU CMenu::GetHandle() const\r
335         // Returns the HMENU assigned to this CMenu\r
336         {\r
337                 return m_hMenu;\r
338         }\r
339 \r
340         inline UINT CMenu::EnableMenuItem(UINT uIDEnableItem, UINT uEnable)\r
341         // Enables, disables, or grays the specified menu item.\r
342         // The uEnable parameter must be a combination of either MF_BYCOMMAND or MF_BYPOSITION\r
343         // and MF_ENABLED, MF_DISABLED, or MF_GRAYED.\r
344         {\r
345                 assert(IsMenu(m_hMenu));\r
346                 return ::EnableMenuItem(m_hMenu, uIDEnableItem, uEnable);\r
347         }\r
348         \r
349         inline UINT CMenu::GetDefaultItem(UINT gmdiFlags, BOOL fByPos /*= FALSE*/)\r
350         // Determines the default menu item.\r
351         // The gmdiFlags parameter specifies how the function searches for menu items. \r
352         // This parameter can be zero or more of the following values: GMDI_GOINTOPOPUPS; GMDI_USEDISABLED.\r
353         {\r
354                 assert(IsMenu(m_hMenu));\r
355                 return ::GetMenuDefaultItem(m_hMenu, fByPos, gmdiFlags);\r
356         }\r
357 \r
358         inline DWORD CMenu::GetMenuContextHelpId() const\r
359         // Retrieves the Help context identifier associated with the menu.\r
360         {\r
361                 assert(IsMenu(m_hMenu));\r
362                 return ::GetMenuContextHelpId(m_hMenu);\r
363         }\r
364 \r
365 #if(WINVER >= 0x0500)\r
366 // minimum OS required : Win2000\r
367 \r
368         inline BOOL CMenu::GetMenuInfo(LPMENUINFO lpcmi) const\r
369         // Retrieves the menu information.\r
370         {\r
371                 assert(IsMenu(m_hMenu));\r
372                 return ::GetMenuInfo(m_hMenu, lpcmi);\r
373         }\r
374 \r
375         inline BOOL CMenu::SetMenuInfo(LPCMENUINFO lpcmi)\r
376         // Sets the menu information from the specified MENUINFO structure.\r
377         {\r
378                 assert(IsMenu(m_hMenu));\r
379                 return ::SetMenuInfo(m_hMenu, lpcmi);\r
380         }\r
381 \r
382 #endif\r
383 \r
384         inline UINT CMenu::GetMenuItemCount() const\r
385         // Retrieves the number of menu items.\r
386         {\r
387                 assert(IsMenu(m_hMenu));\r
388                 return ::GetMenuItemCount(m_hMenu);\r
389         }\r
390 \r
391         inline UINT CMenu::GetMenuItemID(int nPos) const\r
392         // Retrieves the menu item identifier of a menu item located at the specified position\r
393         {\r
394                 assert(IsMenu(m_hMenu));\r
395                 return ::GetMenuItemID(m_hMenu, nPos);\r
396         }\r
397 \r
398         inline BOOL CMenu::GetMenuItemInfo(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos /*= FALSE*/)\r
399         // retrieves information about the specified menu item.\r
400         {\r
401                 assert(IsMenu(m_hMenu));\r
402                 assert(lpMenuItemInfo);\r
403                 lpMenuItemInfo->cbSize = GetSizeofMenuItemInfo();\r
404                 return ::GetMenuItemInfo(m_hMenu, uItem, fByPos, lpMenuItemInfo);\r
405         }\r
406 \r
407         inline UINT CMenu::GetMenuState(UINT uID, UINT uFlags) const\r
408         // Retrieves the menu flags associated with the specified menu item.\r
409         // Possible values for uFlags are: MF_BYCOMMAND (default) or MF_BYPOSITION.\r
410         {\r
411                 assert(IsMenu(m_hMenu));\r
412                 return ::GetMenuState(m_hMenu, uID, uFlags);\r
413         }\r
414 \r
415         inline int CMenu::GetMenuString(UINT uIDItem, LPTSTR lpString, int nMaxCount, UINT uFlags) const\r
416         // Copies the text string of the specified menu item into the specified buffer.\r
417         {\r
418                 assert(IsMenu(m_hMenu));\r
419                 assert(lpString);\r
420                 return ::GetMenuString(m_hMenu, uIDItem, lpString, nMaxCount, uFlags);\r
421         }\r
422 \r
423         inline int CMenu::GetMenuString(UINT uIDItem, CString& rString, UINT uFlags) const\r
424         // Copies the text string of the specified menu item into the specified buffer.\r
425         {\r
426                 assert(IsMenu(m_hMenu));\r
427                 return ::GetMenuString(m_hMenu, uIDItem, (LPTSTR)rString.c_str(), rString.GetLength(), uFlags);\r
428         }\r
429 \r
430         inline CMenu* CMenu::GetSubMenu(int nPos)\r
431         // Retrieves the CMenu object of a pop-up menu.\r
432         {\r
433                 assert(IsMenu(m_hMenu));\r
434                 CMenu* pMenu = new CMenu;\r
435                 pMenu->m_hMenu = ::GetSubMenu(m_hMenu, nPos);\r
436                 pMenu->m_IsTmpMenu = TRUE;\r
437                 m_vSubMenus.push_back(pMenu);\r
438                 return pMenu;\r
439         }\r
440 \r
441         inline BOOL CMenu::InsertMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem /*= 0*/, LPCTSTR lpszNewItem /*= NULL*/)\r
442         // Inserts a new menu item into a menu, moving other items down the menu.\r
443         {\r
444                 assert(IsMenu(m_hMenu));\r
445                 return ::InsertMenu(m_hMenu, uPosition, uFlags, uIDNewItem, lpszNewItem);\r
446         }\r
447 \r
448         inline BOOL CMenu::InsertMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, const CBitmap* pBmp)\r
449         // Inserts a new menu item into a menu, moving other items down the menu.\r
450         {\r
451                 assert(IsMenu(m_hMenu));\r
452                 return ::InsertMenu(m_hMenu, uPosition, uFlags, uIDNewItem, (LPCTSTR)pBmp->GetHandle());\r
453         }\r
454 \r
455         inline BOOL CMenu::InsertMenuItem(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos /*= FALSE*/)\r
456         // Inserts a new menu item at the specified position in a menu.\r
457         {\r
458                 assert(IsMenu(m_hMenu));\r
459                 assert(lpMenuItemInfo);\r
460                 lpMenuItemInfo->cbSize = GetSizeofMenuItemInfo();\r
461                 return ::InsertMenuItem(m_hMenu, uItem, fByPos, lpMenuItemInfo);\r
462         }\r
463         \r
464         inline BOOL CMenu::LoadMenu(LPCTSTR lpszResourceName)\r
465         // Loads the menu from the specified windows resource.\r
466         {\r
467                 assert(NULL == m_hMenu);\r
468                 assert(lpszResourceName);\r
469                 m_hMenu = ::LoadMenu(GetApp()->GetResourceHandle(), lpszResourceName);\r
470                 if (m_hMenu) AddToMap();\r
471                 return NULL != m_hMenu;\r
472         }\r
473 \r
474         inline BOOL CMenu::LoadMenu(UINT uIDResource)\r
475         // Loads the menu from the specified windows resource.\r
476         {\r
477                 assert(NULL == m_hMenu);\r
478                 m_hMenu = ::LoadMenu(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(uIDResource));\r
479                 if (m_hMenu) AddToMap();\r
480                 return NULL != m_hMenu;\r
481         }\r
482 \r
483         inline BOOL CMenu::LoadMenuIndirect(const void* lpMenuTemplate)\r
484         // Loads the specified menu template and assigns it to this CMenu.\r
485         {\r
486                 assert(NULL == m_hMenu);\r
487                 assert(lpMenuTemplate);\r
488                 m_hMenu = ::LoadMenuIndirect(lpMenuTemplate);\r
489                 if (m_hMenu) AddToMap();\r
490                 return NULL != m_hMenu;\r
491         }       \r
492 \r
493         inline BOOL CMenu::ModifyMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem /*= 0*/, LPCTSTR lpszNewItem /*= NULL*/)\r
494         // Changes an existing menu item. This function is used to specify the content, appearance, and behavior of the menu item.\r
495         {\r
496                 assert(IsMenu(m_hMenu));\r
497                 return ::ModifyMenu(m_hMenu, uPosition, uFlags, uIDNewItem, lpszNewItem);\r
498         }\r
499 \r
500         inline BOOL CMenu::ModifyMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, const CBitmap* pBmp)\r
501         // Changes an existing menu item. This function is used to specify the content, appearance, and behavior of the menu item.\r
502         {\r
503                 assert(IsMenu(m_hMenu));\r
504                 assert(pBmp);\r
505                 return ::ModifyMenu(m_hMenu, uPosition, uFlags, uIDNewItem, (LPCTSTR)pBmp->GetHandle());\r
506         }\r
507 \r
508         inline BOOL CMenu::RemoveMenu(UINT uPosition, UINT uFlags)\r
509         // Deletes a menu item or detaches a submenu from the menu.\r
510         {\r
511                 assert(IsMenu(m_hMenu));\r
512                 return ::RemoveMenu(m_hMenu, uPosition, uFlags);\r
513         }\r
514 \r
515         inline BOOL CMenu::SetDefaultItem(UINT uItem, BOOL fByPos /*= FALSE*/)\r
516         //  sets the default menu item for the menu.\r
517         {\r
518                 assert(IsMenu(m_hMenu));\r
519                 return ::SetMenuDefaultItem(m_hMenu, uItem, fByPos);\r
520         }\r
521 \r
522         inline BOOL CMenu::SetMenuContextHelpId(DWORD dwContextHelpId)\r
523         // Associates a Help context identifier with the menu.\r
524         {\r
525                 assert(IsMenu(m_hMenu));\r
526                 return ::SetMenuContextHelpId(m_hMenu, dwContextHelpId);\r
527         }\r
528 \r
529         inline BOOL CMenu::SetMenuItemBitmaps(UINT uPosition, UINT uFlags, const CBitmap* pBmpUnchecked, const CBitmap* pBmpChecked)\r
530         // Associates the specified bitmap with a menu item.\r
531         {\r
532                 assert(IsMenu(m_hMenu));\r
533                 return ::SetMenuItemBitmaps(m_hMenu, uPosition, uFlags, *pBmpUnchecked, *pBmpChecked);\r
534         }\r
535 \r
536         inline BOOL CMenu::SetMenuItemInfo(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos /*= FALSE*/)\r
537         // Changes information about a menu item.\r
538         {\r
539                 assert(IsMenu(m_hMenu));\r
540                 assert(lpMenuItemInfo);\r
541                 lpMenuItemInfo->cbSize = GetSizeofMenuItemInfo();\r
542                 return ::SetMenuItemInfo(m_hMenu, uItem, fByPos, lpMenuItemInfo);\r
543         }\r
544                 \r
545         inline BOOL CMenu::TrackPopupMenu(UINT uFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect /*= 0*/)\r
546         // Displays a shortcut menu at the specified location and tracks the selection of items on the menu.\r
547         {\r
548                 assert(IsMenu(m_hMenu));\r
549                 HWND hWnd = pWnd? pWnd->GetHwnd() : 0;\r
550                 return ::TrackPopupMenu(m_hMenu, uFlags, x, y, 0, hWnd, lpRect);\r
551         }\r
552 \r
553         inline BOOL CMenu::TrackPopupMenuEx(UINT uFlags, int x, int y, CWnd* pWnd, LPTPMPARAMS lptpm)\r
554         // Displays a shortcut menu at the specified location and tracks the selection of items on the shortcut menu.\r
555         {\r
556                 assert(IsMenu(m_hMenu));\r
557                 HWND hWnd = pWnd? pWnd->GetHwnd() : 0;\r
558                 return ::TrackPopupMenuEx(m_hMenu, uFlags, x, y, hWnd, lptpm);\r
559         }\r
560 \r
561         inline BOOL CMenu::operator != (const CMenu& menu) const\r
562         // Returns TRUE if the two menu objects are not equal.\r
563         {\r
564                 return menu.m_hMenu != m_hMenu;\r
565         }\r
566 \r
567         inline BOOL CMenu::operator == (const CMenu& menu) const\r
568         // Returns TRUE of the two menu object are equal\r
569         {\r
570                 return menu.m_hMenu == m_hMenu;\r
571         }\r
572 \r
573         inline CMenu::operator HMENU () const\r
574         // Retrieves the menu's handle.\r
575         {\r
576                 return m_hMenu;\r
577         }\r
578         \r
579         \r
580         ///////////////////////////////////////\r
581         // Global functions\r
582         //\r
583         \r
584         inline CMenu* FromHandle(HMENU hMenu)\r
585         // Returns the CMenu object associated with the menu handle (HMENU).\r
586         {\r
587                 assert( GetApp() );\r
588                 CMenu* pMenu = GetApp()->GetCMenuFromMap(hMenu);\r
589                 if (::IsMenu(hMenu) && pMenu == 0)\r
590                 {\r
591                         GetApp()->AddTmpMenu(hMenu);\r
592                         pMenu = GetApp()->GetCMenuFromMap(hMenu);\r
593                 }\r
594                 return pMenu;\r
595         }\r
596 \r
597 }       // namespace Win32xx\r
598 \r
599 #endif  // _WIN32XX_MENU_H_\r
600 \r

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