VC中使程序最小化到系统托盘区

文章转载自:http://blog.csdn.net/zltpc007/article/details/2026560

=============================================

//定义托盘图标结构体
NOTIFYICONDATA nid; 

#define WM_ICONNOTIFY WM_USER + 909 //图标响应消息(lParam)
#define ID_TASKBARICON 100 //参数(wParam)

//初始化系统托盘图标 
void OnBtnMinimize() 
{ 
//初始化系统托盘图标 
nid.cbSize = sizeof(NOTIFYICONDATA); 
nid.hWnd = m_hWnd;; 
nid.uID = ID_TASKBARICON; //发出的消息中的wParam参数 
nid.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP; 
nid.uCallbackMessage 
= WM_ICONNOTIFY; //点击托盘图标系统发出的消息(即发出的消息中的lParam参数)
nid.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_HIS_COMM)); //图标文件
strcpy(nid.szTip, "我的程序"); 
Shell_NotifyIcon(NIM_ADD, &nid); //加入图标
ShowWindow(SW_HIDE); //隐藏窗体
}

//手工添加消息处理函数
afx_msg LRESULT OnNotifyIcon(WPARAM wParam, LPARAM lParam);

ON_MESSAGE(WM_ICONNOTIFY, OnNotifyIcon)

//双击系统托盘,使程序正常化
LRESULT OnNotifyIcon(WPARAM wParam, LPARAM lParam)
{
POINT rpoint; 
CMenu tmenu; 
GetCursorPos(&rpoint); 

//如果在托盘图标上双击左键 
if ( ( wParam == ID_TASKBARICON ) && ( lParam == WM_LBUTTONDBLCLK ) ) 
{
ShowWindow(SW_SHOW); //显示窗体 
Shell_NotifyIcon(NIM_DELETE, &nid); //删除系统托盘图标 
}

//如果在托盘图标上单击右键
if ( ( wParam == ID_TASKBARICON ) && ( lParam == WM_RBUTTONDOWN ) ) 
{
tmenu.LoadMenu(IDR_MAINFRAME); //加载系统主菜单
SetForegroundWindow(); //将程序置于桌面顶部
//在点击图标处弹出系统菜单的第一项
tmenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, 
rpoint.x, rpoint.y, this); 
}
return 0;
}

你可能感兴趣的:(shell,user,delete)