AW: [python-win32] Windows "scrolling in" like in gmail-notifier oroutlook 2003..

Massa, Harald harald.massa at suedvers.de
Tue Sep 14 14:47:00 CEST 2004


Thank you very much for your Pointer, Mark. With "AnimateWindow" I was able
to google it up ...
 
I took also some Ctypes-Receipe out of the windows-cookbook, and ... for
everyone to enjoy or not:
# -*- coding: LATIN-1 -*-
import win32con
import sys
from ctypes import *
import time
import threading
 
WNDPROC = WINFUNCTYPE(c_long, c_int, c_uint, c_int, c_int)
 
class WNDCLASS(Structure):
    _fields_ = [('style', c_uint),
                ('lpfnWndProc', WNDPROC),
                ('cbClsExtra', c_int),
                ('cbWndExtra', c_int),
                ('hInstance', c_int),
                ('hIcon', c_int),
                ('hCursor', c_int),
                ('hbrBackground', c_int),
                ('lpszMenuName', c_char_p),
                ('lpszClassName', c_char_p)]
 
class RECT(Structure):
    _fields_ = [('left', c_long),
                ('top', c_long),
                ('right', c_long),
                ('bottom', c_long)]
 
class PAINTSTRUCT(Structure):
    _fields_ = [('hdc', c_int),
                ('fErase', c_int),
                ('rcPaint', RECT),
                ('fRestore', c_int),
                ('fIncUpdate', c_int),
                ('rgbReserved', c_char * 32)]
 
class POINT(Structure):
    _fields_ = [('x', c_long),
                ('y', c_long)]
    
class MSG(Structure):
    _fields_ = [('hwnd', c_int),
                ('message', c_uint),
                ('wParam', c_int),
                ('lParam', c_int),
                ('time', c_int),
                ('pt', POINT)]
 
def ErrorIfZero(handle):
    if handle == 0:
        raise WinError
    else:
        return handle
 

class TrayNotifcation(object):
    def __init__(self, text='',breite=250,hoehe=60):
        self.maxx=windll.user32.GetSystemMetrics(win32con.SM_CXMAXIMIZED)
        self.maxy=windll.user32.GetSystemMetrics(win32con.SM_CYMAXIMIZED)
        self.text=text
        self.breite=breite
        self.hoehe=hoehe
 
        CreateWindowEx = windll.user32.CreateWindowExA
        CreateWindowEx.argtypes = [c_int, c_char_p, c_char_p, c_int, c_int,
c_int, c_int, c_int, c_int, c_int, c_int, c_int]
        CreateWindowEx.restype = ErrorIfZero
         
        # Ctypes may already have something like this...?
        def makeCOLORREF(red, green, blue):
             return red + (green << 8) + (blue << 16)
        myBrush = windll.gdi32.CreateSolidBrush(makeCOLORREF(220, 255, 220))
        
        # Define Window Class
        wndclass = WNDCLASS()
        wndclass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW 
        wndclass.lpfnWndProc = WNDPROC(self.WndProc)
        wndclass.cbClsExtra = wndclass.cbWndExtra = 0
        wndclass.hInstance =
windll.kernel32.GetModuleHandleA(c_int(win32con.NULL))
        wndclass.hIcon = windll.user32.LoadIconA(c_int(win32con.NULL),
c_int(win32con.IDI_APPLICATION))
        wndclass.hCursor = windll.user32.LoadCursorA(c_int(win32con.NULL),
c_int(win32con.IDC_ARROW))
        #wndclass.hbrBackground =
