sprint 1-alpha
|
00001 /****************************************************************************** 00002 * GTL: GUI Template Library 00003 * A Cross Platform C++ Wrapper for Win32 users 00004 * Copyright (C) 2007-2011 Paolo Medici (www.pmx.it) 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 #ifndef _SPRINT_MENU_H 00023 #define _SPRINT_MENU_H 00024 00028 namespace sprint { 00029 namespace gtl { 00030 00031 // fw 00032 template <bool t_bManaged> class CMenuT; 00033 00034 // non rilascia il menu 00035 typedef CMenuT<false> CMenuHandle; 00036 00037 // Rilascia il menu 00038 typedef CMenuT<true> CMenu; 00039 00041 template <bool t_bManaged> 00042 class CMenuT { 00043 HMENU m_hMenu; 00044 public: 00045 CMenuT(HMENU hmenu = NULL) : m_hMenu(hmenu) { } 00046 00048 bool Check(int id, bool status) 00049 { 00050 return ::CheckMenuItem(m_hMenu, id, 00051 MF_BYCOMMAND | (status ? MF_CHECKED : MF_UNCHECKED)); 00052 } 00053 00054 ~CMenuT() 00055 { 00056 if(t_bManaged && m_hMenu != NULL) 00057 DestroyMenu(); 00058 } 00059 00060 CMenuT<t_bManaged>& operator =(HMENU hMenu) 00061 { 00062 Attach(hMenu); 00063 return *this; 00064 } 00065 00066 void Attach(HMENU hMenuNew) 00067 { 00068 if(t_bManaged && m_hMenu != NULL && m_hMenu != hMenuNew) 00069 ::DestroyMenu(m_hMenu); 00070 m_hMenu = hMenuNew; 00071 } 00072 00073 HMENU Detach() 00074 { 00075 HMENU hMenu = m_hMenu; 00076 m_hMenu = NULL; 00077 return hMenu; 00078 } 00079 00080 operator HMENU() const { return m_hMenu; } 00081 00082 bool IsNull() const { return (m_hMenu == NULL); } 00083 00084 BOOL IsMenu() const 00085 { 00086 return ::IsMenu(m_hMenu); 00087 } 00088 00089 // Create/destroy methods 00090 BOOL CreateMenu() 00091 { 00092 m_hMenu = ::CreateMenu(); 00093 return (m_hMenu != NULL) ? TRUE : FALSE; 00094 } 00095 00096 BOOL CreatePopupMenu() 00097 { 00098 m_hMenu = ::CreatePopupMenu(); 00099 return (m_hMenu != NULL) ? TRUE : FALSE; 00100 } 00101 00102 #ifndef _WIN32_WCE 00103 BOOL LoadMenuIndirect(const void* lpMenuTemplate) 00104 { 00105 m_hMenu = ::LoadMenuIndirect(lpMenuTemplate); 00106 return (m_hMenu != NULL) ? TRUE : FALSE; 00107 } 00108 #endif // !_WIN32_WCE 00109 00110 BOOL DestroyMenu() 00111 { 00112 if (m_hMenu == NULL) 00113 return FALSE; 00114 BOOL bRet = ::DestroyMenu(m_hMenu); 00115 if(bRet) 00116 m_hMenu = NULL; 00117 return bRet; 00118 } 00119 00120 // Menu Operations 00121 BOOL DeleteMenu(UINT nPosition, UINT nFlags) 00122 { 00123 return ::DeleteMenu(m_hMenu, nPosition, nFlags); 00124 } 00125 00126 UINT CheckMenuItem(UINT nIDCheckItem, UINT nCheck) 00127 { 00128 return (UINT)::CheckMenuItem(m_hMenu, nIDCheckItem, nCheck); 00129 } 00130 00132 UINT EnableMenuItem(UINT nIDEnableItem, UINT nEnable) 00133 { 00134 return ::EnableMenuItem(m_hMenu, nIDEnableItem, nEnable); 00135 } 00136 00137 CMenuHandle GetSubMenu(int index) 00138 { 00139 return CMenuHandle(::GetSubMenu(m_hMenu, index)); 00140 } 00141 00142 bool InsertItem(UINT uItem, bool fByPosition, const MENUITEMINFO & mii) 00143 { 00144 return ::InsertMenuItem(m_hMenu, uItem, fByPosition, &mii); 00145 } 00146 00147 bool Append(UINT uFlags, UINT_PTR uIDNewItem, LPCTSTR lpNewItem) 00148 { 00149 return ::AppendMenu(m_hMenu, uFlags, uIDNewItem, lpNewItem); 00150 } 00151 00153 bool Add(CMenuHandle handle, LPCTSTR lpNewItem) 00154 { 00155 return ::AppendMenu(m_hMenu, MF_STRING | MF_POPUP, (UINT_PTR)(HMENU) handle, lpNewItem); 00156 } 00157 00158 bool AddSeparator() 00159 { 00160 return ::AppendMenu(m_hMenu, MF_SEPARATOR,0,0); 00161 } 00163 bool Add(int uIDNewItem, LPCTSTR lpNewItem) 00164 { 00165 return ::AppendMenu(m_hMenu, MF_STRING, uIDNewItem, lpNewItem); 00166 } 00167 00168 00169 }; 00170 00171 } 00172 } 00173 00174 #endif