加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

winapi – 如何Shell_NotifyIcon而不在通知区域中添加图标

发布时间:2020-12-16 01:37:50 所属栏目:安全 来源:网络整理
导读:MSDN关于 Notifications and the Notification Area的文档非常清楚,要求在通知区域中显示一个图标以显示通知: To display a notification, you must have an icon in the notification area . In certain cases,such as Microsoft Communicator or battery
MSDN关于 Notifications and the Notification Area的文档非常清楚,要求在通知区域中显示一个图标以显示通知:

To display a notification,you must
have an icon in the notification
area
. In certain cases,such as
Microsoft Communicator or battery
level,that icon will already be
present. In many other cases,however,
you will add an icon to the
notification area only as long as is
needed to show the notification.

由于我不想在通知区域添加任何图标,我想到的可能是“重用”现有的一个最常见的桌面上的图标.一个好的候选者可能是系统时钟.

我的问题是:

>我如何查找/枚举
NOTIFYICONDATA结构
系统时钟(AKA“日期和时间
属性“恢复时”?
>有没有更好的方法
完成这个(没有添加
一个图标)?

Shell_NotifyIcon在引擎盖下使用IUserNotification.我玩了它并制作了一个 utility out of it.我听说一个视力受损的系统管理员使用它来使他的脚本屏幕阅读器兼容.它是命令行,它没有消息循环.

它是自我意识的,这意味着发送给它的通知将排队(您可以控制它).为此,我提供了一个IQueryContinue实现.该项目是C语言,是开源的,帮助自己.

以下是它的内容:

HRESULT NotifyUser(const NOTIFU_PARAM& params,IQueryContinue *querycontinue,IUserNotificationCallback *notifcallback)
 {
    HRESULT result = E_FAIL;

    IUserNotification *un = 0;
    IUserNotification2 *deux = 0; //French pun : "un" above stands for UserNotification but it also means 1 in French. deux means 2.

    //First try with the Vista/Windows 7 interface
    //(unless /xp flag is specified
    if (!params.mForceXP)
       result = CoCreateInstance(CLSID_UserNotification,CLSCTX_ALL,IID_IUserNotification2,(void**)&deux);

    //Fall back to Windows XP
    if (!SUCCEEDED(result))
    {
       TRACE(eWARN,L"Using Windows XP interface IUserNotificationn");
       result = CoCreateInstance(CLSID_UserNotification,IID_IUserNotification,(void**)&un);
    }
    else
    {
       TRACE(eINFO,L"Using Vista interface IUserNotification2n");
       un = (IUserNotification*)deux; //Rather ugly cast saves some code...
    }

    if (SUCCEEDED(result))
    {
       const std::basic_string<TCHAR> crlf_text(L"n");
       const std::basic_string<TCHAR> crlf(L"n");
       std::basic_string<TCHAR> text(params.mText);
       size_t look = 0;
       size_t found;

       //Replace n with actual CRLF pair
       while ((found = text.find(crlf_text,look)) != std::string::npos)
       {
          text.replace(found,crlf_text.size(),crlf);
          look = found+1;
       }

       result = un->SetIconInfo(params.mIcon,params.mTitle.c_str());
       result = un->SetBalloonInfo(params.mTitle.c_str(),text.c_str(),params.mType);

       //Looks like it controls what happends when the X button is
       //clicked on
       result = un->SetBalloonRetry(0,250,0);

       if (deux)
          result = deux->Show(querycontinue,notifcallback);
       else
          result = un->Show(querycontinue,250);

       un->Release();
    }

    return result;
 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读