示例#1
0
    def __init__(self):
        assert singleton is None
        self.hwnd = None
        self.event_callbacks = {}
        self.ignore_events = IGNORE_EVENTS
        self.log_events = LOG_EVENTS

        if not WINDOW_EVENTS:
            return

        self.wc = WNDCLASSEX()
        self.wc.cbSize = ctypes.sizeof(WNDCLASSEX)
        self.wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW
        self.wc.lpfnWndProc = WNDPROC(self.WndProc)
        self.wc.cbClsExtra = 0
        self.wc.cbWndExtra = 0
        self.wc.hInstance = GetModuleHandleA(0)
        self.wc.hIcon = 0
        self.wc.hCursor = 0
        self.wc.hBrush = GetStockObject(win32con.WHITE_BRUSH)
        self.wc.lpszMenuName = 0
        self.wc.lpszClassName = u'Xpra-Event-Window'
        self.wc.hIconSm = 0
        self.wc.hbrBackground = win32con.COLOR_WINDOW
        self.wc_atom = RegisterClassExW(ctypes.byref(self.wc))
        if self.wc_atom == 0:
            raise ctypes.WinError(ctypes.get_last_error())

        self.hwnd = CreateWindowExA(0, self.wc_atom,
                                    u"For xpra event listener only",
                                    win32con.WS_CAPTION, 0, 0,
                                    win32con.CW_USEDEFAULT,
                                    win32con.CW_USEDEFAULT, 0, 0,
                                    self.wc.hInstance, None)
        if self.hwnd == 0:
            raise ctypes.WinError(ctypes.get_last_error())

        if wtsapi32:
            #register our interest in session events:
            #http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html#isenslogon
            #http://stackoverflow.com/questions/365058/detect-windows-logout-in-python
            #http://msdn.microsoft.com/en-us/library/aa383841.aspx
            #http://msdn.microsoft.com/en-us/library/aa383828.aspx
            wtsapi32.WTSRegisterSessionNotification(self.hwnd,
                                                    NOTIFY_FOR_THIS_SESSION)
        log("Win32EventListener created with hwnd=%s", self.hwnd)
示例#2
0
def get_notifyicon_wnd_class():
    global _notifyicon_wnd_class
    if _notifyicon_wnd_class is None:
        hmodule = HMODULE(0)
        assert GetModuleHandleExA(0, None, byref(hmodule))
        log("GetModuleHandleExA(..)=%#x", int(hmodule.value))

        NIwc = WNDCLASSEX()
        NIwc.cbSize = sizeof(WNDCLASSEX)
        NIwc.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        NIwc.lpfnWndProc = WNDPROC(NotifyIconWndProc)
        NIwc.hInstance = hmodule
        NIwc.hBrush = GetStockObject(win32con.WHITE_BRUSH)
        NIwc.lpszClassName = "win32NotifyIcon"

        NIclassAtom = RegisterClassExA(byref(NIwc))
        log("RegisterClassExA(%s)=%i", NIwc.lpszClassName, NIclassAtom)
        if NIclassAtom == 0:
            raise ctypes.WinError(ctypes.get_last_error())
        NIwc.NIclassAtom = NIclassAtom
        _notifyicon_wnd_class = NIwc
    return _notifyicon_wnd_class
示例#3
0
    instance = win32NotifyIcon.instances.get(hwnd)
    fn = message_map.get(msg)
    log("NotifyIconWndProc%s instance=%s, message(%i)=%s",
        (hwnd, msg, wParam, lParam), instance, msg, fn)
    #log("potential matching win32 constants for message: %s", [x for x in dir(win32con) if getattr(win32con, x)==msg])
    if instance and fn:
        return fn(instance, hwnd, msg, wParam, lParam) or 0
    return DefWindowProcA(hwnd, msg, wParam, lParam)


NIwc = WNDCLASSEX()
NIwc.cbSize = sizeof(WNDCLASSEX)
NIwc.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
NIwc.lpfnWndProc = WNDPROC(NotifyIconWndProc)
NIwc.hInstance = GetModuleHandleA(0)
NIwc.hBrush = GetStockObject(win32con.WHITE_BRUSH)
NIwc.lpszClassName = u"win32NotifyIcon"

NIclassAtom = RegisterClassExA(byref(NIwc))
if NIclassAtom == 0:
    raise ctypes.WinError(ctypes.get_last_error())
log("RegisterClassExA(%s)=%i", NIwc.lpszClassName, NIclassAtom)


def main():
    import os
    from xpra.platform.win32.common import user32

    def click_callback(button, pressed):
        menu = CreatePopupMenu()
        AppendMenu(menu, win32con.MF_STRING, 1024, u"Generate balloon")