#include "tlhelp32.h" #include "afxdialogex.h" void CTHSMFCAppDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } if (nID == SC_MINIMIZE) { //用我们自己的消息响应最小化事件 ToMini(); } else { CDialogEx::OnSysCommand(nID, lParam); } } void CTHSMFCAppDlg::ToMini() { ShowWindow(SW_HIDE); NotifyIcon.cbSize = sizeof(NOTIFYICONDATA); NotifyIcon.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); NotifyIcon.hWnd = m_hWnd; lstrcpy(NotifyIcon.szTip, L"TEST"); NotifyIcon.uCallbackMessage = WM_NC; NotifyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; Shell_NotifyIcon(NIM_ADD, &NotifyIcon); }
LRESULT CTHSMFCAppDlg::OnNotifyMsg(WPARAM wparam, LPARAM lparam) //wParam接收的是图标的ID,而lParam接收的是鼠标的行为 { //if (wparam != IDR_MAINFRAME) // return 1; switch (lparam) { case WM_RBUTTONUP://右键起来时弹出快捷菜单,这里只有一个“关闭” { LPPOINT lpoint = new tagPOINT; ::GetCursorPos(lpoint);//得到鼠标位置 CMenu menu; menu.CreatePopupMenu();//声明一个弹出式菜单 //增加菜单项“关闭”,点击则发送消息WM_DESTROY给主窗口(已 //隐藏),将程序结束。 menu.AppendMenu(MF_STRING, WM_DESTROY, _T("关闭")); //确定弹出式菜单的位置 menu.TrackPopupMenu(TPM_LEFTALIGN, lpoint->x, lpoint->y, this); //资源回收 HMENU hmenu = menu.Detach(); menu.DestroyMenu(); delete lpoint; } break; case WM_LBUTTONDBLCLK://双击左键的处理 { this->ShowWindow(SW_SHOW);//简单的显示主窗口完事儿 } break; } return 0; }
时间: 2024-09-30 04:18:29