2

对我来说,Windows 气球消息似乎几周前在 Windows 10 上完全停止工作。在 2019 年 8 月,以下基于 Qt 的代码可用于在 Windows 操作中心发布通知,并让一个带有该通知的 toast 弹出:

#include <QApplication>
#include <QSystemTrayIcon>

int main(int argc, char **argv)
{
    QApplication app( argc, argv );

    //create a notification icon, and post a test notification
    QSystemTrayIcon *trayTest = new QSystemTrayIcon();
    trayTest->setIcon( QIcon( "path-to-some-icon-resource" ) );
    trayTest->show();
    trayTest->showMessage( "Hello", "world" );

    return app.exec();
}

但是现在 QSystemTrayIcon::showMessage 突然停止了任何效果,并且任何地方都没有出现。工作中的系统托盘应用程序正在使用该方法,并且 Windows 通知在所有系统上停止工作(安装了 Windows 10)。QSystemTrayIcon::showMessage 不适用于 Qt 5.7、Qt 5.12 和 Qt 5.13。我查看了 Qt 5.7 的源代码,内部在 qsystemtrayicon_win.cpp 中调用了 Shell_NotifyIcon:

bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs)
{
    NOTIFYICONDATA tnd;
    memset(&tnd, 0, notifyIconSize);
    qStringToLimitedWCharArray(message, tnd.szInfo, 256);
    qStringToLimitedWCharArray(title, tnd.szInfoTitle, 64);

    tnd.uID = q_uNOTIFYICONID;
    tnd.dwInfoFlags = iconFlag(type);
    tnd.cbSize = notifyIconSize;
    tnd.hWnd = m_hwnd;
    tnd.uTimeout = uSecs;
    tnd.uFlags = NIF_INFO | NIF_SHOWTIP;

    return Shell_NotifyIcon(NIM_MODIFY, &tnd);
}

Shell_NotifyIcon 在不同版本的 Qt 中用于 showMessage 的 windows 实现。我验证了在 Qt 5.7 下调用 QSystemTrayIcon::showMessage 时调用了 Shell_NotifyIcon,如果没有发生错误,它会返回 1,并且没有显示任何通知。玩弄“焦点辅助”和“通知和操作”设置没有效果。

最近是否有 Windows 更新修改了 Windows 通知的行为?是否只能使用一些新的原生 Windows 10 api 发布通知?我找不到任何有关 Windows 更新和通知不再显示的信息。

4

0 回答 0