⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trayiconmenu.cpp

📁 mysee网络直播源代码Mysee Lite是Mysee独立研发的网络视频流媒体播放系统。在应有了P2P技术和一系列先进流媒体技术之后
💻 CPP
字号:
/*
 *  Openmysee
 *
 *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#include "stdafx.h"
#include ".\trayiconmenu.h"
#include <string.h>
#include <TCHAR.h>
#include <shellapi.h>
#include "MultiLanguageMgr.h"

CTrayIconMenu::CTrayIconMenu()
{
    MultiLanguage langDll;		//生成多语言数据
	m_curLanguage = langDll.GetCurLanguage();

	hWnd = NULL;
}

CTrayIconMenu::~CTrayIconMenu(void)
{

}

BOOL	CTrayIconMenu::ShowMenu(HWND hparent, const UINT_PTR*	p_cmdID, const TCHAR*	p_cmdstr)
{
	hWnd = hparent;
	if(p_cmdID == NULL || p_cmdstr == NULL)
		return FALSE;
	
	return ShowMenu(p_cmdID, p_cmdstr);
}

#define	MAX_MENUSTR	 256
HMENU	CTrayIconMenu::MakeMenu(const UINT*& p_cmdID, const TCHAR*& p_cmdstr)	
{
	HMENU hmenu = CreatePopupMenu();
	if(hmenu == NULL)
		return hmenu;

	TCHAR	m_strbuf[MAX_MENUSTR];	//存放菜单文字的缓冲区
	const	TCHAR	*p_oldstrh;
	MultiLanguage	LangDll;
	for(p_oldstrh = p_cmdstr, p_cmdstr = _tcschr(p_cmdstr, _T('*')) + 1; 
	*p_cmdID != ID_END; 
	p_cmdID++, p_oldstrh = p_cmdstr, p_cmdstr = _tcschr(p_cmdstr, _T('*')) + 1)
	{
		memset(m_strbuf, 0, sizeof(TCHAR)*MAX_MENUSTR);
		_tcsncpy(m_strbuf, p_oldstrh, 
			(p_cmdstr - p_oldstrh - 1) >= MAX_MENUSTR ? (MAX_MENUSTR - 1) : (p_cmdstr - p_oldstrh - 1));

		if(*p_cmdID == ID_POPUP)	//生成子菜单
		{
			p_cmdstr = _tcschr(p_cmdstr, _T('*')) + 1;
			p_cmdID++;
			HMENU hpopmenu = MakeMenu(p_cmdID, p_cmdstr);	//递归地生成子菜单
			if(hpopmenu == NULL)
			{
				DestroyMenu(hmenu);
				return NULL;
			}
			AppendMenu(hmenu, MF_STRING | MF_POPUP, (UINT_PTR) hpopmenu, LangDll.GetStringByStr(m_strbuf));
		}
		else if(*p_cmdID == ID_EXTERNAL)
		{
			p_cmdID++;
			if(*p_cmdID != 0)
				AppendMenu(hmenu, MF_STRING | MF_POPUP, *p_cmdID, LangDll.GetStringByStr(m_strbuf));
		}
		else if(*p_cmdID == ID_SEPERATOR)	//生成分隔线
		{
			AppendMenu(hmenu, MF_SEPARATOR, 0, NULL);
		}
		else if(*p_cmdID == ID_LANGUAGE)
		{
			AppendMenu(hmenu, MF_STRING | MF_POPUP, (UINT_PTR) MakeLanguageMenu(), LangDll.GetStringByStr(m_strbuf));
		}
		else	//生成一般的命令项
		{
			UINT m_addUI = MenuUI(*p_cmdID);
			AppendMenu(hmenu, MF_STRING | m_addUI, *p_cmdID, LangDll.GetStringByStr(m_strbuf));
		}
	}

	return hmenu;
}

void	CTrayIconMenu::ReleaseMenu(HMENU hmenu, const UINT_PTR*& p_cmdID)
{
	for(int i = 0; *p_cmdID != ID_END; p_cmdID++, i++)
	{
		if(*p_cmdID == ID_POPUP)
		{
			HMENU hsub = GetSubMenu(hmenu, i);
			assert(hsub != NULL);
			p_cmdID++;
			ReleaseMenu(hsub, p_cmdID);
		}
		else if(*p_cmdID == ID_EXTERNAL)
		{
			p_cmdID++;
			RemoveMenu(hmenu, i, MF_BYPOSITION);
			i--;
		}
	}
	DestroyMenu(hmenu);
}

BOOL	CTrayIconMenu::ShowMenu(const UINT_PTR* p_traycmd, const TCHAR* p_traystr)
{
	POINT curpoint;
	if(GetCursorPos(&curpoint) == FALSE)	//获得鼠标位置
		return FALSE;

	if (!p_traycmd || !p_traystr) //数据还没有准备好
		return FALSE;

	do
	{
		const UINT_PTR* p_tmptraycmd = p_traycmd;
		const TCHAR*	p_tmptraystr = p_traystr;
		h_popup = MakeMenu(p_tmptraycmd, p_tmptraystr);

		if(h_popup == NULL)
			return FALSE;

		UINT returncmd = TrackPopupMenuEx(h_popup, TPM_BOTTOMALIGN | TPM_RIGHTALIGN /*| TPM_NONOTIFY*/ | TPM_RETURNCMD |	TPM_LEFTBUTTON,
		 curpoint.x, curpoint.y, hWnd, NULL);	//鼠标位置在生成的菜单右下角
		DWORD ret = GetLastError();

		p_tmptraycmd = p_traycmd;
		ReleaseMenu(h_popup, p_tmptraycmd);

		if(returncmd == 0)
			return FALSE;

		if(MenuCommand(returncmd))
			break;
	}while(1);

	return TRUE;
}

