5 #ifndef __SFJP_ROAST_EX__windows__menu_HPP__
6 #define __SFJP_ROAST_EX__windows__menu_HPP__
15 /* typedef ::LPCTSTR lpctstr_t;
16 class windows_exception : public ::std::string
19 windows_exception(const char* s) : ::std::string(s) {}
20 windows_exception(const ::std::string& s) : ::std::string(s) {}
23 class windows_menu_exception : public windows_exception
26 windows_menu_exception(const char* s) : windows_exception(s) {}
27 windows_menu_exception(const ::std::string& s) : windows_exception(s) {}
30 /////////////////////////////////////////////////
35 bool _SetMenuItemInfo(UINT uItem, BOOL fByPosition, LPMENUITEMINFO lpmii){
36 return ( SetMenuItemInfo(m_hMenu, uItem, fByPosition, lpmii) == TRUE );
39 const ::HMENU m_hMenu;
41 const BOOL fByPosition;
43 menuitem(HMENU hMenu, UINT uItem_in, BOOL fByPosition_in)
44 : m_hMenu(hMenu), uItem(uItem_in), fByPosition(fByPosition_in) {}
51 bool _InsertMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, lpctstr_t lpNewItem){
52 return ( InsertMenu(m_hMenu, uPosition, uFlags, uIDNewItem, lpNewItem) == TRUE );
54 bool _InsertMenuItem(UINT uItem, BOOL fByPosition, LPCMENUITEMINFO lpmii){
55 return ( InsertMenuItem(m_hMenu, uItem, fByPosition, lpmii) == TRUE );
57 /*bool _SetMenuItemInfo(UINT uItem, BOOL fByPosition, LPMENUITEMINFO lpmii){
58 return ( SetMenuItemInfo(m_hMenu, uItem, fByPosition, lpmii) == TRUE );
62 if ( !m_bAttachedMenu )
63 if ( ::DestroyMenu(m_hMenu) == FALSE )
64 windows_menu_exception("::DestroyMenu() Returned Error.");
71 m_bAttachedMenu = false;
72 m_hMenu = ::CreateMenu();
73 if ( m_hMenu == NULL )
74 windows_menu_exception("::CreateMenu() Returned Error.");
76 menu(HMENU hMenuAttach){
77 m_bAttachedMenu = true;
78 m_hMenu = hMenuAttach;
80 virtual ~menu(){ destroy_menu(); }
83 void attach(HMENU hMenuAttach){
86 m_bAttachedMenu = true;
87 m_hMenu = hMenuAttach;
89 void attach(const menu& menu_in){
92 m_bAttachedMenu = true;
93 m_hMenu = menu_in.m_hMenu;
98 bool insert(unsigned int index, lpctstr_t szText, UINT itemId=0){ return _InsertMenu(index, MF_BYPOSITION, itemId, szText); }
99 bool insert_separater(unsigned int index){ return _InsertMenu(index, MF_BYPOSITION | MF_SEPARATOR, NULL, NULL); }
101 bool insert_byid(unsigned int before_id, lpctstr_t szText, UINT itemId=0){ return _InsertMenu(before_id, MF_BYCOMMAND, itemId, szText); }
102 bool insert_separater_byid(unsigned int before_id){ return _InsertMenu(before_id, MF_BYCOMMAND | MF_SEPARATOR, NULL, NULL); }
104 bool add(lpctstr_t szText, UINT itemId=0){ return insert(-1, szText, itemId); }
105 bool add_separater(){ return insert_separater(-1); }
106 bool add_sep(){ return add_separater(); }
108 bool attach_submenu(unsigned int index, HMENU hSubMenu){}
109 bool attach_submenu_byid(unsigned int itemid, HMENU hSubMenu){}
111 ///////////////////////////////////////////////
113 menuitem get(unsigned int index){ return menuitem(m_hMenu, index, TRUE); }
114 menuitem get_byid(UINT itemId){ return menuitem(m_hMenu, itemId, FALSE); }
115 menuitem operator [](unsigned int index){ return get(index); }
119 HMENU get_hmenu(){ return m_hMenu; }
120 operator HMENU (){ return get_hmenu(); }
123 ////////////////////////////////////////////////////////////////
127 #endif//__SFJP_ROAST_EX__windows__menu_HPP__