范圣帅 - 卡农的魔笛

卡迪的快乐生活

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#define WM_ICONMESSAGE (WM_USER+100)

//{{AFX_MSG(CMainFrame) 
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 
// NOTE - the ClassWizard will add and remove member functions here. 
//    DO NOT EDIT what you see in these blocks of generated code! 
afx_msg LRESULT OnIconMessage(WPARAM wparam,LPARAM lparam);//在这里声明一个消息处理函数 
//}}AFX_MSG

 

 

LRESULT CMiniBar::OnIconMessage(WPARAM wparam,LPARAM lparam) 
{ 
    UINT uID; 
    UINT uMouseMsg; 
    uID=(UINT)wparam; 
    uMouseMsg=(UINT)lparam; 
    if (uID==IDR_MAINFRAME) {
        switch(uMouseMsg) { 
            case WM_LBUTTONDOWN: 
               AfxMessageBox(L"Lbuttondown"); 
               break; 
            case WM_RBUTTONDOWN: 
               AfxMessageBox(L"Rbuttondown"); 
               break; 
            case WM_LBUTTONDBLCLK: 
               AfxGetMainWnd()->SendMessage(WM_CLOSE); 
               break; 
            default: 
               break; 
        } 
    } 
    return 0; 
} 
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) 
//{{AFX_MSG_MAP(CMainFrame) 
ON_WM_CREATE() 
ON_WM_TIMER() 
ON_MESSAGE(WM_ICON_MESSAGE, OnMyMessage) // 加进去的注意后面没分号 
//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
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_ICON_MESSAGE; 
 tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME)); 
 wcscpy(tnd.szTip,"测试程序");// 图标提示为"测试程序" 
 Shell_NotifyIcon(NIM_ADD,&tnd);// 向任务栏添加图标 
} 
void CMainFrame::OnDestroy() 
{ 
  CFrameWnd::OnDestroy(); 
  NOTIFYICONDATA tnid; 
  tnid.cbSize=sizeof(NOTIFYICONDATA); 
  tnid.hWnd=this->m_hWnd; 
  //tnid.uID=IDR_MAINFRAME; 
  Shell_NotifyIcon(NIM_DELETE,&tnid);
}

 隐藏任务栏图标

CoInitialize(NULL);
ITaskbarList* plist=NULL;
HRESULT hr=CoCreateInstance         (CLSID_TaskbarList,NULL,CLSCTX_ALL,IID_ITaskbarList,(PVOID*)&plist);
hr=plist->HrInit();
hr=plist->DeleteTab(this->GetSafeHwnd());
plist->Release();
CoUninitialize();

 

posted on 2013-01-21 12:32  范圣帅  阅读(2024)  评论(0编辑  收藏  举报