简体   繁体   English

从通知中心删除通知 windows 10

[英]Removing notification from notification center windows 10

I've been using win32api in Python3 to create a Windows 10 application that supports toast notifications.我一直在 Python3 中使用 win32api 创建一个支持 toast 通知的 Windows 10 应用程序。

I already have a system tray icon for my app, I'm adding toast notifications using the following code我的应用程序已经有一个系统托盘图标,我正在使用以下代码添加 toast 通知

def show_toast(self,msg,title):
        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, self.hicon, 
            "SpotiFind")
        win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, (self.hwnd, 0, 
            win32gui.NIF_INFO,
            win32con.WM_USER + 20,
            self.hicon, "Balloon Tooltip", msg, 200, title))        

All works well but the notification stays in the notification area and I want to delete it automatically... according to MSDN ( https://learn.microsoft.com/en-us/windows/desktop/api/shellapi/ns-shellapi-_notifyicondataa )一切正常,但通知停留在通知区域,我想自动删除它......根据 MSDN( https://learn.microsoft.com/en-us/windows/desktop/api/shellapi/ns-shellapi -_notifyicondataa )

To remove a balloon notification, specify NIF_INFO and provide an empty string through szInfo.要删除气球通知,请指定 NIF_INFO 并通过 szInfo 提供一个空字符串。

So I've tried the following所以我尝试了以下

def _destroy_toast(self):
    win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, (self.hwnd, 0, 
            win32gui.NIF_INFO,
            win32con.WM_USER + 20,
            self.hicon, "Balloon Tooltip", "", 200, ""))

This does nothing...这没有任何作用...

Thanks in advance..提前致谢..

I tried to implement this in C# and also had problems with it.我试图在 C# 中实现它,但也遇到了问题。 The way that works for me is:对我有用的方法是:

Shell_NotifyIcon(NIM_DELETE, nid)
Shell_NotifyIcon(NIM_CREATE, nid)

During deletion, all notifications will be cleared, both active and snoozed.在删除过程中,所有通知都将被清除,包括活动的和暂停的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM