Example #1
0
    def register(self):
        self.hInstance = win32api.GetModuleHandle()
        className = 'MyWindowClassName'

        # https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576(v=vs.85).aspx
        # win32gui does not support WNDCLASSEX.
        wndClass = win32gui.WNDCLASS()
        # https://msdn.microsoft.com/en-us/library/windows/desktop/ff729176(v=vs.85).aspx
        wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        wndClass.lpfnWndProc = self.wndProc
        wndClass.hInstance = self.hInstance
        wndClass.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW)
        wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
        wndClass.lpszClassName = className
        # win32gui does not support RegisterClassEx
        self.wndClassAtom = win32gui.RegisterClass(wndClass)

        self.hInstance_edge = win32api.GetModuleHandle()
        className = 'MyWindowClassName_edge'

        wndClass_edge = win32gui.WNDCLASS()
        # https://msdn.microsoft.com/en-us/library/windows/desktop/ff729176(v=vs.85).aspx
        wndClass_edge.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        wndClass_edge.lpfnWndProc = self.wndProc_edge
        wndClass_edge.hInstance = self.hInstance_edge
        wndClass_edge.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW)
        wndClass_edge.hbrBackground = win32gui.GetStockObject(
            win32con.WHITE_BRUSH)
        wndClass_edge.lpszClassName = className
        self.wndClassAtom_edge = win32gui.RegisterClass(wndClass_edge)
Example #2
0
    def message_receiver(self):  # Hidden window that can listen for messages
        self._logger.debug('Starting the message receiver')
        event_window = None
        try:
            hinst = win32api.GetModuleHandle(None)
            wndclass = win32gui.WNDCLASS()
            wndclass.hInstance = hinst
            wndclass.lpszClassName = "ListenerWindowClass"
            wndclass.lpfnWndProc = self.msg_handler
            event_window = None

            event_window_class = win32gui.RegisterClass(wndclass)
            event_window = win32gui.CreateWindowEx(0, event_window_class,
                                                   "ListenerWindow", 0, 0, 0,
                                                   0, 0, win32con.HWND_MESSAGE,
                                                   None, None, None)
            win32ts.WTSRegisterSessionNotification(
                event_window, win32ts.NOTIFY_FOR_ALL_SESSIONS)
            while not self._stop_event.is_set():
                win32gui.PumpWaitingMessages()
                self._stop_event.wait(5)
        except Exception as e:
            self._logger.error("Exception while making message handler: %s", e)
        finally:
            win32ts.WTSUnRegisterSessionNotification(event_window)
            self._logger.debug('Exiting the message receiver')
Example #3
0
    def __init__(self):
        msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
            msg_TaskbarRestart: self.OnRestart,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_USER + 20: self.OnTaskbarNotify,
        }
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "PythonTaskbarDemo"
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map  # could also specify a wndproc.

        # Don't blow up if class already registered to make testing easier
        try:
            classAtom = win32gui.RegisterClass(wc)
        except win32gui.error as err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise

        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "Taskbar Demo",
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self._DoCreateIcons()
def listen_for_sleep():

    hinst = win32api.GetModuleHandle(None)
    wndclass = win32gui.WNDCLASS()
    wndclass.hInstance = hinst
    wndclass.lpszClassName = "dummy_window"
    messageMap = {
        win32con.WM_QUERYENDSESSION: wndproc,
        win32con.WM_ENDSESSION: wndproc,
        win32con.WM_QUIT: wndproc,
        win32con.WM_DESTROY: wndproc,
        win32con.WM_CLOSE: wndproc,
        win32con.WM_POWERBROADCAST: wndproc
    }

    wndclass.lpfnWndProc = messageMap

    try:
        myWindowClass = win32gui.RegisterClass(wndclass)
        hwnd = win32gui.CreateWindowEx(win32con.WS_EX_LEFT, myWindowClass,
                                       "dummy_window", 0, 0, 0,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT, 0, 0, hinst,
                                       None)
        logging.info(f'hwnd={hwnd}')
    except Exception as e:
        logging.error(f'Exception caught: {str(e)}')
        return

    while True:
        win32gui.PumpWaitingMessages()
        time.sleep(1)
Example #5
0
    def start(self):
        print("[log] start")
        wndproc = {
            # win32con.WM_PAINT: self.OnPaint,
            win32con.WM_CLOSE: self.OnClose,
            win32con.WM_CREATE: self.OnCreate,
            win32con.WM_DRAWCLIPBOARD: self.OnDrawClipboard,  # copy
            # win32con.WM_CHANGECBCHAIN: self.OnChangeCBChain,
        }

        wc = win32gui.WNDCLASS()
        wc.lpszClassName = 'app_clipboard'
        wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hbrBackground = win32con.COLOR_WINDOW + 1
        wc.lpfnWndProc = wndproc
        class_atom = win32gui.RegisterClass(wc)
        hwnd = win32gui.CreateWindowEx(
            0, class_atom, u'分享链接', win32con.WS_CAPTION | win32con.WS_VISIBLE
            | win32con.WS_THICKFRAME | win32con.WS_SYSMENU, 100, 100, 600, 400,
            0, 0, 0, None)
        win32clipboard.SetClipboardViewer(hwnd)
        win32gui.PumpMessages()
        win32gui.UnregisterClass(class_atom, None)

        win32clipboard.OpenClipboard()
        win32clipboard.EmptyClipboard()
        win32clipboard.CloseClipboard()
Example #6
0
    def __init__(self):
        self.visible = 0
        self.events = {
            win32con.WM_DESTROY: self.onDestroy,
            win32con.WM_USER + 20: self.onTaskbarNotify,
            win32con.WM_COMMAND: self.onCommand
            # win32con.WM_USER+5	: self.onBalloonClick
        }
        self.windowtext = "window text"
        self.windowclassname = "window class name"

        window = win32gui.WNDCLASS()
        self.handlerInstance = window.hInstance = win32api.GetModuleHandle(
            None)
        window.lpszClassName = self.windowclassname
        window.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        window.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        window.hbrBackground = win32con.COLOR_WINDOW
        window.lpfnWndProc = self.events

        classAtom = win32gui.RegisterClass(window)
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, self.windowtext, style, 0,
                                          0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0,
                                          self.handlerInstance, None)
        win32gui.UpdateWindow(self.hwnd)
        self.setIcon()
Example #7
0
    def _register_window(self):
        message_map = {
            win32con.WM_DESTROY: self._on_destroy,
            win32con.WM_SIZE: self._on_resize,
            win32con.WM_ERASEBKGND: self._on_erase_bkgnd,
            win32con.WM_GETMINMAXINFO: self._on_minmax_info
        }

        self.wndclass = win32gui.WNDCLASS()
        self.wndclass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        self.wndclass.lpfnWndProc = message_map
        self.wndclass.hInstance = win32api.GetModuleHandle()
        self.wndclass.hCursor = win32gui.LoadCursor(win32con.NULL,
                                                    win32con.IDC_ARROW)
        self.wndclass.hbrBackground = win32gui.GetStockObject(
            win32con.WHITE_BRUSH)
        self.wndclass.lpszMenuName = ""
        self.wndclass.lpszClassName = "MainWin"

        try:  # Try loading an icon embedded in the exe file. This will crash when frozen with PyInstaller
            self.wndclass.hIcon = win32gui.LoadIcon(self.wndclass.hInstance, 1)
        except:
            pass

        # Register Window Class
        if not win32gui.RegisterClass(self.wndclass):
            raise WinError()
Example #8
0
    def _CreateMainWindow(self, prev, settings, browser, rect):
        # Creates a parent window that hosts the view window.  This window
        # gets the control notifications etc sent from the child.
        style = win32con.WS_CHILD | win32con.WS_VISIBLE  #
        wclass_name = "ShellViewDemo_DefView"
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        wc.hInstance = win32gui.dllhandle
        wc.lpszClassName = wclass_name
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        try:
            win32gui.RegisterClass(wc)
        except win32gui.error as details:
            # Should only happen when this module is reloaded
            if details[0] != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise

        message_map = {
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_NOTIFY: self.OnNotify,
            win32con.WM_CONTEXTMENU: self.OnContextMenu,
            win32con.WM_SIZE: self.OnSize,
        }

        self.hwnd = win32gui.CreateWindow(wclass_name, "", style, \
                                          rect[0], rect[1], rect[2] - rect[0], rect[3] - rect[1],
                                          self.hwnd_parent, 0, win32gui.dllhandle, None)
        win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, message_map)
        print("View 's hwnd is", self.hwnd)
        return self.hwnd
