예제 #1
0
    def _getIcon(self) -> bool:
        def getArgs(icon): return (self._hinst, icon, con32.IMAGE_ICON, 0, 0,
                                   con32.LR_LOADFROMFILE | con32.LR_DEFAULTSIZE)
        if Path(self.icon).exists():
            p = Path(self.icon).resolve()
            try:
                self._hicon = gui32.LoadImage(*getArgs(p))
                return True
            except Exception as e:
                self._showError(e, 'continue')

        imgFuncs = [
            lambda: gui32.LoadIcon(self._hinst, 1),
            lambda: gui32.LoadImage(*getArgs(py_icon)),
            lambda: gui32.LoadIcon(0, con32.IDI_APPLICATION)
        ]
        for i, getImg in enumerate(imgFuncs):
            try:
                self._hicon = getImg()
                break
            except Exception as e:
                if i < 2:
                    continue
                else:
                    self._showError(e, 'exit')
                    return False
        if self.icon:
            dwInfoFlags = dict(INFO=gui32.NIIF_INFO,
                               WARNING=gui32.NIIF_WARNING,
                               ERROR=gui32.NIIF_ERROR)
            self._infoFlags |= dwInfoFlags.get(str(self.icon).upper(), 0)
        return True
예제 #2
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
예제 #3
0
 def update_tray_icon(self):
     try:
         hIcon = win32gui.LoadIcon(win32gui.GetModuleHandle(None),
                                   win32con.IDI_APPLICATION)
     except:
         hIcon = win32gui.LoadIcon(None, win32con.IDI_APPLICATION)
     if self.__NOTIFY_ID is None:
         message = win32gui.NIM_ADD
     else:
         message = win32gui.NIM_MODIFY
     self.__NOTIFY_ID = (self.HWND, 0, win32gui.NIF_ICON
                         | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
                         self.MESSAGE, hIcon, self.tooltip)
     win32gui.Shell_NotifyIcon(message, self.__NOTIFY_ID)
예제 #4
0
    def _set_icon(self, icon_path=None):
        """Load the tray icon.

        Doesn't appear to be editable once it's been set.
        TODO: Look at http://www.brunningonline.net/simon/blog/archives/SysTrayIcon.py.html on how to edit it.
        """

        #Load icon as an image
        try:
            if icon_path is None or not os.path.isfile(icon_path):
                raise TypeError
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hinst = win32api.GetModuleHandle(None)
            hicon = win32gui.LoadImage(hinst, icon_path, win32con.IMAGE_ICON,
                                       0, 0, icon_flags)

        #Fallback to default windows icon
        except TypeError:
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (self.hwnd, 0, flags, TRAY_EVENT, hicon, self.program_name)
        try:
            win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
        except win32gui.error:
            # This is common when windows is starting, and this code is hit
            # before the taskbar has been created.
            # but keep running anyway - when explorer starts, we get the
            # TaskbarCreated message.
            pass

        self.logger.debug('Set tray icon.')
예제 #5
0
    def __init__(self):
        # 注册一个窗口类
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32gui.GetModuleHandle(None)
        wc.lpszClassName = "PythonRecordScreen"
        wc.lpfnWndProc = {win32con.WM_DESTROY: self.OnDestroy}
        classAtom = win32gui.RegisterClass(wc)
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, "PythonRecordScreen",
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)

        icon = os.path.join(
            os.path.abspath(os.path.dirname(__file__)) + 'ico.ico')
        if os.path.isfile(icon):

            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, icon, win32con.IMAGE_ICON, 0, 0,
                                       icon_flags)
        else:

            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        nid = (self.hwnd, 0, win32gui.NIF_ICON, win32con.WM_USER + 20, hicon,
               "PythonRecordScreen")
        win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
 def __init__(self):
     message_map = {
         win32con.WM_DESTROY: self.on_destroy,
         win32con.WM_COMMAND: self.on_command,
         win32con.WM_USER + 20: self.on_taskbar_notify
     }
     # Register the Window class.
     wc = win32gui.WNDCLASS()
     hinst = wc.hInstance = win32api.GetModuleHandle(None)
     wc.lpszClassName = "TimeCounter"
     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)
     # icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
     try:
         shell_dll = os.path.join(win32api.GetSystemDirectory(),
                                  "shell32.dll")
         large, small = win32gui.ExtractIconEx(shell_dll, 265, 1)
         hicon = small[0]
         win32gui.DestroyIcon(large[0])
     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,
            "Starting...")
     win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
     global handel
     handel = self.hwnd
예제 #7
0
    def refresh_icon(s):
        # 尝试找到自定义图标
        hinst = win32gui.GetModuleHandle(None)
        if os.path.isfile(s.icon):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst,
                                       s.icon,
                                       win32con.IMAGE_ICON,
                                       0,
                                       0,
                                       icon_flags)
        else:  # 找不到图标文件 - 使用默认值
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        if s.notify_id:
            message = win32gui.NIM_MODIFY
        else:
            message = win32gui.NIM_ADD
        s.notify_id = (s.hwnd,
                       0,
                       win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
                       win32con.WM_USER + 20,
                       hicon,
                       s.hover_text)
        win32gui.Shell_NotifyIcon(message, s.notify_id)
예제 #8
0
 def __init__(self, filename):
   def try_load(filename):
     try: icon = win32gui.LoadImage(None, filename, win32con.IMAGE_ICON, 0, 0, win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE | win32con.LR_SHARED)
     except: icon = None
     return icon
   self.hIcon = try_load(filename)
   if self.hIcon is None: self.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
예제 #9
0
    def draw_icon(self, icon):

        # Try and find a custom icon
        hinst = win32gui.GetModuleHandle(None)

        if os.path.isfile(icon):

            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            self.hicon = win32gui.LoadImage(hinst, icon, win32con.IMAGE_ICON,
                                            0, 0, icon_flags)

        else:

            logging.warning("Can't find icon file - using default.")
            self.hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        if self.notify_id:

            message = win32gui.NIM_MODIFY

        else:

            message = win32gui.NIM_ADD

        self.notify_id = (self.hWindow, 0, win32gui.NIF_ICON
                          | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
                          win32con.WM_USER + 20, self.hicon, self.hoverText)

        win32gui.Shell_NotifyIcon(message, self.notify_id)
예제 #10
0
    def _DoCreateIcons(self):
        # Try and find a custom icon
        hinst = win32api.GetModuleHandle(None)
        iconPathName = os.path.abspath(
            os.path.join(os.path.split(sys.executable)[0], "pyc.ico"))
        if not os.path.isfile(iconPathName):
            # Look in DLLs dir, a-la py 2.5
            iconPathName = os.path.abspath(
                os.path.join(
                    os.path.split(sys.executable)[0], "DLLs", "pyc.ico"))
        if not os.path.isfile(iconPathName):
            # Look in the source tree.
            iconPathName = os.path.abspath(
                os.path.join(
                    os.path.split(sys.executable)[0], "..\\PC\\pyc.ico"))
        if os.path.isfile(iconPathName):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, iconPathName,
                                       win32con.IMAGE_ICON, 0, 0, icon_flags)
        else:
            print("Can't find a Python icon file - using default")
            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,
               "Python Demo")
        try:
            win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
        except win32gui.error:
            # This is common when windows is starting, and this code is hit
            # before the taskbar has been created.
            print("Failed to add the taskbar icon - is explorer running?")
예제 #11
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()
예제 #12
0
    def refresh_icon(self, **data):

        if DEBUG: print(sys._getframe(0).f_code.co_name)

        hinst = win32gui.GetModuleHandle(None)
        if os.path.isfile(self.icon): # 尝试找到自定义图标
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst,
                                       self.icon,
                                       win32con.IMAGE_ICON,
                                       0,
                                       0,
                                       icon_flags)
        else: # 找不到图标文件 - 使用默认值
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        if self.notify_id: message = win32gui.NIM_MODIFY
        else: message = win32gui.NIM_ADD
        self.notify_id = (self.hwnd,
                          0,
                          win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
                          win32con.WM_USER+20,
                          hicon,
                          self.hover_text)
        win32gui.Shell_NotifyIcon(message, self.notify_id)
예제 #13
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()
예제 #14
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)
예제 #15
0
    def refresh(s, title='', msg='', time=500):
        '''刷新托盘图标
           title 标题
           msg   内容,为空的话就不显示提示
           time  提示显示时间'''
        hinst = win32gui.GetModuleHandle(None)
        if os.path.isfile(s.icon):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, s.icon, win32con.IMAGE_ICON, 0,
                                       0, icon_flags)
        else:  # 找不到图标文件 - 使用默认值
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        if s.notify_id:
            message = win32gui.NIM_MODIFY
        else:
            message = win32gui.NIM_ADD

        s.notify_id = (
            s.hwnd,
            0,  # 句柄、托盘图标ID
            win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
            | win32gui.NIF_INFO,
            # 托盘图标可以使用的功能的标识
            win32con.WM_USER + 20,
            hicon,
            s.hover_text,  # 回调消息ID、托盘图标句柄、图标字符串
            msg,
            time,
            title,  # 提示内容、提示显示时间、提示标题
            win32gui.NIIF_INFO  # 提示用到的图标
        )
        win32gui.Shell_NotifyIcon(message, s.notify_id)
예제 #16
0
    def create_icon(self, icon="icon.ico"):
        # If default icon exists, use it
        if os.path.isfile(icon):
            hinst = win32gui.GetModuleHandle(None)
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, icon, win32con.IMAGE_ICON, 0, 0,
                                       icon_flags)

        # No icon was found, using system default
        else:
            print "Can't find icon file - using default."
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        # Add icon to system tray
        if self.notify_id: message = win32gui.NIM_MODIFY
        else: message = win32gui.NIM_ADD

        # Create Tray and add to Taskbar
        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        self.notify_id = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon,
                          "willSpeak")
        try:
            win32gui.Shell_NotifyIcon(message, self.notify_id)
        except win32gui.error:
            # This is common when windows is starting, and this code is hit before the taskbar has been created.
            # When explorer starts, we get the TaskbarCreated message.
            print "Failed to add the taskbar icon - is explorer running?"
예제 #17
0
    def refresh_icon(self, is_init=True, trayMsg=None):
        hinst = win32gui.GetModuleHandle(None)
        # try to find custom icon file
        if os.path.isfile(self.icon):
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            hicon = win32gui.LoadImage(hinst, self.icon, win32con.IMAGE_ICON, 0,
                                       0, icon_flags)
        # if the custom icon not found, using default
        else:
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        if self.notify_id:
            message = win32gui.NIM_MODIFY
        else:
            message = win32gui.NIM_ADD
        self.notify_id = (self.hwnd, 0, win32gui.NIF_ICON | win32gui.NIF_MESSAGE
                          | win32gui.NIF_TIP, win32con.WM_USER + 20, hicon,
                          self.hover_text)
        win32gui.Shell_NotifyIcon(message, self.notify_id)
        if not is_init:
            if not (trayMsg and isinstance(trayMsg, TrayMessage)):
                raise ValueError(
                    '"{}" except a "winsystray.TrayMessage" object, but gaven "{}".'
                    .format(trayMsg,
                            type(trayMsg).__name__))
            win32gui.Shell_NotifyIcon(
                win32gui.NIM_MODIFY,
                (self.hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon,
                 trayMsg.app, trayMsg.msg, 200, trayMsg.title))
예제 #18
0
파일: fgReporter.py 프로젝트: gelio5/Hydra
def main():
    hInstance = win32api.GetModuleHandle()
    className = 'SimpleWin32'
    wndClass = win32gui.WNDCLASS()
    wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
    wndClass.lpfnWndProc = wndProc
    wndClass.hInstance = hInstance
    wndClass.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
    wndClass.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
    wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
    wndClass.lpszClassName = className

    try:
        wndClassAtom = win32gui.RegisterClass(wndClass)
    except Exception as e:
        raise e

    hWindow = win32gui.CreateWindow(
        wndClassAtom, 'FullGenReport', win32con.WS_OVERLAPPEDWINDOW,
        win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
        win32con.CW_USEDEFAULT, None, None, hInstance, None)

    win32gui.ShowWindow(hWindow, win32con.SW_SHOWNORMAL)
    win32gui.UpdateWindow(hWindow)
    win32gui.PumpMessages()
예제 #19
0
 def win32LoadIcon(self, iconPathName):
     icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
     try:
         return win32gui.LoadImage(self.hinst, iconPathName,
                                   win32con.IMAGE_ICON, 0, 0, icon_flags)
     except Exception, e:
         log.error("Failed to load icon at %s: %s", iconPathName, e)
         return win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
예제 #20
0
    def __init__(self,
                 title="Untitled",
                 style=None,
                 exstyle=None,
                 pos=(0, 0),
                 size=(400, 400),
                 background=None,
                 message_map={},
                 cursor=None):
        global _g_class_num

        if style is None:
            style = win32con.WS_OVERLAPPEDWINDOW
        if exstyle is None:
            style = win32con.WS_EX_LEFT
        if background is None:
            background = win32con.COLOR_WINDOW
        if cursor is None:
            cursor = win32con.IDC_ARROW

        self._instance = win32api.GetModuleHandle(None)

        self.message_map = {win32con.WM_DESTROY: self._on_destroy}
        self.message_map.update(message_map)

        _g_class_num += 1
        class_name = "class_name%d" % _g_class_num
        wc = win32gui.WNDCLASS()
        wc.hInstance = self._instance
        wc.lpfnWndProc = self.message_map  # could also specify a wndproc
        wc.lpszClassName = class_name
        wc.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        wc.hbrBackground = background
        wc.cbWndExtra = 0
        wc.hCursor = win32gui.LoadCursor(0, cursor)
        wc.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        class_atom = win32gui.RegisterClass(wc)

        # C code:
        # wc.cbWndExtra = DLGWINDOWEXTRA + sizeof(HBRUSH) + (sizeof(COLORREF));
        #wc.cbWndExtra = win32con.DLGWINDOWEXTRA + struct.calcsize("Pi")
        #wc.hIconSm = 0

        self._handle = win32gui.CreateWindowEx(
            exstyle,
            class_atom,
            title,
            style,  # win32con.WS_POPUP, # | win32con.WS_EX_TRANSPARENT,
            pos[0],
            pos[1],
            size[0],
            size[1],
            0,  # no parent
            0,  # no menu
            self._instance,
            None)
예제 #21
0
파일: mswgui.py 프로젝트: hiddenman/impexp
 def _register_class(self):
     # register a window class for toplevel windows.
     wndclass = win32gui.WNDCLASS()
     wndclass.hbrBackground = win32con.COLOR_BTNFACE + 1
     wndclass.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
     wndclass.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
     wndclass.lpszClassName = "msw.anygui.PythonWindow"
     wndclass.lpfnWndProc = self._wndproc
     self.__class__._wndclass = win32gui.RegisterClass(wndclass)
예제 #22
0
    def add_notify_icon(self, hicon=None, tooltip=None):
        """ Creates a notify icon for the gtk window. """
        if not self.notify_icon:
            if not hicon:
                hicon = win32gui.LoadIcon(0, IDI_APPLICATION)
            self.notify_icon = NotifyIcon(self._hwnd, hicon, tooltip)

            # Makes redraw if the taskbar is restarted.
            self.message_map({WM_TASKBARCREATED: self.notify_icon._redraw})
예제 #23
0
 def GetWndClassEx(self, hInstance, WndProc, szWindowClass='DesktopApp', Transparent=True):
     WndClassEx                   = WNDCLASSEX()
     WndClassEx.cbSize            = ctypes.sizeof(WNDCLASSEX)
     WndClassEx.style             = win32con.CS_HREDRAW | win32con.CS_VREDRAW
     WndClassEx.lpfnWndProc       = WNDPROCTYPE(WndProc)
     WndClassEx.cbClsExtra        = 0
     WndClassEx.cbWndExtra        = 0
     WndClassEx.hInstance         = hInstance
     WndClassEx.hIcon             = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
     WndClassEx.hCursor           = win32gui.LoadCursor(0, win32con.IDC_ARROW)
     if Transparent:
         WndClassEx.hbrBackground = self.RGB(0,0,0)
     else:
         WndClassEx.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
     WndClassEx.lpszMenuName      = None
     WndClassEx.lpszClassName     = szWindowClass
     WndClassEx.hIconSm           = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
     return WndClassEx
예제 #24
0
    def __init__(self, title, message, icon_path=None):  # noqa: D107
        try:
            import win32con
        except ImportError as e:  # noqa: F841
            logger.debug(
                'Failed to import win32con: {e}'.format_map(locals()))
            return
        try:
            import win32gui
        except ImportError as e:  # noqa: F841
            logger.debug(
                'Failed to import win32gui: {e}'.format_map(locals()))
            return

        wc, class_atom = NotificationWindow._create_window_class()

        # create the window
        hwnd = win32gui.CreateWindow(
            NotificationWindow._class_atom,
            'Colcon notification',  # window class name
            win32con.WS_OVERLAPPED | win32con.WS_SYSMENU,  # style
            0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
            0, 0, NotificationWindow._wc.hInstance, None)
        win32gui.UpdateWindow(hwnd)

        # load icon image
        try:
            if icon_path is None:
                # use fall back
                raise Exception()
            hicon = win32gui.LoadImage(
                NotificationWindow._wc.hInstance, icon_path,
                win32con.IMAGE_ICON, 0, 0,
                win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE,  # flags
            )
        except Exception:  # noqa: B902
            hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)

        # show the notification
        flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
        nid = (hwnd, 0, flags, win32con.WM_USER + 20, hicon, 'tooltip')
        try:
            win32gui.Shell_NotifyIcon(
                win32gui.NIM_ADD, nid)
            win32gui.Shell_NotifyIcon(
                win32gui.NIM_MODIFY, (
                    hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon,
                    'Balloon  tooltip', message, 200, title))
        except Exception as e:  # noqa: F841
            logger.debug(
                'Failed to show the notification: {e}'.format_map(locals()))
        else:
            # wait a while before destroying the window
            time.sleep(5)
        finally:
            win32gui.DestroyWindow(hwnd)
예제 #25
0
    def setIcon(self, hicon=None, tooltip=None):
        if type(hicon) == str:
            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
            try:
                # hicon = win32gui.LoadImage(self.handlerInstance, hicon, win32con.IMAGE_ICON, 0, 0, icon_flags)
                hicon = win32gui.LoadImage(0, hicon, win32con.IMAGE_ICON, 0, 0,
                                           win32con.LR_LOADFROMFILE)

            except Exception, e:
                hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
예제 #26
0
파일: windows.py 프로젝트: kazarin1alex/lit
def get_hicon(hWin):
    hIcon = win32api.SendMessage(hWin, win32con.WM_GETICON, win32con.FALSE, 0)
    if hIcon == win32con.NULL:
        hIcon = win32api.SendMessage(hWin, win32con.WM_GETICON, win32con.TRUE, 0)
    if hIcon == win32con.NULL:
        hIcon = win32gui.GetClassLong(hWin, win32con.GCL_HICONSM)
    if hIcon == win32con.NULL:
        hIcon = win32gui.GetClassLong(hWin, win32con.GCL_HICON)
    if hIcon == win32con.NULL:
        hIcon = win32gui.LoadIcon(win32con.NULL, MAKEINTRESOURCE(win32con.IDI_APPLICATION))
    return hIcon
예제 #27
0
    def __init__(self, className, serverIp, serverPort, **opts):
        message_map = {
            win32con.WM_DESTROY: self.OnDestroy,
            win32con.WM_CLOSE: self.OnClose,
            win32con.WM_COPYDATA: self.OnCopyData,
        }

        wc = win32gui.WNDCLASS()
        wc.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
        wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        wc.hbrBackground = win32con.COLOR_WINDOW
        #		wc.lpszClassName = "WinAdapter"
        wc.lpszClassName = className
        wc.lpfnWndProc = message_map
        self.hinst = wc.hInstance = win32api.GetModuleHandle(None)
        self.cAtom = win32gui.RegisterClass(wc)

        self.ConnectorHash = {}
        self.conList = []
        self.busTh = None  # busServer thread

        #print 'adapter: hinst: %s\n' % self.hinst

        self.hwnd = win32gui.CreateWindowEx(
            win32con.WS_EX_APPWINDOW,
            self.cAtom,
            className,  #"WinAdapter App",
            win32con.WS_OVERLAPPED | win32con.WS_SYSMENU,
            win32con.CW_USEDEFAULT,
            0,
            win32con.CW_USEDEFAULT,
            0,
            0,
            0,
            self.hinst,
            None)

        global g_HWNDMAIN
        g_HWNDMAIN = self.hwnd

        ##win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWDEFAULT)
        #win32gui.UpdateWindow(self.hwnd)

        __LOG__.Trace("WINDOW :[%d]" % (g_HWNDMAIN), (logging.CRITICAL))

        self.serverIp = serverIp
        self.serverPort = serverPort
        self.busTh = busThread(self.serverIp, self.serverPort, **opts)
        self.busTh.setDaemon(True)
        self.busTh.start()

        self.queueTh = queueThread()
        self.queueTh.setDaemon(True)
        self.queueTh.start()
예제 #28
0
 def RegisterClass(self):
     WndProc = {WM_DESTROY: self.OnDestroy}
     wc = win32gui.WNDCLASS()
     wc.hInstance = self.hinst
     wc.hbrBackground = COLOR_BTNFACE + 1
     wc.hCursor = win32gui.LoadCursor(0, IDC_ARROW)
     wc.hIcon = win32gui.LoadIcon(0, IDI_APPLICATION)
     wc.lpszClassName = 'FontFuzzer{}'.format(self.classNameRandom)
     wc.lpfnWndProc = WndProc
     reg = win32gui.RegisterClass(wc)
     return reg
예제 #29
0
 def RegisterClass(self):
     ''' Register class '''
     WndProc = {WM_DESTROY: self.OnDestroy}
     wc = win32gui.WNDCLASS()
     wc.hInstance = self.hinst
     wc.hbrBackground = WHITE_BRUSH
     wc.hCursor = win32gui.LoadCursor(0, IDC_ARROW)
     wc.hIcon = win32gui.LoadIcon(0, IDI_APPLICATION)
     wc.lpszClassName = "ttf fuzzer"
     wc.lpfnWndProc = WndProc
     reg = win32gui.RegisterClass(wc)
     return reg
예제 #30
0
 def load(self, icon_value):
   if type(icon_value) is icon:
     self.hIcon = icon_value.hIcon
   elif type(icon_value) is int:
     self.hIcon = icon_value
   else:
     def try_load(filename):
       try: i = win32gui.LoadImage(None, filename, win32con.IMAGE_ICON, 0, 0, win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE | win32con.LR_SHARED)
       except: i = None
       return i
     self.hIcon = try_load(filename)
     if self.hIcon is None: self.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)