jackba / wy-internal-system

Automatically exported from code.google.com/p/wy-internal-system
0 stars 0 forks source link

MFC NotifyIcon #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
ON_MESSAGE(WM_NOTIFY_ICON, OnNotifyIcon)

    //notify
    //...
    notifyIconData.cbSize = sizeof(NOTIFYICONDATA);
    notifyIconData.hIcon = ::AfxGetApp()->LoadIcon(IDI_ICON_MU);
    notifyIconData.hWnd = m_hWnd;
    lstrcpy(notifyIconData.szTip, L"GREAT MUFC!");
    notifyIconData.uCallbackMessage = WM_NOTIFY_ICON;
    notifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
    Shell_NotifyIcon(NIM_ADD, &notifyIconData);

    //547 X 412
    ::SetWindowPos(this->m_hWnd, NULL, 0, 0, 547, 412, 0);

LRESULT CPicturedButtonDlg::OnNotifyIcon(WPARAM wParam, LPARAM lParam)
{
    if (lParam == WM_RBUTTONUP)
    {
        CMenu menu;
        menu.CreatePopupMenu();

        CBitmap bmpBG;
        bmpBG.LoadBitmapW(IDB_CLOSE);
        CBitmap bmpSky;
        bmpSky.LoadBitmapW(IDB_MUFC);

        menu.AppendMenuW(MF_BITMAP, WM_DESTROY, &bmpBG);
        menu.AppendMenuW(MF_STRING, WM_MOVE, L"connect");
//      menu.AppendMenuW(MF_BITMAP, WM_MOVE, &bmpSky);
        menu.AppendMenuW(MF_STRING, WM_MOVE, L"History");
        menu.AppendMenuW(MF_STRING, WM_DESTROY, L"Exit");
        LPPOINT lpPoint = new tagPOINT;
        ::GetCursorPos(lpPoint);
        menu.TrackPopupMenu(TPM_LEFTALIGN, lpPoint->x, lpPoint->y, this, new CRect(0, 0, 50, 50));
        HMENU h = menu.Detach();
        menu.DestroyMenu();
        delete lpPoint;

        return S_OK;
    }
    if (lParam == WM_LBUTTONDOWN)
    {
        ShowWindow(SW_SHOW);
        ModifyStyleEx(0, WS_EX_TOPMOST);
    }

    return S_OK;
}

void CPicturedButtonDlg::OnHideWindow()
{
    ShowWindow(SW_HIDE); 
}

void CPicturedButtonDlg::OnDestroy()
{
    CDialog::OnDestroy();

    Shell_NotifyIcon(NIM_DELETE, &notifyIconData);
}

Original issue reported on code.google.com by Giggs...@gmail.com on 23 Feb 2012 at 8:42

GoogleCodeExporter commented 9 years ago
public:
    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    NOTIFYICONDATA notifyIconData;
    LRESULT OnNotifyIcon(WPARAM wParam, LPARAM lParam);
    #define WM_NOTIFY_ICON WM_USER + 1
    void OnHideWindow();
public:
    afx_msg void OnBnClickedButton4();
public:
    afx_msg void OnDestroy();

Original comment by Giggs...@gmail.com on 23 Feb 2012 at 8:43

GoogleCodeExporter commented 9 years ago

Original comment by Giggs...@gmail.com on 23 Feb 2012 at 10:56