BEGIN_MESSAGE_MAP(CPcmserverDlg, CDialog)
//
{{AFX_MSG_MAP(CPcmserverDlg)
...
ON_MESSAGE(WM_SYSTEMTRAY, OnSystemTray)
...
//
}}AFX_MSG_MAP
END_MESSAGE_MAP()
LRESULT C
***
Dlg::OnSystemTray(WPARAM wParam, LPARAM lParam)
{
switch
( lParam )
{
case
WM_LBUTTONDOWN:
{
this
->
ShowWindow(SW_NORMAL);
DeleteTray();
//
销毁Tray
}
break
;
case
WM_RBUTTONDOWN:
{
//
右键弹出托盘的菜单
CMenu menu;
menu.LoadMenu(IDR_TRAYMENU);
POINT pt;
::GetCursorPos(
&
pt);
menu.GetSubMenu(
0
)
->
TrackPopupMenu(TPM_LEFTALIGN
|
TPM_RIGHTALIGN, pt.x, pt.y, AfxGetMainWnd());
}
break
;
}
return
1
;
}
void
C
***
Dlg::DeleteTray()
{
NOTIFYICONDATA nid;
nid.cbSize
=
sizeof
( NOTIFYICONDATA );
nid.hWnd
=
m_hWnd;
nid.uID
=
IDR_MAINFRAME;
nid.uFlags
=
0
;
::Shell_NotifyIcon( NIM_DELETE,
&
nid );
}