BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { cs.style =WS_POPUP;//使主窗口不可见 cs.dwExStyle |=WS_EX_TOOLWINDOW;//不显示任务按钮 return CFrameWnd::PreCreateWindow(cs); } |
typedef struct _NOTIFYICONDATA { DWORD cbSize; HWND hWnd; UINT uID; UINT uFlags; UINT uCallbackMessage; HICON hIcon; charszTip[64]; } NOTIFYICONDATA |
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { NOTIFYICONDATA tnd; tnd.cbSize=sizeof(NOTIFYICONDATA); tnd.hWnd=this->m_hWnd; tnd.uID=IDR_MAINFRAME; tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; tnd.uCallbackMessage=WM_MYMESSAGE; file://用户自定义的消息,即鼠标在任务栏上程序图标上动作时图标发送的消息 tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME)); strcpy(tnd.szTip,"测试程序");//图标提示为"测试程序" Shell_NotifyIcon(NIM_ADD,&tnd);//向任务栏添加图标 } |
void CMainFrame::OnMYMESSAGE(WPARAM wParam,LPARAM lParam) { UINT uID;//发出该消息的图标的ID UINT uMouseMsg;//鼠标动作 POINT pt; uID=(UINT) wParam; uMouseMsg=(UINT) lParam; if(uMouseMsg==WM_RBUTTONDOWN)//如果是单击右键 { switch(uID) { case IDR_MAINFRAME://如果是我们的图标 GetCursorPos(&pt);//取得鼠标位置 AfxGetApp( )-> m_pMainWnd->ShowWindow(SW_SHOWNORMAL);//显示程序窗口 break; default: } } return; } |
void CMainFrame::~CmainFrame() { NOTIFYICONDATA tnid; tnid.cbSize=sizeof(NOTIFYICONDATA); tnid.hWnd=this->m_hWnd; tnid.uID=IDR_MAINFRAME;//保证删除的是我们的图标 Shell_NotifyIcon(NIM_DELETE,&tnid); } |
文章评论(0条评论)
登录后参与讨论