SOUI官方论坛

 找回密码
 立即注册
查看: 105|回复: 0

Soui 2 点击系统托盘图标事件回调函数处理

[复制链接]
  • TA的每日心情
    开心
    2023-6-19 14:36
  • 签到天数: 2 天

    [LV.1]初来乍到

    2

    主题

    3

    帖子

    80

    积分

    24:00金丹期

    Rank: 2

    积分
    80
    发表于 2023-6-19 11:25:26 | 显示全部楼层 |阅读模式
    需求:当点击系统托盘图标 主窗口不需要显示
    实现:

    1、        在此类中设置回调函数接口 CShellNotifyHwnd2
    回调函数定义
    #include <functional> //
    typedef std::function<bool()> FunShellNotifyIconLCLick;

                    void SetFunShellNotifyIconLCLick(FunShellNotifyIconLCLick fun) {
                            m_FunShellNotifyIconLCLick = fun;
                    }


    系统托盘图标点击 先调用回调函数,如果回调函数已出来则 不执行默认处理

            LRESULT CShellNotifyHwnd2::OnIconNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL)
            {
                    LRESULT bRet = S_FALSE;
                    switch (lParam)
                    {
                     
                    case WM_LBUTTONDOWN:
                    {
                            bool bHandle = false;
                            if (NULL != m_FunShellNotifyIconLCLick)
                            {
                                    bHandle = m_FunShellNotifyIconLCLick();
                            }

                            if (!bHandle)
                            {
                                    if (m_pMainWnd->IsWindowVisible())
                                            m_pMainWnd->ShowWindow(SW_HIDE);
                                    else
                                    {
                                            m_pMainWnd->ShowWindow(SW_SHOW);
                                            SetForegroundWindow(m_pMainWnd->m_hWnd);
                                    }
                            }

           
                            bRet = S_OK;
                    }break;
                   



    2、SShellNotifyIcon 在此类中添加设置回调函数接口
    void SShellNotifyIcon::SetFunShellNotifyIconLCLick(FunShellNotifyIconLCLick fun)
            {
                    m_FunShellNotifyIconLCLick = fun;
                    if (NULL != m_MsgOnlyWnd)
                    {
                            m_MsgOnlyWnd->SetFunShellNotifyIconLCLick(fun);
                    }
           
            }
    3、在主窗口中设置回调函数
        SShellNotifyIcon* pNotifyIcon = (SShellNotifyIcon*) FindChildByID2<SShellNotifyIcon>(8);
        if (NULL != pNotifyIcon)
        {
            FunShellNotifyIconLCLick fun = std::bind(&CMainDlg::OnTrayIconLButtonDown, this);
            pNotifyIcon->SetFunShellNotifyIconLCLick(fun);
        }

    回调函数处理如下
    bool CMainDlg::OnTrayIconLButtonDown()
    {   
        return true; //主窗体就不显示了
    }


    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|SOUI官方论坛

    GMT+8, 2024-5-18 12:43

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表