系统托盘菜单栏的文本怎么输进去的?怎么修改标题啊?
解决方案 »
- 如何在MFC多文档中同时显示多个视图
- 如何使用MSCOMM控件发送数组到串口
- 谁有www.vckbase.com 或者 www.vccode.com 类视的网站代码啊???
- vc6的编译是不是存在问题?怎么老出莫名奇妙的问题?
- 关于进度框所在的对话框中的文本框变空的问题,多谢!
- 各位大侠,请教一个很重要的问题
- How to convert "const char* "to "unsigned short**" in VC++
- 关于MFC的CPen该部该释放问题?崩溃了!
- TCITEM结构中lParam有什么用处?
- 如何获得DLL中的函数及输入,输出参数
- 谁来告诉我这是什么控件(高分求助)?
- 编译DirectSound例子程序,提示libcp.lib找不到,VS2008已经把“\ML”模式给废了,那还有什么办法。
菜单你可以编辑在资源里面,用TrackPopupMenu显示。
动态修改菜单用SetMenuItemInfo。
#define WM_TRAYICON_NOTIFY WM_USER + 100
m_trayIcon.Create(this, WM_TRAYICON_NOTIFY, _T("Title"), AfxGetApp()->LoadIcon(IDR_MAINFRAME), IDR_MAINFRAME);//这第三个参数为托盘图标显示的标题.
WM_TRAYICON_NOTIFY为自定义消息.
afx_msg LRESULT OnTrayIconNotify(WPARAM wParam, LPARAM lParam);
ON_MESSAGE(WM_TRAYICON_NOTIFY, OnTrayIconNotify)CMenu m_menuTrayRight;
CMainFrame::CMainFrame()
{
HMENU hMenu = ::LoadMenu(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_SYSTRAY_MENU));
ASSERT(hMenu != NULL);
m_menuTrayRight.Attach(::GetSubMenu(hMenu,0));
::RemoveMenu(hMenu, 0, MF_BYPOSITION);
::DestroyMenu(hMenu);
}LRESULT CMainFrame::OnTrayIconNotify(WPARAM wParam, LPARAM lParam)
{
UINT uMouseMsg = (UINT)lParam; // mouse message that was sent.
switch(uMouseMsg)
{
case WM_LBUTTONDBLCLK:
{
...
}
break; case WM_RBUTTONUP: // 弹出菜单
{
CPoint pos;
GetCursorPos(&pos);
if(m_menuTrayRight.GetSafeHmenu() != NULL)
m_menuTrayRight.TrackPopupMenu(TPM_RIGHTBUTTON|TPM_RIGHTALIGN, pos.x, pos.y, this); ::PostMessage(m_hWnd,WM_NULL, 0, 0);
}
break; case WM_LBUTTONUP:
{
...
}
break; return 1;
}
return 0;
}大致就是这样做的,请参考.
CTrayNotify::CTrayNotify()
{
memset((void*)&m_nid,0,sizeof(m_nid));
m_nid.cbSize=sizeof(m_nid);
m_bShow=FALSE;}
/*---------------------------------------------------------------------------------
*/
CTrayNotify::~CTrayNotify()
{
ShowIcon(FALSE);
}
/*---------------------------------------------------------------------------------
*/
void CTrayNotify::SetIcon(const HICON hIcon,BOOL bEnable)
{
m_nid.hIcon=hIcon;
if(bEnable)
m_nid.uFlags|=NIF_ICON;
}
/*---------------------------------------------------------------------------------
*/
HICON CTrayNotify::GetIcon() const
{
return m_nid.hIcon;
}
/*---------------------------------------------------------------------------------
*/
void CTrayNotify::SetMsg(UINT uMsg,BOOL bEnable)
{
m_nid.uCallbackMessage=uMsg;
if(bEnable)
m_nid.uFlags|=NIF_MESSAGE;}
/*---------------------------------------------------------------------------------
*/
UINT CTrayNotify::GetMsg()
{
return m_nid.uCallbackMessage;
}
/*---------------------------------------------------------------------------------
*/
void CTrayNotify::SetTip(const char *szTip,BOOL bEnable)
{
lstrcpyn(m_nid.szTip,szTip,sizeof(m_nid.szTip));
if(bEnable)
m_nid.uFlags|=NIF_TIP;
}
/*---------------------------------------------------------------------------------
*/
void CTrayNotify::GetTip(char *szTip,UINT uTxtLen) const
{
lstrcpyn(szTip,m_nid.szTip,uTxtLen);
}
/*---------------------------------------------------------------------------------
*/
BOOL CTrayNotify::SetHwnd(const HWND hWnd)
{
BOOL bRet=TRUE;
if(IsWindow(hWnd))
{
m_nid.hWnd=hWnd;
}
else
bRet=FALSE;
return bRet;
}
/*---------------------------------------------------------------------------------
*/
HWND CTrayNotify::GetHwnd() const
{
return m_nid.hWnd;
}
/*---------------------------------------------------------------------------------
*/
void CTrayNotify::SetID(const UINT uID)
{
m_nid.uID=uID;
}
/*---------------------------------------------------------------------------------
*/
UINT CTrayNotify::GetID() const
{
return m_nid.uID;
}
/*---------------------------------------------------------------------------------
*/
BOOL CTrayNotify::Refresh()
{
return Shell_NotifyIcon(NIM_MODIFY,&m_nid);
}
/*---------------------------------------------------------------------------------
*/
BOOL CTrayNotify::ShowIcon(BOOL bShow)
{
BOOL bRet=FALSE;
if(m_bShow)
{
if(!bShow)
{
bRet=Shell_NotifyIcon(NIM_DELETE,&m_nid);
}
}
else
{
if(bShow)
bRet=Shell_NotifyIcon(NIM_ADD,&m_nid);
}
if(bRet)
{
m_bShow=bShow;
}
return bRet;}
/*---------------------------------------------------------------------------------
*/
BOOL CTrayNotify::Modify(const NOTIFYICONDATA& nid)
{
CopyMemory((void*)&m_nid,(void*)&nid,sizeof(nid));
return Shell_NotifyIcon(NIM_MODIFY,&m_nid);
}
/*---------------------------------------------------------------------------------
*/
void CTrayNotify::GetNid(NOTIFYICONDATA* pNid) const
{
CopyMemory((void*)pNid,(void*)&m_nid,sizeof(m_nid));
}
/*---------------------------------------------------------------------------------
*/
BOOL CTrayNotify::IsIconShow() const
{
return m_bShow;
}
/*---------------------------------------------------------------------------------
*/
void CTrayNotify::Reset()
{
ShowIcon(FALSE);
memset((void*)&m_nid,0,sizeof(m_nid));
}
/*---------------------------------------------------------------------------------
*/
void CTrayNotify::SetFlag(UINT uFlag)
{
m_nid.uFlags=uFlag;
}
/*---------------------------------------------------------------------------------
*/
UINT CTrayNotify::GetFlag() const
{
return m_nid.uFlags;
}