码迷,mamicode.com
首页 > 其他好文 > 详细

托盘的实现

时间:2015-05-14 08:38:42      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

#define WM_TRAYICON_MSG (WM_USER+100)
public:
    afx_msg void OnBnClickedButTuo();
    BOOL TrayMyIcon(BOOL bAdd=TRUE);
    LRESULT OnTrayCallBackMsg(WPARAM wparam, LPARAM lparam);
//按钮事件,实现托盘
void CWuMaDlg::OnBnClickedButTuo()
{
    // TODO:  在此添加控件通知处理程序代码
    TrayMyIcon();
}
//托盘实现
BOOL CWuMaDlg::TrayMyIcon(BOOL bAdd)
{
    BOOL bRet = FALSE;
    NOTIFYICONDATA tnd;
    tnd.cbSize = sizeof(NOTIFYICONDATA);
    tnd.hWnd = m_hWnd;
    tnd.uID = IDR_MAINFRAME;
    if (bAdd == TRUE) {
        tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
        tnd.uCallbackMessage = WM_TRAYICON_MSG;
        tnd.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
        _tcscpy_s(tnd.szTip, sizeof(tnd.szTip), _T("無聊辅助v1.0"));
        ShowWindow(SW_MINIMIZE);
        ShowWindow(SW_HIDE);
        bRet = Shell_NotifyIcon(NIM_ADD, &tnd);
    }
    else{
        ShowWindow(SW_SHOWNA);
        SetForegroundWindow();
        bRet = Shell_NotifyIcon(NIM_DELETE, &tnd);
    }
    return bRet;
}
//消息响应
LRESULT CWuMaDlg::OnTrayCallBackMsg(WPARAM wparam, LPARAM lparam)
{
    switch (lparam)
    {
    case WM_RBUTTONUP:
    {
                         CMenu mMenu, *pMenu = NULL;
                         CPoint pt;
                         mMenu.LoadMenu(IDR_MENU1);
                         pMenu = mMenu.GetSubMenu(0);
                         GetCursorPos(&pt);
                         SetForegroundWindow();
                         pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, this);
                         break;
    }
    case WM_LBUTTONDBLCLK:
        ShowWindow(SW_RESTORE);
        SetForegroundWindow();
        TrayMyIcon(FALSE);
        break;
    default:break;
    }
    return NULL;
}
//右键显示界面
void CWuMaDlg::OnMenuShow()
{
    ShowWindow(SW_RESTORE);
    TrayMyIcon(FALSE);
}

//退出
void CWuMaDlg::OnMenuExit()
{
    TrayMyIcon(FALSE);
    OnCancel();
}

 

托盘的实现

标签:

原文地址:http://www.cnblogs.com/wumac/p/4502328.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!