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 _InsertMenuItem(UINT uItem, BOOL fByPosition, LPCMENUITEMINFO lpmii){
36 return ( InsertMenuItem(m_hMenu, uItem, fByPosition, lpmii) == TRUE );
38 bool _InsertMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, lpctstr_t lpNewItem){
39 return ( InsertMenu(m_hMenu, uPosition, uFlags, uIDNewItem, lpNewItem) == TRUE );
43 if ( !m_bAttachedMenu )
44 if ( ::DestroyMenu(m_hMenu) == FALSE )
45 windows_menu_exception("::DestroyMenu() Returned Error.");
52 m_bAttachedMenu = false;
53 m_hMenu = ::CreateMenu();
54 if ( m_hMenu == NULL )
55 windows_menu_exception("::CreateMenu() Returned Error.");
57 menu(HMENU hMenuAttach){
58 m_bAttachedMenu = true;
59 m_hMenu = hMenuAttach;
61 virtual ~menu(){ destroy_menu(); }
64 void attach(HMENU hMenuAttach){
67 m_bAttachedMenu = true;
68 m_hMenu = hMenuAttach;
70 void attach(const menu& menu_in){
73 m_bAttachedMenu = true;
74 m_hMenu = menu_in.m_hMenu;
79 bool insert(unsigned int index, lpctstr_t szText, UINT itemId=0){ return _InsertMenu(index, MF_BYPOSITION, itemId, szText); }
80 bool insert_separater(unsigned int index){ return _InsertMenu(index, MF_BYPOSITION | MF_SEPARATOR, NULL, NULL); }
82 bool insert_byid(unsigned int before_id, lpctstr_t szText, UINT itemId=0){ return _InsertMenu(before_id, MF_BYCOMMAND, itemId, szText); }
83 bool insert_separater_byid(unsigned int before_id){ return _InsertMenu(before_id, MF_BYCOMMAND | MF_SEPARATOR, NULL, NULL); }
85 bool add(lpctstr_t szText, UINT itemId=0){ return insert(-1, szText, itemId); }
86 bool add_separater(){ return insert_separater(-1); }
87 bool add_sep(){ return add_separater(); }
91 HMENU get_hmenu(){ return m_hMenu; }
92 operator HMENU (){ return get_hmenu(); }
95 ////////////////////////////////////////////////////////////////
99 #endif//__SFJP_ROAST_EX__windows__menu_HPP__