-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
TrayMessage.py
39 lines (34 loc) · 1.41 KB
/
TrayMessage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from win32gui import *
from win32con import *
from time import sleep
class WindowsBalloonTip:
def __init__(self):
message_map = {
WM_DESTROY: self.OnDestroy,
}
# Register the Window class.
wc = WNDCLASS()
self.hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbar"
wc.lpfnWndProc = message_map # could also specify a wndproc.
self.classAtom = RegisterClass(wc)
def ShowWindow(self, title, msg, time):
# Create the Window.
style = WS_OVERLAPPED | WS_SYSMENU
self.hwnd = CreateWindow(self.classAtom, "Taskbar", style, \
0, 0, CW_USEDEFAULT, CW_USEDEFAULT, \
0, 0, self.hinst, None)
UpdateWindow(self.hwnd)
hicon = LoadIcon(0, IDI_APPLICATION)
nid = (self.hwnd, 0, 0, WM_USER + 20, hicon, "tooltip")
Shell_NotifyIcon(NIM_ADD, nid)
Shell_NotifyIcon(NIM_MODIFY, \
(self.hwnd, 0, NIF_INFO, WM_USER + 20, \
hicon, "Balloon tooltip", msg, 200, title))
# self.show_balloon(title, msg)
sleep(int(time))
DestroyWindow(self.hwnd)
def OnDestroy(self, hwnd, msg, wparam, lparam):
nid = (self.hwnd, 0)
Shell_NotifyIcon(NIM_DELETE, nid)
PostQuitMessage(0) # Terminate the app.