系统托盘菜单栏的文本怎么输进去的?怎么修改标题啊?

解决方案 »

  1.   

    系统托盘图标相关操作用Shell_NotifyIcon。
    菜单你可以编辑在资源里面,用TrackPopupMenu显示。
    动态修改菜单用SetMenuItemInfo。
      

  2.   

    CTrayIcon m_trayIcon;
    #define WM_TRAYICON_NOTIFY   WM_USER + 100
    m_trayIcon.Create(this, WM_TRAYICON_NOTIFY, _T("Title"), AfxGetApp()->LoadIcon(IDR_MAINFRAME), IDR_MAINFRAME);//这第三个参数为托盘图标显示的标题.
    WM_TRAYICON_NOTIFY为自定义消息.
    afx_msg LRESULT OnTrayIconNotify(WPARAM wParam, LPARAM lParam);
    ON_MESSAGE(WM_TRAYICON_NOTIFY, OnTrayIconNotify)CMenu  m_menuTrayRight;
    CMainFrame::CMainFrame()
    {
        HMENU  hMenu = ::LoadMenu(AfxGetInstanceHandle(),
    MAKEINTRESOURCE(IDR_SYSTRAY_MENU));
        ASSERT(hMenu != NULL);
        m_menuTrayRight.Attach(::GetSubMenu(hMenu,0));
        ::RemoveMenu(hMenu, 0, MF_BYPOSITION);
        ::DestroyMenu(hMenu);
    }LRESULT CMainFrame::OnTrayIconNotify(WPARAM wParam, LPARAM lParam)
    {
    UINT uMouseMsg = (UINT)lParam;  // mouse message that was sent.

    switch(uMouseMsg)
    {
    case WM_LBUTTONDBLCLK:
    {
        ...
          }
    break; case WM_RBUTTONUP: // 弹出菜单
    {
    CPoint pos;
    GetCursorPos(&pos);

    if(m_menuTrayRight.GetSafeHmenu() != NULL)
    m_menuTrayRight.TrackPopupMenu(TPM_RIGHTBUTTON|TPM_RIGHTALIGN, pos.x, pos.y, this); ::PostMessage(m_hWnd,WM_NULL, 0, 0);
    }
    break; case WM_LBUTTONUP:
    {
    ...
    }
    break; return 1;
    }
    return 0;
    }大致就是这样做的,请参考.
      

  3.   

    关于上面提到CTrayIcon类,网上可以很容易下载到.
      

  4.   

    我是个新手,有个程序如下,我找不到修改系统托盘右键菜单的代码段,以及如何修改菜单,请高手赐教!!!
    CTrayNotify::CTrayNotify()
    {
    memset((void*)&m_nid,0,sizeof(m_nid));
    m_nid.cbSize=sizeof(m_nid);
    m_bShow=FALSE;}
    /*---------------------------------------------------------------------------------
    */
    CTrayNotify::~CTrayNotify()
    {
    ShowIcon(FALSE);
    }
    /*---------------------------------------------------------------------------------
    */
    void CTrayNotify::SetIcon(const HICON hIcon,BOOL bEnable)
    {
    m_nid.hIcon=hIcon;
    if(bEnable)
    m_nid.uFlags|=NIF_ICON;
    }
    /*---------------------------------------------------------------------------------
    */
    HICON CTrayNotify::GetIcon() const
    {
    return m_nid.hIcon;
    }
    /*---------------------------------------------------------------------------------
    */
    void CTrayNotify::SetMsg(UINT uMsg,BOOL bEnable)
    {
    m_nid.uCallbackMessage=uMsg;
    if(bEnable)
    m_nid.uFlags|=NIF_MESSAGE;}
    /*---------------------------------------------------------------------------------
    */
    UINT CTrayNotify::GetMsg()
    {
    return m_nid.uCallbackMessage;
    }
    /*---------------------------------------------------------------------------------
    */
    void CTrayNotify::SetTip(const char *szTip,BOOL bEnable)
    {
    lstrcpyn(m_nid.szTip,szTip,sizeof(m_nid.szTip));
    if(bEnable)
    m_nid.uFlags|=NIF_TIP;
    }
    /*---------------------------------------------------------------------------------
    */
    void CTrayNotify::GetTip(char *szTip,UINT uTxtLen) const
    {
    lstrcpyn(szTip,m_nid.szTip,uTxtLen);
    }
    /*---------------------------------------------------------------------------------
    */
    BOOL CTrayNotify::SetHwnd(const HWND hWnd)
    {
    BOOL bRet=TRUE;
    if(IsWindow(hWnd))
    {
    m_nid.hWnd=hWnd;
    }
    else
    bRet=FALSE;
    return bRet;
    }
    /*---------------------------------------------------------------------------------
    */
    HWND CTrayNotify::GetHwnd() const
    {
    return m_nid.hWnd;
    }
    /*---------------------------------------------------------------------------------
    */
    void CTrayNotify::SetID(const UINT uID)
    {
    m_nid.uID=uID;
    }
    /*---------------------------------------------------------------------------------
    */
    UINT CTrayNotify::GetID() const
    {
    return m_nid.uID;
    }
    /*---------------------------------------------------------------------------------
    */
    BOOL CTrayNotify::Refresh()
    {
    return Shell_NotifyIcon(NIM_MODIFY,&m_nid);
    }
    /*---------------------------------------------------------------------------------
    */
    BOOL CTrayNotify::ShowIcon(BOOL bShow)
    {
    BOOL bRet=FALSE;
    if(m_bShow)
    {
    if(!bShow)
    {
    bRet=Shell_NotifyIcon(NIM_DELETE,&m_nid);
    }
    }
    else
    {
    if(bShow)
    bRet=Shell_NotifyIcon(NIM_ADD,&m_nid);
    }
    if(bRet)
    {
    m_bShow=bShow;
    }
    return bRet;}
    /*---------------------------------------------------------------------------------
    */
    BOOL CTrayNotify::Modify(const NOTIFYICONDATA& nid)
    {
    CopyMemory((void*)&m_nid,(void*)&nid,sizeof(nid));
    return Shell_NotifyIcon(NIM_MODIFY,&m_nid);
    }
    /*---------------------------------------------------------------------------------
    */
    void CTrayNotify::GetNid(NOTIFYICONDATA* pNid) const
    {
    CopyMemory((void*)pNid,(void*)&m_nid,sizeof(m_nid));
    }
    /*---------------------------------------------------------------------------------
    */
    BOOL CTrayNotify::IsIconShow() const
    {
    return m_bShow;
    }
    /*---------------------------------------------------------------------------------
    */
    void CTrayNotify::Reset()
    {
    ShowIcon(FALSE);
    memset((void*)&m_nid,0,sizeof(m_nid));
    }
    /*---------------------------------------------------------------------------------
    */
    void CTrayNotify::SetFlag(UINT uFlag)
    {
    m_nid.uFlags=uFlag;
    }
    /*---------------------------------------------------------------------------------
    */
    UINT CTrayNotify::GetFlag() const
    {
    return m_nid.uFlags;
    }
      

  5.   

    int Create(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID);你的类里没有这个函数吗Create函数的最后一个参数指定了关联菜单的ID号