Example #9
0
def create_window(title, class_name, width, height, window_proc, icon):
    # Register window class
    wndclass = win32gui.WNDCLASS()
    wndclass.hInstance = win32api.GetModuleHandle(None)
    wndclass.lpszClassName = class_name
    wndclass.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
    wndclass.hbrBackground = win32con.COLOR_WINDOW
    wndclass.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
    wndclass.lpfnWndProc = window_proc
    atom_class = win32gui.RegisterClass(wndclass)
    assert (atom_class != 0)

    # Center window on screen.
    screenx = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
    screeny = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
    xpos = int(math.floor((screenx * 0.2 - width) / 2))
    ypos = int(math.floor((screeny - height) / 2))
    if xpos < 0:
        xpos = 0
    if ypos < 0:
        ypos = 0

    # Create window
    window_style = (win32con.WS_OVERLAPPEDWINDOW | win32con.WS_CLIPCHILDREN
                    | win32con.WS_VISIBLE)
    window_handle = win32gui.CreateWindow(class_name, title, window_style,
                                          xpos, ypos, width, height,
                                          0, 0, wndclass.hInstance, None)

    assert (window_handle != 0)
    win32gui.SetWindowPos(window_handle, win32con.HWND_TOPMOST, xpos, ypos, width, height, win32con.SWP_SHOWWINDOW)
    # win32con.HWND_TOPMOST窗口置顶

    # Window icon
    icon = os.path.abspath(icon)
    if not os.path.isfile(icon):
        icon = None
    if icon:
        # Load small and big icon.
        # WNDCLASSEX (along with hIconSm) is not supported by pywin32,
        # we need to use WM_SETICON message after window creation.
        # Ref:
        # 1. http://stackoverflow.com/questions/2234988
        # 2. http://blog.barthe.ph/2009/07/17/wmseticon/
        bigx = win32api.GetSystemMetrics(win32con.SM_CXICON)
        bigy = win32api.GetSystemMetrics(win32con.SM_CYICON)
        big_icon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON,
                                      bigx, bigy,
                                      win32con.LR_LOADFROMFILE)
        smallx = win32api.GetSystemMetrics(win32con.SM_CXSMICON)
        smally = win32api.GetSystemMetrics(win32con.SM_CYSMICON)
        small_icon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON,
                                        smallx, smally,
                                        win32con.LR_LOADFROMFILE)
        win32api.SendMessage(window_handle, win32con.WM_SETICON,
                             win32con.ICON_BIG, big_icon)
        win32api.SendMessage(window_handle, win32con.WM_SETICON,
                             win32con.ICON_SMALL, small_icon)

    return window_handle
Example #10
0
def TestGradientFill():
    wc = win32gui.WNDCLASS()
    wc.lpszClassName = "test_win32gui_2"
    wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW
    wc.hbrBackground = win32con.COLOR_WINDOW + 1
    wc.lpfnWndProc = wndproc_2
    class_atom = win32gui.RegisterClass(wc)
    hwnd = win32gui.CreateWindowEx(
        0,
        class_atom,
        "Kaleidoscope",
        win32con.WS_CAPTION
        | win32con.WS_VISIBLE
        | win32con.WS_THICKFRAME
        | win32con.WS_SYSMENU,
        100,
        100,
        900,
        900,
        0,
        0,
        0,
        None,
    )
    s = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
    win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                           s | win32con.WS_EX_LAYERED)
    win32gui.SetLayeredWindowAttributes(hwnd, 0, 175, win32con.LWA_ALPHA)
    for x in range(30):
        win32gui.InvalidateRect(hwnd, None, True)
        win32gui.PumpWaitingMessages()
        time.sleep(0.3)
    win32gui.DestroyWindow(hwnd)
    win32gui.UnregisterClass(class_atom, None)
Example #11
0
def TestSetWorldTransform():
    wc = win32gui.WNDCLASS()
    wc.lpszClassName = "test_win32gui_1"
    wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW
    wc.hbrBackground = win32con.COLOR_WINDOW + 1
    wc.lpfnWndProc = wndproc_1
    class_atom = win32gui.RegisterClass(wc)
    hwnd = win32gui.CreateWindow(
        wc.lpszClassName,
        "Spin the Lobster!",
        win32con.WS_CAPTION | win32con.WS_VISIBLE,
        100,
        100,
        900,
        900,
        0,
        0,
        0,
        None,
    )
    for x in range(500):
        win32gui.InvalidateRect(hwnd, None, True)
        win32gui.PumpWaitingMessages()
        time.sleep(0.01)
    win32gui.DestroyWindow(hwnd)
    win32gui.UnregisterClass(wc.lpszClassName, None)
Example #12
0
def main():
    hInstance = win32api.GetModuleHandle()  # 获取当前的实例句柄

    # 定义窗口类
    wndClass = win32gui.WNDCLASS()
    wndClass.lpszClassName = 'window'  # 窗口的类名
    wndClass.lpfnWndProc = wndProc
    wndClass.hInstance = hInstance
    wndClass.cbWndExtra = 0
    wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
    wndClass.hIcon = win32gui.LoadIcon(None, win32con.IDI_APPLICATION)
    wndClass.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW)
    wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)

    # 注册窗口类
    wndClassAtom = win32gui.RegisterClass(wndClass)

    # 创建窗口
    hWindow = win32gui.CreateWindow(
        wndClassAtom, 'Python Win32 Window', win32con.WS_OVERLAPPEDWINDOW,
        win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
        win32con.CW_USEDEFAULT, 0, 0, hInstance, None)

    # 显示窗口
    win32gui.ShowWindow(hWindow, win32con.SW_SHOWNORMAL)

    # 更新窗口
    win32gui.UpdateWindow(hWindow)

    # 消息循环
    win32gui.PumpMessages()
Example #13
0
    def create_window(self, window_name='Dummy Window'):
        message_map = {
            win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
            win32con.WM_DESTROY: self.destroy,
            win32con.WM_COMMAND: self.command,
            self.message_id : self.notify,
        }

        # Register the Window class.
        window_class = win32gui.WNDCLASS()
        window_class.lpszClassName = 'geobox_client_tray_icon'
        window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        window_class.hCursor = win32gui.LoadCursor(
            0,
            win32con.IDC_ARROW
        )
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map
        class_atom = win32gui.RegisterClass(window_class)
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU

        window_id = win32gui.CreateWindow(
            class_atom,
            window_name,
            style,
            0, 0,
            0, 0,
            0,
            0,
            None,
            None
        )
        log.debug('Dummy window created')
        win32gui.UpdateWindow(window_id)
        return window_id
Example #14
0
def register_keyboard(onkey):
    wc = win32gui.WNDCLASS()
    wc.lpfnWndProc = functools.partial(proc, onkey)
    wc.lpszClassName = 'KeyListener'
    hinst = wc.hInstance = win32api.GetModuleHandle(None)
    classAtom = win32gui.RegisterClass(wc)
    hwnd = win32gui.CreateWindow(
        classAtom,
        'KeyListener',
        0,
        0,
        0,
        0,
        0,  # width, height
        0,
        0,
        hinst,
        None)
    rid = RAWINPUTDEVICE()
    rid.usUsagePage = 1
    rid.usUsage = 6
    rid.dwFlags = RIDEV_INPUTSINK
    rid.hwndTarget = hwnd
    user32.RegisterRawInputDevices(ctypes.byref(rid), 1,
                                   ctypes.sizeof(RAWINPUTDEVICE))
Example #15
0
    def __init__(self):
        wx.EvtHandler.__init__(self)
        msg_TaskbarCreated = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
            msg_TaskbarCreated: self.OnTaskbarCreated,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_USER + 20: self.OnTaskbarNotify
        }

        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "SysTrayIcon"
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map

        classAtom = win32gui.RegisterClass(wc)

        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "SysTrayIcon",
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self._nid = None
        self.in_popup = False
        self.menu = None
        self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnRightUp)
        # With wxPython 4, calling <EvtHandler>.Destroy() no longer makes the
        # instance evaluate to False in boolean comparisons, so we emulate that
        # functionality
        self._destroyed = False
def main():
    hInstance = win32api.GetModuleHandle()
    className = 'MyWindowClassName'

    wndClass = win32gui.WNDCLASS()
    wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
    wndClass.lpfnWndProc = wndProc
    wndClass.hInstance = hInstance
    wndClass.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW)
    wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
    wndClass.lpszClassName = className
    wndClassAtom = win32gui.RegisterClass(wndClass)
    exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT
    style = win32con.WS_DISABLED | win32con.WS_POPUP | win32con.WS_VISIBLE
    hWindow = win32gui.CreateWindowEx(
        exStyle,
        wndClassAtom,
        None,  # WindowName
        style,
        0,
        0,  # x,y
        win32api.GetSystemMetrics(win32con.SM_CXSCREEN),
        win32api.GetSystemMetrics(win32con.SM_CYSCREEN),  # width,height 
        None,  # hWndParent
        None,  # hMenu
        hInstance,
        None  # lpParam
    )
    win32gui.SetLayeredWindowAttributes(
        hWindow, 0x00ffffff, 255, win32con.LWA_COLORKEY | win32con.LWA_ALPHA)
    #win32gui.UpdateWindow(hWindow)
    win32gui.SetWindowPos(
        hWindow, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOACTIVATE
        | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
Example #17
0
 def _run(self, quiet: bool = False):
     message_map = {con32.WM_DESTROY: self._onDestroy, }
     # register the window class
     wc = gui32.WNDCLASS()
     self._hinst = wc.hInstance = gui32.GetModuleHandle(None)
     wc.lpszClassName = 'PythonBalloontip'
     wc.lpfnWndProc = message_map
     self._classAtom = gui32.RegisterClass(wc)
     # create the window
     style = con32.WS_OVERLAPPED | con32.WS_SYSMENU
     self._hwnd = gui32.CreateWindow(self._classAtom, 'Taskbar', style, 0, 0, con32.CW_USEDEFAULT,
                                     con32.CW_USEDEFAULT, 0, 0, self._hinst, None)
     gui32.UpdateWindow(self._hwnd)
     try:
         timeout = float(self.timeout)
         if timeout <= 0:
             raise ValueError(
                 "the 'timeout' parameter must be greater than 0")
     except Exception as e:
         self._showError(e, 'exit')
         return
     self._infoFlags = gui32.NIIF_NOSOUND if quiet else 0
     if not self._getIcon():
         return
     flags = gui32.NIF_ICON | gui32.NIF_MESSAGE | gui32.NIF_TIP | gui32.NIF_INFO
     nid = (self._hwnd, 0, flags, con32.WM_USER + 20, self._hicon,
            "Balloontip", self.msg, 200, self.title, self._infoFlags)
     gui32.Shell_NotifyIcon(gui32.NIM_ADD, nid)
     sleep(timeout)
     gui32.DestroyWindow(self._hwnd)
     gui32.UnregisterClass(self._classAtom, self._hinst)
Example #18
0
    def __init__(self, tip, ico, items):

        if not ico: raise

        self._callbacks = dict()
        self._keys = []
        self._tip = tip
        self._ico = ico
        self._items = items

        windowClass = win32gui.WNDCLASS()
        windowClass.hInstance = win32gui.GetModuleHandle(None)
        windowClass.lpszClassName = "5ea86490-d4ec-11e1-9b23-0800200c9a66"
        windowClass.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        windowClass.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        windowClass.hbrBackground = win32con.COLOR_WINDOW
        windowClass.lpfnWndProc = {
            win32con.WM_COMMAND: self._commandCallback,
            win32con.WM_USER + 20: self._notifyCallback
        }

        self._hwnd = win32gui.CreateWindow(
            win32gui.RegisterClass(windowClass), windowClass.lpszClassName,
            win32con.WS_OVERLAPPED | win32con.WS_SYSMENU, 0, 0,
            win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0,
            windowClass.hInstance, None)

        win32gui.Shell_NotifyIcon(
            win32gui.NIM_ADD,
            (self._hwnd, 0, win32gui.NIF_ICON | win32gui.NIF_MESSAGE
             | win32gui.NIF_TIP, win32con.WM_USER + 20,
             win32gui.LoadImage(
                 win32gui.GetModuleHandle(None), os.path.abspath(self._ico),
                 win32con.IMAGE_ICON, 0, 0, win32con.LR_LOADFROMFILE
                 | win32con.LR_DEFAULTSIZE), self._tip))
Example #19
0
def new_icon(hdesk,desktop_name):
    """ Runs as a thread on each desktop to create a new tray icon and handle its messages """ 
    global id
    id=id+1
    hdesk.SetThreadDesktop()
    ## apparently the threads can't use same hinst, so each needs its own window class
    windowclassname='PythonDesktopManager'+desktop_name
    wc = win32gui.WNDCLASS()
    wc.hInstance = win32api.GetModuleHandle(None)
    wc.lpszClassName = windowclassname
    wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW | win32con.CS_GLOBALCLASS
    wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
    wc.hbrBackground = win32con.COLOR_WINDOW
    wc.lpfnWndProc = icon_wndproc
    windowclass = win32gui.RegisterClass(wc)
    style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
    hwnd = win32gui.CreateWindow(windowclass, 'dm_'+desktop_name, win32con.WS_SYSMENU,
                    0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                    0, 0, wc.hInstance, None)
    win32gui.UpdateWindow(hwnd)
    flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
    notify_info = (hwnd, id, flags, win32con.WM_USER+20, hicon, 'Desktop Manager (%s)' %desktop_name)
    window_info[hwnd]=notify_info
    ## wait for explorer to initialize system tray for new desktop
    tray_found=0
    while not tray_found:
        try:
            tray_found=win32gui.FindWindow("Shell_TrayWnd",None)
        except win32gui.error:
            traceback.print_exc
            time.sleep(.5)
    win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, notify_info)
    win32gui.PumpMessages()
Example #20
0
    def __init__(self, host='localhost', password=None):
        self.client = Client(host=host, password=password, socket_timeout=10)

        msg_task_bar_restart = win32gui.RegisterWindowMessage("TaskbarCreated")
        message_map = {
            msg_task_bar_restart: self._on_restart,
            win32con.WM_DESTROY: self._on_destroy,
            win32con.WM_COMMAND: self._on_command,
            self._WM_USER_STOCK_DATA: self._on_data_receive,
            win32con.WM_USER + 20: self._on_taskbar_notify
        }
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "StockTaskBar"
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        wc.lpfnWndProc = message_map  # could also specify a wndproc.

        # Don't blow up if class already registered to make testing easier
        try:
            classAtom = win32gui.RegisterClass(wc)
        except win32gui.error, err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise
Example #21
0
   def __init__(self):
      restart_message = win32gui.RegisterWindowMessage('TaskBar Created')
      message_map = {restart_message: self.restart,
                     win32con.WM_DESTROY: self.destroy,
                     win32con.WM_COMMAND: self.command,
                     win32con.WM_USER+20: self.taskbar_notify}

      wc = win32gui.WNDCLASS()
      hinst = wc.hInstance = win32api.GetModuleHandle(None)
      wc.lpszClassName = "Tracker"
      wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
      wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
      wc.hbrBackground = win32con.COLOR_WINDOW
      wc.lpfnWndProc = message_map  # could also specify a wndproc

      # Don't blow up if class already registered to make testing easier
      try:
         classAtom = win32gui.RegisterClass(wc)
      except win32gui.error:
         raise

      # Create the Window.
      style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
      self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "Taskbar Demo", style,
                                        0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                                        0, 0, hinst, None)
      win32gui.UpdateWindow(self.hwnd)
      self.create_icon()
Example #22
0
    def __init__(self, hoverText, icon):

        self.hotkeys = []

        self.hoverText = hoverText
        self.window_class_name = "Notify icon"

        # Register the Window class.
        window_class = win32gui.WNDCLASS()
        hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
        window_class.lpszClassName = self.window_class_name
        window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        classAtom = win32gui.RegisterClass(window_class)

        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hWindow = win32gui.CreateWindow(classAtom, self.window_class_name,
                                             style, 0, 0,
                                             win32con.CW_USEDEFAULT,
                                             win32con.CW_USEDEFAULT, 0, 0,
                                             hinst, None)

        win32gui.UpdateWindow(self.hWindow)

        self.notify_id = None
        self.draw_icon(icon)
Example #23
0
    def _RegisterWndClass(self):
        className = "PythonDocSearch"
        message_map = {}
        wc = win32gui.WNDCLASS()
        wc.SetDialogProc()  # Make it a dialog class.
        wc.hInstance = self.hinst
        wc.lpszClassName = className
        wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW + 1
        wc.lpfnWndProc = message_map  # could also specify a wndproc.
        # C code: wc.cbWndExtra = DLGWINDOWEXTRA + sizeof(HBRUSH) + (sizeof(COLORREF));
        wc.cbWndExtra = win32con.DLGWINDOWEXTRA + struct.calcsize("Pi")
        icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE

        ## py.ico went away in python 2.5, load from executable instead
        this_app = win32api.GetModuleHandle(None)
        try:
            wc.hIcon = win32gui.LoadIcon(this_app,
                                         1)  ## python.exe and pythonw.exe
        except win32gui.error:
            wc.hIcon = win32gui.LoadIcon(this_app, 135)  ## pythonwin's icon
        try:
            classAtom = win32gui.RegisterClass(wc)
        except win32gui.error, err_info:
            if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
                raise
Example #24
0
    def __init__(self):
        message_map = {
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_SIZE: self.OnSize,
        }
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "test_explorer_browser"
        wc.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(wc)
        # Create the Window.
        style = win32con.WS_OVERLAPPEDWINDOW | win32con.WS_VISIBLE
        self.hwnd = win32gui.CreateWindow( classAtom, "Python IExplorerBrowser demo", style, \
                0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
                0, 0, hinst, None)
        eb = pythoncom.CoCreateInstance(shellcon.CLSID_ExplorerBrowser, None,
                                        pythoncom.CLSCTX_ALL,
                                        shell.IID_IExplorerBrowser)
        # as per MSDN docs, hook up events early
        self.event_cookie = eb.Advise(wrap(EventHandler()))

        eb.SetOptions(shellcon.EBO_SHOWFRAMES)
        rect = win32gui.GetClientRect(self.hwnd)
        # Set the flags such that the folders autoarrange and non web view is presented
        flags = (shellcon.FVM_LIST,
                 shellcon.FWF_AUTOARRANGE | shellcon.FWF_NOWEBVIEW)
        eb.Initialize(self.hwnd, rect, (0, shellcon.FVM_DETAILS))
        # And start browsing at the root of the namespace.
        eb.BrowseToIDList([], shellcon.SBSP_ABSOLUTE)
        #eb.FillFromObject(None, shellcon.EBF_NODROPTARGET);
        #eb.SetEmptyText("No known folders yet...");
        self.eb = eb
Example #25
0
    def create_window(self):
        def OnDestroy(hwnd, message, wparam, lparam):
            win32gui.PostQuitMessage(0)
            return True

        win32gui.InitCommonControls()
        hinst = win32api.GetModuleHandle(None)
        #hinst = win32gui.dllhandle
        className = 'deez_login'
        message_map = {
            win32con.WM_DESTROY: OnDestroy,
        }
        wc = win32gui.WNDCLASS()
        wc.style = win32con.WS_OVERLAPPED | win32con.CS_HREDRAW | win32con.CS_VREDRAW
        wc.lpfnWndProc = message_map
        wc.lpszClassName = className
        try:
            win32gui.RegisterClass(wc)
        except:
            pass
        style = win32con.WS_MAXIMIZEBOX | win32con.WS_MAXIMIZEBOX | win32con.WS_BORDER
        hwnd = win32gui.CreateWindow(className, 'Seedr Browser', style,
                                     win32con.CW_USEDEFAULT,
                                     win32con.CW_USEDEFAULT, 525, 530, 0, 0,
                                     hinst, None)
        win32gui.UpdateWindow(hwnd)
        win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 530, 530, 0)
        win32gui.MoveWindow(hwnd,
                            win32api.GetSystemMetrics(0) / 3,
                            win32api.GetSystemMetrics(1) / 9, 530, 530, True)
        win32gui.ShowWindow(hwnd, win32con.SW_SHOW)
        return hwnd
Example #26
0
    def __init__(self, menu_options, tray_name="willSpeak"):
        # Create instance level variable
        self.menu_options = menu_options

        # Create task mappings for try events
        message_map = {
            win32gui.RegisterWindowMessage("TaskbarCreated"): self.OnRestart,
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_COMMAND: self.OnCommand,
            win32con.WM_USER + 20: self.OnTaskbarNotify,
        }

        # Register the Window class.
        window_class = win32gui.WNDCLASS()
        window_class.lpszClassName = tray_name
        hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
        window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map
        classAtom = win32gui.RegisterClass(window_class)

        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, tray_name, style, 0, 0,
                                          win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.create_icon()
        win32gui.PumpMessages()
Example #27
0
 def __init__(self, title, msg):
     message_map = {
         win32con.WM_DESTROY: self.OnDestroy,
     }
     # Register the Window class.
     wc = win32gui.WNDCLASS()
     hinst = wc.hInstance = win32api.GetModuleHandle(None)
     wc.lpszClassName = "PythonTaskbar"
     wc.lpfnWndProc = message_map  # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(wc)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom, "Taskbar", style, 0,
                                       0, win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT, 0, 0,
                                       hinst, None)
     win32gui.UpdateWindow(self.hwnd)
     iconPathName = os.path.abspath(icon)
     icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
     try:
         hicon = win32gui.LoadImage(hinst, iconPathName,
                                    win32con.IMAGE_ICON, 0, 0,
                                    icon_flags)
     except:
         hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
     flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
     nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon,
            "tooltip")
     win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
     win32gui.Shell_NotifyIcon(
         win32gui.NIM_MODIFY,
         (self.hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon,
          "Balloon tooltip", title, 200, msg))
     win32gui.DestroyWindow(self.hwnd)
Example #28
0
    def __init__(self,
                 icon,
                 hover_text,
                 menu_options=(),
                 on_quit=None,
                 window_class_name=None,
                 gui=None):
        self.icon = icon
        self.hover_text = hover_text
        self.on_quit = on_quit
        self.gui = gui
        menu_options = menu_options + (('退出', None, self.QUIT), )
        self._next_action_id = self.FIRST_ID
        self.menu_actions_by_id = set()
        self.menu_options = self._add_ids_to_menu_options(list(menu_options))
        self.menu_actions_by_id = dict(self.menu_actions_by_id)
        del self._next_action_id
        self.window_class_name = window_class_name or "SysTrayIconPy"

        message_map = {
            win32gui.RegisterWindowMessage("TaskbarCreated"):
            self.refresh_icon,
            win32con.WM_DESTROY: self.destroy,
            win32con.WM_COMMAND: self.command,
            win32con.WM_USER + 20: self.notify,
        }

        window_class = win32gui.WNDCLASS()
        window_class.hInstance = win32gui.GetModuleHandle(None)
        window_class.lpszClassName = self.window_class_name
        window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map
        self.classAtom = win32gui.RegisterClass(window_class)
Example #29
0
 def initialize(self):
     message_map = {
         win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
         win32con.WM_DESTROY: self.destroy,
         win32con.WM_COMMAND: self.command,
         win32con.WM_USER + 20: self.notify,
     }
     # Register the Window class.
     window_class = win32gui.WNDCLASS()
     hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
     window_class.lpszClassName = self.window_class_name
     window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
     window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map  # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(window_class)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(
         classAtom,
         self.window_class_name,
         style,
         0,
         0,
         win32con.CW_USEDEFAULT,
         win32con.CW_USEDEFAULT,
         0,
         0,
         hinst,
         None,
     )
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
Example #30
0
    def _create_window(cls, title):
        def _on_destroy(hwnd, msg, wparam, lparam):
            win32gui.PostQuitMessage(0)
            return True

        def _on_resized(hwnd, msg, wparam, lparam):
            l, t, r, b = win32gui.GetClientRect(hwnd)
            progress = win32gui.FindWindowEx(hwnd, None,
                                             commctrl.PROGRESS_CLASS, "")
            win32gui.SetWindowPos(progress, None, l, t, r, b, 0)
            return True

        win32gui.InitCommonControls()

        # Set-up the top most window for holding the progress indicator.
        instance = win32api.GetModuleHandle(None)
        className = 'MyWndClass'
        message_map = {
            win32con.WM_DESTROY: _on_destroy,
            win32con.WM_EXITSIZEMOVE: _on_resized,
        }
        wc = win32gui.WNDCLASS()
        wc.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        wc.lpfnWndProc = message_map
        wc.lpszClassName = className
        win32gui.RegisterClass(wc)

        main_window = win32gui.CreateWindow(
            className, title,
            win32con.WS_OVERLAPPED | win32con.WS_CAPTION | win32con.WS_SYSMENU
            | win32con.WS_THICKFRAME | win32con.WS_VISIBLE,
            win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 400, 100, 0, 0,
            instance, None)

        return main_window