wxpython windows下顯示托盤區氣球訊息

來源:互聯網
上載者:User

2009-10-18 javaeye http://angeloce.iteye.com/admin/blogs/493681

 

=====================================

 

有一個小需求希望在wx下建立的托盤區表徵圖上顯示氣球訊息,很尷尬的是wx.TaskBarIcon不像wx.Window等有GetHandle方法,無法直接獲得控制代碼.解決的辦法

1.自己重寫TaskBarIcon...

2.直接遍曆找到控制代碼(更通用麻煩些).

#coding: cp936import win32guiimport win32conimport timeclass TestTaskbarIcon:    def __init__(self):                # 註冊一個視窗類別        wc = win32gui.WNDCLASS()        hinst = wc.hInstance = win32gui.GetModuleHandle(None)        wc.lpszClassName = "PythonTaskbarDemo"        wc.lpfnWndProc = {win32con.WM_DESTROY: self.OnDestroy,}        classAtom = win32gui.RegisterClass(wc)        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU        self.hwnd = win32gui.CreateWindow( classAtom, "Taskbar Demo", style,                0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,                0, 0, hinst, None)        hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)        nid = (self.hwnd, 0, win32gui.NIF_ICON, win32con.WM_USER+20, hicon, "Demo")        win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)    def showMsg(self, title, msg):        # 原作者使用Shell_NotifyIconA方法代替封裝後的Shell_NotifyIcon方法        # 據稱是不能win32gui structure, 我稀裡糊塗搞出來了.        # 具體對比原代碼.        nid = (self.hwnd, # 控制代碼                0, # 托盤表徵圖ID                win32gui.NIF_INFO, # 標識                0, # 回調訊息ID                0, # 托盤表徵圖控制代碼                "TestMessage", # 表徵圖字串                msg, # 氣球提示字串                0, # 提示的顯示時間                title, # 提示標題                win32gui.NIIF_INFO # 提示用到的表徵圖                )        win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, nid)    def OnDestroy(self, hwnd, msg, wparam, lparam):        nid = (self.hwnd, 0)        win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)        win32gui.PostQuitMessage(0) # Terminate the app.        if __name__ == '__main__':    t = TestTaskbarIcon()    t.showMsg("出來吧!", "奧特曼!")    time.sleep(5)    win32gui.DestroyWindow(t.hwnd)

 

    1. 除了演算法設計時, 使用python真的很簡單.

    2. 會用python沒什麼, 還得會用千奇百怪的東西, 比如這個

    3. 不經常對windows開發的人,還是常備msdn和baidu/google才不會慌馬腳..

 

    程式有改動,盡量縮減,原文請見:

 

寫道http://www.3snews.net/html/50/550-20986.html

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.