diff options
author | Hendrik Leppkes <h.leppkes@gmail.com> | 2013-05-11 19:27:57 +0400 |
---|---|---|
committer | Hendrik Leppkes <h.leppkes@gmail.com> | 2013-05-11 19:27:57 +0400 |
commit | 2fc3656e0631ef4e877e23e78b0ef35652e7a4e8 (patch) | |
tree | 22102306bb32facb6fefdccfab3d9061ca7f75e0 | |
parent | 8e6e10c20e3725e34fddbb00c8667632d302209d (diff) |
Add CPopupMenu helper class
-rw-r--r-- | common/DSUtilLite/DSUtilLite.vcxproj | 2 | ||||
-rw-r--r-- | common/DSUtilLite/DSUtilLite.vcxproj.filters | 6 | ||||
-rw-r--r-- | common/DSUtilLite/PopupMenu.cpp | 68 | ||||
-rw-r--r-- | common/DSUtilLite/PopupMenu.h | 34 |
4 files changed, 110 insertions, 0 deletions
diff --git a/common/DSUtilLite/DSUtilLite.vcxproj b/common/DSUtilLite/DSUtilLite.vcxproj index 537a2383..8361e796 100644 --- a/common/DSUtilLite/DSUtilLite.vcxproj +++ b/common/DSUtilLite/DSUtilLite.vcxproj @@ -80,6 +80,7 @@ </ItemDefinitionGroup> <ItemGroup> <ClInclude Include="BaseDSPropPage.h" /> + <ClInclude Include="PopupMenu.h" /> <ClInclude Include="BaseTrayIcon.h" /> <ClInclude Include="ByteParser.h" /> <ClInclude Include="DeCSS\CSSauth.h" /> @@ -99,6 +100,7 @@ </ItemGroup> <ItemGroup> <ClCompile Include="BaseDSPropPage.cpp" /> + <ClCompile Include="PopupMenu.cpp" /> <ClCompile Include="BaseTrayIcon.cpp" /> <ClCompile Include="ByteParser.cpp" /> <ClCompile Include="DeCSS\CSSauth.cpp" /> diff --git a/common/DSUtilLite/DSUtilLite.vcxproj.filters b/common/DSUtilLite/DSUtilLite.vcxproj.filters index 3a63b3e7..9073b986 100644 --- a/common/DSUtilLite/DSUtilLite.vcxproj.filters +++ b/common/DSUtilLite/DSUtilLite.vcxproj.filters @@ -72,6 +72,9 @@ <ClInclude Include="BaseTrayIcon.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="PopupMenu.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="stdafx.cpp"> @@ -113,5 +116,8 @@ <ClCompile Include="BaseTrayIcon.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="PopupMenu.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project>
\ No newline at end of file diff --git a/common/DSUtilLite/PopupMenu.cpp b/common/DSUtilLite/PopupMenu.cpp new file mode 100644 index 00000000..044e3dbd --- /dev/null +++ b/common/DSUtilLite/PopupMenu.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2010-2013 Hendrik Leppkes + * http://www.1f0.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "stdafx.h" +#include "PopupMenu.h" + +CPopupMenu::CPopupMenu(void) + : order(0) +{ + m_hMenu = CreatePopupMenu(); +} + +CPopupMenu::~CPopupMenu(void) +{ + if (m_hMenu) + DestroyMenu(m_hMenu); +} + +HRESULT CPopupMenu::AddItem(UINT id, LPWSTR caption, BOOL checked, BOOL enabled) +{ + if (!m_hMenu) + return E_UNEXPECTED; + MENUITEMINFO mii; + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_ID | MIIM_STATE | MIIM_FTYPE | MIIM_STRING; + mii.fType = MFT_STRING; + mii.wID = id; + mii.fState = (checked ? MFS_CHECKED : 0) | (!enabled ? MFS_DISABLED : 0); + mii.dwTypeData = caption; + mii.cch = (UINT)wcslen(mii.dwTypeData); + InsertMenuItem(m_hMenu, order++, TRUE, &mii); + return S_OK; +} + +HRESULT CPopupMenu::AddSeparator() +{ + if (!m_hMenu) + return E_UNEXPECTED; + MENUITEMINFO mii; + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_TYPE; + mii.fType = MFT_SEPARATOR; + InsertMenuItem(m_hMenu, order++, TRUE, &mii); + return S_OK; +} + +HMENU CPopupMenu::Finish() +{ + HMENU hMenu = m_hMenu; + m_hMenu = NULL; + return hMenu; +} diff --git a/common/DSUtilLite/PopupMenu.h b/common/DSUtilLite/PopupMenu.h new file mode 100644 index 00000000..2bbc5745 --- /dev/null +++ b/common/DSUtilLite/PopupMenu.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010-2013 Hendrik Leppkes + * http://www.1f0.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +class CPopupMenu +{ +public: + CPopupMenu(void); + virtual ~CPopupMenu(void); + + HRESULT AddItem(UINT id, LPWSTR caption, BOOL checked = FALSE, BOOL enabled = TRUE); + HRESULT AddSeparator(); + HMENU Finish(); +private: + HMENU m_hMenu; + int order; +}; |