vC++ 系統托盤圖示實現
阿新 • • 發佈:2019-01-02
- LRESULT ***Frame/*or Dialog*/::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message){
- case MYWM_NOTIFYICON:
- //如果是使用者定義的訊息
- if(lParam==WM_LBUTTONDBLCLK)
- {
- //滑鼠雙擊時主窗口出現
- AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
- }
- else if(lParam==WM_RBUTTONDOWN){
- //滑鼠右鍵單擊彈出選單
- CMenu menu;
- menu.LoadMenu(IDR_RIGHT_MENU);
- //載入事先定義的選單
- CMenu* pMenu=menu.GetSubMenu(0);
- CPoint pos;
- GetCursorPos(&pos);
- pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,pos.x,pos.y,AfxGetMainWnd());
- }
- break;
- case WM_SYSCOMMAND:
- //如果是系統訊息
- switch(wParam){
- case SC_MINIMIZE:
- //接收到最小化訊息時主視窗隱藏
- ShowWindow(SW_HIDE);
- return 0;
- break;
- case SC_CLOSE :
- ::Shell_NotifyIcon(NIM_DELETE,&m_nid); //關閉時刪除系統托盤圖示
- break;
- }
- break;
- }
- return CFrameWnd/*or CDialog*/::WindowProc(message, wParam, lParam); //其實就是呼叫父類的訊息處理函式
- }