Reputation: 101
I've been using win32api in Python3 to create a Windows 10 application that supports toast notifications.
I already have a system tray icon for my app, I'm adding toast notifications using the following code
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)
To remove a balloon notification, specify NIF_INFO and provide an empty string through 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..
Upvotes: 6
Views: 898
Reputation: 1505
I tried to implement this in C# and also had problems with it. 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.
Upvotes: 0