windll.gdi32.GetStockObject(c_int(win32con.WHITE_BRUSH))
        wndclass.hbrBackground =myBrush 
        wndclass.lpszMenuName = None
        wndclass.lpszClassName = "TrayNotiWin"
        # Register Window Class
        if not windll.user32.RegisterClassA(byref(wndclass)):
            raise WinError()
        # Create Window
        self.hwnd = CreateWindowEx(0,#DWORD dwExStyle,
                              wndclass.lpszClassName,#LPCTSTR lpClassName,
                              "Python Window", #LPCTSTR lpWindowName,
                              win32con.WS_POPUPWINDOW, #DWORD dwStyle,
                              self.maxx-self.breite,# x
                              self.maxy-self.hoehe,# y
                              self.breite,# breite
                              self.hoehe,# höhe
                              win32con.NULL,#HWND hWndParent,
                              win32con.NULL,#HMENU hMenu,
                              wndclass.hInstance,#HINSTANCE hInstance,
                              win32con.NULL#LPVOID lpParam
                              )
        
    def notify(self,text=None):
        if text:
            self.text=text
        windll.user32.ShowWindow(c_int(self.hwnd),
c_int(win32con.SW_SHOWNORMAL))
        windll.user32.UpdateWindow(c_int(self.hwnd))
        
        #print self.hwnd
        class killer(threading.Thread):
            def run(my):
                time.sleep(1.8)
 
windll.user32.ShowWindow(c_int(self.hwnd),c_int(win32con.SW_HIDE))
        killer().start()
 
    def close(self):
        windll.user32.PostMessageA(self.hwnd, win32con.WM_CLOSE, 0, 0)
 
    def __del__(self):
        """Fenster entfernen"""
        windll.user32.PostMessageA(self.hwnd, win32con.WM_CLOSE, 0, 0)
 
    
    def WndProc(self,hwnd, message, wParam, lParam):
        ps = PAINTSTRUCT()
        rect = RECT()
        if message == win32con.WM_PRINTCLIENT:
           hdc=wParam
           #print "wm_printclient erhalten"
           windll.user32.GetClientRect(c_int(hwnd), byref(rect))
           windll.gdi32.SetBkMode(hdc,win32con.TRANSPARENT)
           rect.top=rect.top+4
           rect.left=rect.left+4
           windll.user32.DrawTextA(c_int(hdc),
                                    self.text,
                                    c_int(-1), byref(rect), 
                                    win32con.DT_TOP)
        elif message == win32con.WM_SHOWWINDOW:
            #print "ShowWindow erhalten"
            bShown = wParam
            if bShown:
 
windll.user32.AnimateWindow(c_int(hwnd),c_int(280),c_int(win32con.AW_SLIDE|w
in32con.AW_VER_NEGATIVE))
            else:
 
windll.user32.AnimateWindow(c_int(hwnd),c_int(280),c_int(win32con.AW_SLIDE|w
in32con.AW_VER_POSITIVE|win32con.AW_HIDE))
            return 0
            
        elif message == win32con.WM_PAINT:
            #print "Paint bekommen"
            hdc = windll.user32.BeginPaint(c_int(hwnd), byref(ps))
            windll.user32.GetClientRect(c_int(hwnd), byref(rect))
            windll.user32.DrawTextA(c_int(hdc),
                                    self.text,
                                    c_int(-1), byref(rect), 
                                    win32con.DT_TOP)
            windll.user32.EndPaint(c_int(hwnd), byref(ps))
            return 0
        elif message == win32con.WM_DESTROY:
            #print "wmdestroy"
            windll.user32.PostQuitMessage(0)
            return 0
    
        return windll.user32.DefWindowProcA(c_int(hwnd), c_int(message),
c_int(wParam), c_int(lParam))
 

if __name__=="__main__":
    nt=TrayNotifcation("hey, hey, wickie")
    nt.notify()
    
    
    class waiter(threading.Thread):
        def run(self):
            time.sleep(3)
            nt.close()
    waiter().start()
    
    
    msg = MSG()
    pMsg = pointer(msg)
    NULL = c_int(win32con.NULL)
    while windll.user32.GetMessageA( pMsg, NULL, 0, 0) != 0:
        windll.user32.TranslateMessage(pMsg)
        windll.user32.DispatchMessageA(pMsg)
    print "das war es"
    nt.close()
    
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20040914/90208a72/attachment.htm


More information about the Python-win32 mailing list