예제 #1
0
 def create_window(self):
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     window_name = u"%s StatusIcon Window" % bytestostr(self.title)
     self.hwnd = CreateWindowExA(0, NIclassAtom, window_name, style,
         win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, \
         0, 0, NIwc.hInstance, None)
     if self.hwnd == 0:
         raise ctypes.WinError(ctypes.get_last_error())
     log("hwnd=%#x", self.hwnd)
     UpdateWindow(self.hwnd)
예제 #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())
예제 #3
0
 def create_window(self):
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     window_name = u"%s StatusIcon Window" % bytestostr(self.title)
     self.hwnd = CreateWindowExA(0, NIclassAtom, window_name, style,
         win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, \
         0, 0, NIwc.hInstance, None)
     log("create_window() hwnd=%#x", self.hwnd or 0)
     if not self.hwnd:
         raise ctypes.WinError(ctypes.get_last_error())
     UpdateWindow(self.hwnd)
     #register callbacks:
     win32NotifyIcon.instances[self.hwnd] = self
예제 #4
0
 def create_window(self):
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     window_name = "%s StatusIcon Window" % bytestostr(self.title)
     niwc = get_notifyicon_wnd_class()
     args = (0, niwc.NIclassAtom, window_name, style,
             win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, 0, 0,
             niwc.hInstance, 0)
     log("CreateWindowExA%s", args)
     self.hwnd = CreateWindowExA(*args)
     log("create_window() hwnd=%#x", self.hwnd or 0)
     if not self.hwnd:
         raise ctypes.WinError(ctypes.get_last_error())
     UpdateWindow(self.hwnd)
     #register callbacks:
     win32NotifyIcon.instances[self.hwnd] = self
예제 #5
0
 def create_tray_window(self):
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     window_name = (self.title + " StatusIcon Window").decode()
     self.hwnd = CreateWindowExA(0, NIclassAtom, window_name, style,
         0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
         0, 0, NIwc.hInstance, None)
     if self.hwnd == 0:
         raise ctypes.WinError(ctypes.get_last_error())
     log("hwnd=%#x", self.hwnd)
     UpdateWindow(self.hwnd)
     r = Shell_NotifyIcon(NIM_ADD,
                          self.make_nid(NIF_ICON | NIF_MESSAGE | NIF_TIP))
     log("Shell_NotifyIcon ADD=%i", r)
     if not r:
         raise Exception("Shell_NotifyIcon failed to ADD")
예제 #6
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)