0
我正在使用氣球彈出通知來顯示用戶通知消息。 默認情況下,持續時間僅爲5秒窗口通知設置會在5秒內出現。如何增加窗口上氣球彈出通知的時間
我的代碼是:
from win32api import *
from win32con import NULL
from win32gui import *
import win32com.client as com
import win32con
import win32file
import time
class WindowsBalloonTip:
def __init__(self, title, msg,notlivelong):
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
}
# Register the Window class.
iconPathName= "D:\cc.ico"
wc = WNDCLASS()
hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbar"
wc.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = CreateWindow(classAtom, "Taskbar", style, \
0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
0, 0, hinst, None)
UpdateWindow(self.hwnd)
print iconPathName
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
try:
hicon = LoadImage(hinst,iconPathName, win32con.IMAGE_ICON, 16, 16,icon_flags)
except:
hicon = LoadIcon(0, win32con.IDI_APPLICATION)
# logging.debug("Image adding fail")
flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, "TITLE")
Shell_NotifyIcon(NIM_ADD, nid)
Shell_NotifyIcon(NIM_MODIFY, \
(self.hwnd, 0, NIF_INFO, win32con.WM_USER+20,\
hicon, "Balloon tooltip",msg,200,title))
# self.show_balloon(title, msg)
global sleep
time.sleep(2)
if notlivelong:
DestroyWindow(self.hwnd)
UnregisterClass(wc.lpszClassName, None)
def OnDestroy(self, hwnd, msg, wparam, lparam):
nid = (self.hwnd, 0)
Shell_NotifyIcon(NIM_MODIFY, nid)
PostQuitMessage(0)
# Terminate the app.
def balloon_tip(title, msg,notlivelong):
w=WindowsBalloonTip(title, msg,notlivelong)
balloon_tip("title1", "msg1",False) #iF True, then last for 2 sec.
如何讓這個氣球彈出停留時間更長。同樣考慮這種情況,彈出窗口在鼠標移動時也應該保持很長時間。另外,調用彈出窗口後,進程應該終止,但彈出窗口應該保留。