1、在CNBVSPConsoleDlg.cpp(视自身情况而定)
// 自定义消息类型
#define MYWM_NOTIFYICON WM_USER+100
2、在CNBVSPConsoleDlg.h中定义变量
NOTIFYICONDATA m_NotiIcon; //tray struct
3、在CNBVSPConsoleDlg::OnInitDialog()中加入代码
CString szToolTip;
m_NotiIcon.cbSize = sizeof(NOTIFYICONDATA);
m_NotiIcon.hWnd = this->m_hWnd;
m_NotiIcon.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
m_NotiIcon.uCallbackMessage = MYWM_NOTIFYICON; //用户定义的回调消息
szToolTip = popmenuTooltip;
strcpy(m_NotiIcon.szTip, popmenuTooltip);
m_NotiIcon.uID = IDR_MAINFRAME;
m_NotiIcon.hIcon = m_hIcon;
Shell_NotifyIcon(NIM_ADD, &m_NotiIcon);
4、在CNBVSPConsoleDlg::OnDestroy()中加入代码
Shell_NotifyIcon(NIM_DELETE, &m_NotiIcon);
5、重载WindowsProc处理消息(也可以自己添加MYWM_NOTIFYICON消息映射函数处理)
LRESULT CNBVSPConsoleDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case MYWM_NOTIFYICON: //如果是用户定义的消息
if(lParam==WM_RBUTTONDOWN)
{ //鼠标右键单击弹出选单
CMenu menu;
if(menu.LoadMenu(IDR_RIGHT_MENU))
{ // 载入事先定义的选单
...
}
}
case WM_SYSCOMMAND:
...
}
}