BOOL	CTrayIconMenu::OnMenuPopup(HMENU hmenu, int pos)
{
	
	return FALSE;
}

BOOL	CTrayIconMenu::MenuCommand(UINT m_cmdID)
{
	if(m_cmdID >= TRAYWM_LANGUAGESTART && m_cmdID <= TRAYWM_LANGUAGEEND)//用户选择了语言切换,这是一个"EX"型命令处理函数
	{
        SendMessage(hWnd, WM_COMMAND, TRAYWM_LANGUAGECHANGE, 0);
		return OnSwitchLanguageEx(m_cmdID);
	}
	else
	{
		//这里处理普通的命令处理函数
		PostMessage(hWnd, WM_COMMAND, m_cmdID, 0);
		//普通命令处理函数将返回TRUE
		return TRUE;
	}
}

UINT	CTrayIconMenu::MenuUI(UINT m_cmdID)
{
	if(m_cmdID == m_curLanguage)
		return MF_CHECKED;

	return 0;
}

BOOL	CTrayIconMenu::OnSwitchLanguageEx(UINT m_language)
{
	LANGID langid;
	switch(m_language - TRAYWM_LANGUAGESTART )
	{
	case 0:	//gb
		langid = MAINLAND_LANG_ID;
		break;
	case 1:	//big5
		langid = TAIWAN_LANG_ID;
		break;
	case 2:	//english
		langid = DEFAULT_LANG_ID;
		break;
	default:
		langid = DEFAULT_LANG_ID;
	}

	m_curLanguage = langid;

	MultiLanguage LanguageDll;
	LanguageDll.SwitchLanguage(langid);

	return FALSE;	//表示重新显示菜单并处理命令					
}

HMENU	CTrayIconMenu::MakeLanguageMenu()
{
	MultiLanguage langDll;		//生成多语言数据

	LANGID id = m_curLanguage;

	UINT flags[3] = {MF_STRING, MF_STRING, MF_STRING};
	int index = 0;
	switch(id)
	{
	case MAINLAND_LANG_ID:	//gb
		index = 0;
		break;
	case TAIWAN_LANG_ID:	//big5
		index = 1;
		break;
	case DEFAULT_LANG_ID:	//english
		index = 2;
		break;
	default:
		index = 0;
	}

	flags[index] |= MF_CHECKED;

	HMENU h_langsubmenu = CreatePopupMenu();
	AppendMenu(h_langsubmenu, flags[0] , TRAYWM_LANGUAGESTART, langDll.GetStringByStr(_T("简体中文(&S)")));
	AppendMenu(h_langsubmenu, flags[1] , TRAYWM_LANGUAGESTART + 1, langDll.GetStringByStr(_T("繁体中文(&T)")));
	AppendMenu(h_langsubmenu, flags[2] , TRAYWM_LANGUAGESTART + 2, langDll.GetStringByStr(_T("英文(&E)")));
	return h_langsubmenu;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -