Ejemplo n.º 1
0
 def init_window(self):
     log("Win32Clipboard.init_window() creating clipboard window class and instance"
         )
     self.wndclass = WNDCLASSEX()
     self.wndclass.cbSize = sizeof(WNDCLASSEX)
     self.wndclass.lpfnWndProc = WNDPROC(self.wnd_proc)
     self.wndclass.style = win32con.CS_GLOBALCLASS
     self.wndclass.hInstance = GetModuleHandleA(0)
     self.wndclass.lpszClassName = clipboard_window_class_name
     self.wndclass_handle = RegisterClassExW(byref(self.wndclass))
     log("RegisterClassExA(%s)=%#x", self.wndclass.lpszClassName,
         self.wndclass_handle)
     if self.wndclass_handle == 0:
         raise WinError()
     style = win32con.WS_CAPTION  #win32con.WS_OVERLAPPED
     self.window = CreateWindowExW(0, self.wndclass_handle, u"Clipboard",
                                   style, 0, 0, win32con.CW_USEDEFAULT,
                                   win32con.CW_USEDEFAULT,
                                   win32con.HWND_MESSAGE, 0,
                                   self.wndclass.hInstance, None)
     log("clipboard window=%s", self.window)
     if not self.window:
         raise WinError()
     if not AddClipboardFormatListener(self.window):
         log.warn("Warning: failed to setup clipboard format listener")
         log.warn(" %s", get_last_error())
Ejemplo n.º 2
0
 def check_support(self, force_enable=False):
     #create a temporary window to query opengl attributes:
     hInst = GetModuleHandleA(0)
     log("check_support() GetModuleHandleW()=%#x", hInst or 0)
     classname = "Xpra Temporary Window for OpenGL"
     wndc = WNDCLASSEX()
     wndc.cbSize = sizeof(WNDCLASSEX)
     wndc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW
     wndc.hInstance = hInst
     wndc.hBrush = COLOR_WINDOW
     wndc.lpszClassName = classname
     wndc.lpfnWndProc = WNDPROC(DefWndProc)
     reg_atom = RegisterClassExA(byref(wndc))
     log("check_support() RegisterClassExW()=%#x", reg_atom or 0)
     if not reg_atom:
         return {
             "info":
             "disabled: failed to register window class, %s" %
             FormatError()
         }
     style = WS_OVERLAPPED | WS_SYSMENU
     window_name = "Xpra OpenGL Test"
     self.hwnd = CreateWindowExA(0, reg_atom, window_name, style,
                                 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0, 0,
                                 hInst, None)
     log("check_support() CreateWindowExW()=%#x", self.hwnd or 0)
     if not self.hwnd:
         return {
             "info":
             "disabled: failed to create temporary window, %s" %
             FormatError()
         }
     try:
         self.context = self.create_wgl_context(self.hwnd)
         with WGLWindowContext(self.hwnd, self.hdc, self.context):
             props = check_PyOpenGL_support(force_enable)
         props["display_mode"] = [
             ["SINGLE", "DOUBLE"][int(DOUBLE_BUFFERED)],
         ]  #, "ALPHA"]
         return props
     finally:
         hwnd = self.hwnd
         self.destroy()
         if hwnd and not DestroyWindow(hwnd):
             log.warn(
                 "Warning: failed to destroy temporary OpenGL test window")
         latom = c_void_p(reg_atom)
         if not UnregisterClassW(cast(latom, LPCWSTR), hInst):
             log.warn(
                 "Warning: failed to unregister class for OpenGL test window"
             )
             log.warn(" for class %r and module handle %#x:", classname,
                      hInst or 0)
             log.warn(" '%s'", FormatError())
Ejemplo n.º 3
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
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    WM_TRAY_EVENT: win32NotifyIcon.OnTaskbarNotify,
}


def NotifyIconWndProc(hwnd, msg, wParam, lParam):
    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