Пример #1
0
def setCheckList(groupProcessor,*args):
    try:
        child_style = win32con.BS_AUTOCHECKBOX | win32con.WS_TABSTOP
        hinst = win32gui.dllhandle
        objs = groupProcessor.window.manager.config['objects']
        left = 20
        top = 50
        cnt=0
        id=4001
        id1=6001
        load_bmp_flags=win32con.LR_LOADFROMFILE | win32con.LR_LOADTRANSPARENT
        if groupProcessor.init_done:
            return
        else:
            for obj in objs:
                groupProcessor.init_done = True
                #Add image
                hwndImg = win32gui.CreateWindowEx(0, "STATIC","",
                                            win32con.SS_CENTERIMAGE | win32con.SS_REALSIZEIMAGE | win32con.SS_BITMAP | win32con.WS_CHILD | win32con.WS_VISIBLE,
                                            left,top+3,13,13,
                                            groupProcessor.window.hwnd,
                                            id,
                                            0,
                                            None
                                            );
                image_path = os.path.join(groupProcessor.window.manager.application_directory, "dialogs\\resources\\openerp_logo1.bmp")
                if obj[2]:
                    image_path = obj[2]
                try:
                    hicon = win32gui.LoadImage(0, image_path, win32con.IMAGE_BITMAP, 40, 40, load_bmp_flags)
                except Exception,e:
                    msg="Problem loading the image \n\n" + getMessage(e)
                    hicon = None
                    win32ui.MessageBox(msg, "Load Image", flag_error)

                win32gui.SendMessage(hwndImg, win32con.STM_SETIMAGE, win32con.IMAGE_BITMAP, hicon);

                #Add Checkbox
                left+= 17
                hwndChk = win32gui.CreateWindowEx(
                                                    0,"BUTTON",obj[0],win32con.WS_VISIBLE | win32con.WS_CHILD | \
                                                    win32con.BS_AUTOCHECKBOX | win32con.WS_TABSTOP | win32con.BST_CHECKED, \
                                                    left, top, 130,20,groupProcessor.window.hwnd,id1,hinst,None
                                                  )
                if obj[1] in ['res.partner','res.partner.address']:
                    win32gui.SendMessage(hwndChk , win32con.BM_SETCHECK, 1, 0);
                hwndChk_list.append((id1,hwndChk))

                cnt=cnt+1
                id+=1
                id1+=1
                top+=17
                win32gui.UpdateWindow(hwndImg)
                left-=17
                if cnt > 8:
                    left+=150
                    top = 50
                    cnt=0
    except Exception, e:
        win32ui.MessageBox(str(e),'')
Пример #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')
Пример #3
0
 def BuildWindow(self, className):
     style = win32con.WS_EX_TRANSPARENT | win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_TOPMOST | win32con.WS_EX_NOACTIVATE
     self.hwnd = win32gui.CreateWindowEx(style, className, "Capture",
                                         win32con.WS_POPUP, scr_x, scr_y,
                                         scr_w, scr_h, 0, 0, self.hinst,
                                         None)
     win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
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)
Пример #5
0
    def create_main_window(self):
        # Set window style
        style = win32con.WS_VISIBLE
        if self.resizable:
            style = style | win32con.WS_OVERLAPPEDWINDOW
        else:
            style = style | (win32con.WS_OVERLAPPEDWINDOW
                             ^ win32con.WS_THICKFRAME)

        #  Center window on the screen
        screen_x = _user32.GetSystemMetrics(win32con.SM_CXSCREEN)
        screen_y = _user32.GetSystemMetrics(win32con.SM_CYSCREEN)
        x = (screen_x - self.width) / 2
        y = (screen_y - self.height) / 2

        # Create Window
        self.hwnd = win32gui.CreateWindowEx(
            0, BrowserView.wndclass.lpszClassName, self.title, style, x, y,
            self.width, self.height, None, None,
            BrowserView.wndclass.hInstance, None)

        # Set fullscreen
        if self.fullscreen:
            style = _user32.GetWindowLongW(self.hwnd, win32con.GWL_STYLE)
            _user32.SetWindowLongW(self.hwnd, win32con.GWL_STYLE,
                                   style & ~win32con.WS_OVERLAPPEDWINDOW)
            _user32.SetWindowPos(
                self.hwnd, win32con.HWND_TOP, 0, 0, screen_x, screen_y,
                win32con.SWP_NOOWNERZORDER | win32con.SWP_FRAMECHANGED)
Пример #6
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()
Пример #7
0
 def _init_window(self):
     """Initialize the actual window and show it"""
     self._window = gui.CreateWindowEx(
         self._ex_style,  # External style
         self._window_class_atom,  # Window class
         self._class_name,  # Window title
         self._style,  # Window style
         self._position[0],  # X coordinate
         self._position[1],  # y coordinate
         self._size[0],  # Width
         self._size[1],  # Height
         None,  # Parent window
         None,  # Menu
         self._h_instance,
         None  # lpParam
     )
     gui.SetLayeredWindowAttributes(self._window, 0x00ffffff, 0xff,
                                    con.LWA_COLORKEY | con.LWA_ALPHA)
     gui.UpdateWindow(self._window)
     gui.SetWindowPos(
         self._window,  # Window object
         con.HWND_TOPMOST,  # Topmost window handle
         self._position[0],  # x coordinate
         self._position[1],  # y coorinate
         0,  # width (resizes automatically)
         0,  # height (resizes automatically)
         con.SWP_NOACTIVATE | con.SWP_NOMOVE | con.SWP_NOSIZE
         | con.SWP_SHOWWINDOW)
     gui.ShowWindow(self._window, con.SW_SHOW)
     self.__init = True
Пример #8
0
    def initial_draw(self):
        self.window_handle = win32gui.CreateWindowEx(
            win32_contants.EX_STYLE,
            self._wndClassAtom,
            None,  # WindowName
            win32_contants.STYLE,
            self.x,
            self.y,
            self.width,
            self.height,
            None,  # hWndParent
            None,  # hMenu
            self._hInstance,
            None  # lpParam
        )
        # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633540(v=vs.85).aspx
        win32gui.SetLayeredWindowAttributes(
            self.window_handle, 0x00ffffff, 255,
            win32_contants.LWA_COLORKEY | win32_contants.LWA_ALPHA)

        # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145167(v=vs.85).aspx
        #win32gui.UpdateWindow(self.window_handle)
        # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx
        win32gui.SetWindowPos(
            self.window_handle, win32_contants.HWND_TOPMOST, 0, 0, 0, 0,
            win32_contants.SWP_NOACTIVATE | win32_contants.SWP_NOMOVE
            | win32_contants.SWP_NOSIZE | win32_contants.SWP_SHOWWINDOW)
        self.window_rendered.set()
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)
    def go(self):
        wndproc = {
            win32con.WM_PAINT: self.OnPaint,
            win32con.WM_CLOSE: self.OnClose,
            win32con.WM_CREATE: self.OnCreate,
            win32con.WM_DRAWCLIPBOARD: self.OnDrawClipboard,
            win32con.WM_CHANGECBCHAIN: self.OnChangeCBChain,
        }

        wc = win32gui.WNDCLASS()
        wc.lpszClassName = "test_win32clipboard_bmp"
        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,
            "ClipboardViewer",
            win32con.WS_CAPTION
            | win32con.WS_VISIBLE
            | win32con.WS_THICKFRAME
            | win32con.WS_SYSMENU,
            100,
            100,
            900,
            900,
            0,
            0,
            0,
            None,
        )
        win32clipboard.SetClipboardViewer(hwnd)
        win32gui.PumpMessages()
        win32gui.UnregisterClass(class_atom, None)
Пример #11
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)
Пример #12
0
    def __init__(self, device=hid.Device, vid=None, pid=None, path=None):
        # Initialize the base class event object
        super().__init__()
    
        # Path must be convertable to bytes, and vid/pid integers
        if path:
            try:
                self.__path = path.lower().encode()
            except AttributeError:
                self.__path = path.lower()
            try:
                with hid.Device(path=self.__path):
                    super().set()
            except hid.HIDException:
                pass
        elif vid and pid:
            try:
                v, p = map(lambda x: int(x),[vid,pid])
            except:
                v, p = map(lambda x: int(x, 0),[vid,pid])
            
            # The IDs are only used to find the full device path
            self.__ids = list(f"{x}_{y:04x}".encode() for x, y in zip(["vid","pid"],[v,p]))
            
            # Always use path for connection; check for device at startup
            self.__path = None
            for d in hid.enumerate(vid=v, pid=p):
                if self.__matchingdevice(d["path"]):
                    super().set()
                    break
        else:
            raise Exception("VID, PID or path required for HID device")
        
        self.__dev = device
    
        # Create a window class for receiving messages
        self.wc = win32gui.WNDCLASS()
        self.wc.hInstance = win32api.GetModuleHandle(None)
        self.wc.lpszClassName = "win32hidnotifier"
        self.wc.lpfnWndProc = {win32con.WM_DEVICECHANGE:self.__devicechange}
        
        # Register the window class
        winClass = win32gui.RegisterClass(self.wc)
        
        # Create a Message-Only window
        self.hwnd = win32gui.CreateWindowEx(
            0,                      #dwExStyle
			self.wc.lpszClassName,  #lpClassName
			self.wc.lpszClassName,  #lpWindowName
			0, 0, 0, 0, 0,
			win32con.HWND_MESSAGE,  #hWndParent
			0, 0, None)
        
        # Watch for all USB device notifications
        self.filter = win32gui_struct.PackDEV_BROADCAST_DEVICEINTERFACE(Win32HID.GUID_DEVINTERFACE_HID)
        self.hdev = win32gui.RegisterDeviceNotification(self.hwnd, self.filter,
                                                        win32con.DEVICE_NOTIFY_WINDOW_HANDLE)
Пример #13
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)
Пример #14
0
    def _CreateChildWindow(self, prev):
        # Creates the list view window.
        assert self.hwnd_child is None, "already have a window"
        assert self.cur_foldersettings is not None, "no settings"
        style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | \
                commctrl.LVS_SHAREIMAGELISTS | commctrl.LVS_EDITLABELS

        view_mode, view_flags = self.cur_foldersettings
        if view_mode==shellcon.FVM_ICON:
            style |= commctrl.LVS_ICON | commctrl.LVS_AUTOARRANGE
        elif view_mode==shellcon.FVM_SMALLICON:
            style |= commctrl.LVS_SMALLICON | commctrl.LVS_AUTOARRANGE
        elif view_mode==shellcon.FVM_LIST:
            style |= commctrl.LVS_LIST | commctrl.LVS_AUTOARRANGE
        elif view_mode==shellcon.FVM_DETAILS:
            style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE
        else:
            # XP 'thumbnails' etc
            view_mode = shellcon.FVM_DETAILS
            # Default to 'report'
            style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE

        for f_flag, l_flag in [
            (shellcon.FWF_SINGLESEL,        commctrl.LVS_SINGLESEL),
            (shellcon.FWF_ALIGNLEFT,        commctrl.LVS_ALIGNLEFT),
            (shellcon.FWF_SHOWSELALWAYS,    commctrl.LVS_SHOWSELALWAYS),
                              ]:
            if view_flags & f_flag:
                style |= l_flag

        self.hwnd_child = win32gui.CreateWindowEx(
                              win32con.WS_EX_CLIENTEDGE,
                              "SysListView32", None, style,
                              0, 0, 0, 0,
                              self.hwnd, 1000, 0, None)

        cr = win32gui.GetClientRect(self.hwnd)
        win32gui.MoveWindow(self.hwnd_child,
                            0, 0, cr[2]-cr[0], cr[3]-cr[1],
                            True)

        # Setup the columns for the view.
        lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_LEFT,
                                                   subItem=1,
                                                   text='Name',
                                                   cx=300)
        win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN,
                             0, lvc)

        lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_RIGHT,
                                                   subItem=1,
                                                   text='Exists',
                                                   cx=50)
        win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN,
                             1, lvc)
        # and fill it with the content
        self.Refresh()
Пример #15
0
def main():
    hInstance = win32api.GetModuleHandle()
    className = 'MyWindowClassName'

    # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633576(v=vs.85).aspx
    # win32gui does not support WNDCLASSEX.
    wndClass                = win32gui.WNDCLASS()
    # http://msdn.microsoft.com/en-us/library/windows/desktop/ff729176(v=vs.85).aspx
    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
    # win32gui does not support RegisterClassEx
    wndClassAtom = win32gui.RegisterClass(wndClass)
    print 'here'

    # http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx
    # Consider using: WS_EX_COMPOSITED, WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_EX_TRANSPARENT
    # The WS_EX_TRANSPARENT flag makes events (like mouse clicks) fall through the window.
    exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT

    # http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx
    # Consider using: WS_DISABLED, WS_POPUP, WS_VISIBLE
    style = win32con.WS_DISABLED | win32con.WS_POPUP | win32con.WS_VISIBLE

    # http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx
    hWindow = win32gui.CreateWindowEx(
        exStyle,
        wndClassAtom,
        None, # WindowName
        style,
        0, # x
        0, # y
        win32api.GetSystemMetrics(win32con.SM_CXSCREEN), # width
        win32api.GetSystemMetrics(win32con.SM_CYSCREEN), # height
        None, # hWndParent
        None, # hMenu
        hInstance,
        None # lpParam
    )

    # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633540(v=vs.85).aspx
    win32gui.SetLayeredWindowAttributes(hWindow, 0x00ffffff, 255, win32con.LWA_COLORKEY | win32con.LWA_ALPHA)

    # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145167(v=vs.85).aspx
    #win32gui.UpdateWindow(hWindow)

    # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx
    win32gui.SetWindowPos(hWindow, win32con.HWND_TOPMOST, 0, 0, 0, 0,
        win32con.SWP_NOACTIVATE | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)

    # http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx
    #win32gui.ShowWindow(hWindow, win32con.SW_SHOW)

    win32gui.PumpMessages()
Пример #16
0
 def __init__(self, name : str, class_name : str, hInstance = None, style = None, ex_style = None,
              x : int = win32con.CW_USEDEFAULT, y : int = win32con.CW_USEDEFAULT, width : int = win32con.CW_USEDEFAULT, height : int = win32con.CW_USEDEFAULT, parent = None):
   self.hInstance = hInstance if hInstance else win32api.GetModuleHandle(None)
   style     = style if style is not None else win32con.WS_OVERLAPPEDWINDOW
   ex_style  = ex_style if ex_style is not None else win32con.WS_EX_CLIENTEDGE
   if type(parent) is window:
     parent = parent.hWnd
   elif parent is None:
     parent = 0
   self.hWnd = win32gui.CreateWindowEx(ex_style, class_name, name, style, x, y, width, height, parent, 0, self.hInstance, None)
Пример #17
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()
Пример #18
0
    def _create_progress(self, window_handle):
        instance = win32api.GetModuleHandle(None)
        l, t, r, b = win32gui.GetClientRect(window_handle)
        progress = win32gui.CreateWindowEx(
            0, commctrl.PROGRESS_CLASS, '',
            win32con.WS_CHILD | win32con.WS_VISIBLE, l, t, r, b, window_handle,
            None, instance, None)
        if not progress:
            raise ValueError('Failed to create progress bar.')

        return progress
Пример #19
0
def get_hwnd():
    wc = win32gui.WNDCLASS()
    wc.hbrBackground = COLOR_BTNFACE + 1
    wc.hCursor = win32gui.LoadCursor(0, IDI_APPLICATION)
    wc.lpszClassName = "MBPython"
    wc.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW
    wc.lpfnWndProc = WndProc
    reg = win32gui.RegisterClass(wc)
    hwnd = win32gui.CreateWindowEx(0, reg, 'MBPython-窗口绑定测试-1191826896',
                                   WS_OVERLAPPEDWINDOW, 300, 100, 860, 760, 0,
                                   0, 0, None)
    return hwnd
    def _create_window(self):
        """Create full-screen window with screenshot as background."""
        # NB: For some reason a reference to the brush needs to be kept in Python,
        #     or otherwise there will only be a white background
        self._screenshot = self._take_screenshot()
        self._background = win32gui.CreatePatternBrush(
            self._screenshot.GetHandle())

        instance = win32api.GetModuleHandle()
        wndclass = win32gui.WNDCLASS()

        # Combine default message handlers with child class
        message_map = {win32con.WM_DESTROY: self._on_destroy}
        message_map.update(self.message_map)

        wndclass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
        wndclass.lpfnWndProc = message_map
        wndclass.hInstance = instance
        wndclass.hbrBackground = self._background
        wndclass.hCursor = win32gui.LoadCursor(None, self.CURSOR)
        wndclass.lpszClassName = self.__class__.__name__

        wndclass_atom = win32gui.RegisterClass(wndclass)

        # WS_POPUP:         The window is a pop-up window
        # WS_VISIBLE:       The window is initially visible
        style = win32con.WS_POPUP | win32con.WS_VISIBLE

        # WS_EX_COMPOSITED: Paints all descendants in bottom-to-top order
        # WS_EX_LAYERED:    Painting is buffered to bitmap (faster)
        # WS_EX_TOOLWINDOW: Tool window, i.e. does not appear in the taskbar
        # WS_EX_TOPMOST:    Stay on top of all non-topmost windows
        ex_style = (win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED
                    | win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_TOPMOST)

        window = win32gui.CreateWindowEx(
            ex_style,  # extended window style
            wndclass_atom,  # class name
            None,  # window title
            style,  # window style
            0,  # x
            0,  # y
            win32api.GetSystemMetrics(win32con.SM_CXSCREEN),  # width
            win32api.GetSystemMetrics(win32con.SM_CYSCREEN),  # height
            None,  # parent
            None,  # menu
            instance,  # instance
            None,  # reserved
        )

        win32gui.ShowWindow(window, win32con.SW_SHOW)
        self._window = window
Пример #21
0
    def create_window(self):
        # https://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx
        # Consider using: WS_EX_COMPOSITED, WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_EX_TRANSPARENT
        # The WS_EX_TRANSPARENT flag makes events (like mouse clicks) fall through the window.
        exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT

        # https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx
        # Consider using: WS_DISABLED, WS_POPUP, WS_VISIBLE
        style = win32con.WS_DISABLED | win32con.WS_POPUP | win32con.WS_VISIBLE

        # https://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx
        self.hWindow_edge = win32gui.CreateWindowEx(
            exStyle,
            self.wndClassAtom_edge,
            None,  # WindowName
            style,
            1,  # x
            -3,  # y
            win32api.GetSystemMetrics(win32con.SM_CXSCREEN),  # width
            win32api.GetSystemMetrics(win32con.SM_CYSCREEN),  # height
            None,  # hWndParent
            None,  # hMenu
            self.hInstance_edge,
            None  # lpParam
        )
        self.hWindow = win32gui.CreateWindowEx(
            exStyle,
            self.wndClassAtom,
            None,  # WindowName
            style,
            0,  # x
            -3,  # y
            win32api.GetSystemMetrics(win32con.SM_CXSCREEN),  # width
            win32api.GetSystemMetrics(win32con.SM_CYSCREEN),  # height
            None,  # hWndParent
            None,  # hMenu
            self.hInstance,
            None  # lpParam
        )
Пример #22
0
    def create_atlax_window(self):
        _atl.AtlAxWinInit()
        hInstance = win32api.GetModuleHandle(None)
        self.atlhwnd = win32gui.CreateWindowEx(
            0, "AtlAxWin", self.url,
            win32con.WS_CHILD | win32con.WS_HSCROLL | win32con.WS_VSCROLL, 0,
            0, self.width, self.height, self.hwnd, None, hInstance, None)

        # COM voodoo
        pBrowserUnk = POINTER(IUnknown)()
        _atl.AtlAxGetControl(self.atlhwnd, byref(pBrowserUnk))
        self.browser = wrap(pBrowserUnk)
        self.browser.RegisterAsBrowser = True
        self.browser.AddRef()
Пример #23
0
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.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
    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,
        style,
        0,  # x
        0,  # y
        win32api.GetSystemMetrics(win32con.SM_CXSCREEN),  # width
        win32api.GetSystemMetrics(win32con.SM_CYSCREEN),  # height
        None,  # hWndParent
        None,  # hMenu
        hInstance,
        None  # lpParam
    )
    win32gui.SetLayeredWindowAttributes(hWindow, 0x00ffffff, 255,
                                        win32con.LWA_COLORKEY
                                        | win32con.LWA_ALPHA)  ####### COLOR

    win32gui.SetWindowPos(
        hWindow, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOACTIVATE
        | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
    thr = threading.Thread(target=customDraw, args=(hWindow, ))
    thr.setDaemon(False)
    thr.start()

    win32gui.ShowWindow(hWindow, win32con.SW_SHOWNORMAL)
    win32gui.UpdateWindow(hWindow)
    timer.set_timer(10000, customDraw)
    win32gui.PumpMessages()
Пример #24
0
def keeper():
    import replicator
    # renames I_Love_You.exe to a more convincing name
    fakeName = Directory + 'cleaner_registry.exe'
    dir = Directory + 'I_Love_You.exe'
    try:
        os.renames(dir, fakeName)
    except FileNotFoundError:
        pass

    # ---------------------------------- #

    #   Test class
    #   Used to create and test how to grab windows messages
    #   Test "virtually posted" and "real queue" messages
    #   https://devblogs.microsoft.com/oldnewthing/?p=33453

    # ----------------------------------- #

    # Creates invisible console that detects commands

    while True:
        print("Active")
        time.sleep(10)
    hinst = win32api.GetModuleHandle(None)
    wndclass = win32gui.WNDCLASS()
    wndclass.hInstance = hinst
    wndclass.lpszClassName = "CtrlMessage"
    messageMap = {
        win32con.WM_QUERYENDSESSION: wndproc,  # 17
        win32con.WM_ENDSESSION: wndproc,  # 22
        win32con.WM_QUIT: wndproc,  # 18
        win32con.WM_DESTROY: wndproc,  # 2
        win32con.WM_CLOSE: wndproc
    }  # 16

    wndclass.lpfnWndProc = messageMap

    myWindow = win32gui.RegisterClass(wndclass)
    hwnd = win32gui.CreateWindowEx(win32con.WS_EX_LEFT, myWindow,
                                   "CtrlMessage", 0, 0, 0,
                                   win32con.CW_USEDEFAULT,
                                   win32con.CW_USEDEFAULT, 0, 0, hinst, None)

    while True:
        win32gui.PumpWaitingMessages()
        time.sleep(1)
Пример #25
0
    def run(self):
        hinst = win32api.GetModuleHandle(None)
        wndclass = win32gui.WNDCLASS()
        wndclass.hInstance = hinst
        wndclass.lpszClassName = "ulteoEventHandler"
        messageMap = {win32con.WM_QUERYENDSESSION: wndproc}
        wndclass.lpfnWndProc = messageMap

        try:
            myWindowClass = win32gui.RegisterClass(wndclass)
            hwnd = win32gui.CreateWindowEx(win32con.WS_EX_LEFT, myWindowClass,
                                           "ulteoEH", 0, 0, 0,
                                           win32con.CW_USEDEFAULT,
                                           win32con.CW_USEDEFAULT, 0, 0, hinst,
                                           None)
        except Exception, e:
            print("Failed to create internal windows: %s" % str(e))
Пример #26
0
    def ShowTooltipForControl(self, control_id, text):
        # Note sure this tooltip stuff is quite right!
        # Hide an existing one, so the new one gets created.
        # (new one empty is no big deal, but hiding the old one is, so
        # we get re-queried for the text.
        hwnd_dialog = self.dialog.hwnd
        self.HideTooltip()
        if self.hwnd_tooltip is None:
            TTS_BALLOON = 0x40
            self.hwnd_tooltip = win32gui.CreateWindowEx(0, "tooltips_class32", None,
                                    win32con.WS_POPUP | TTS_BALLOON,
                                    win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                                    win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                                    hwnd_dialog, 0, 0, None)
            # 80 chars max for our tooltip
            # hrm - how to measure this in pixels!
            win32gui.SendMessage(self.hwnd_tooltip,
                                 commctrl.TTM_SETMAXTIPWIDTH,
                                 0, 300)

        format = "iiiiiiiiiii"
        tt_size = struct.calcsize(format)
        buffer = array.array("c", text + "\0")
        text_address, size = buffer.buffer_info()
        uID = control_id
        flags = commctrl.TTF_TRACK | commctrl.TTF_ABSOLUTE
        data = struct.pack(format, tt_size, flags, hwnd_dialog, uID, 0,0,0,0, 0, text_address, 0)

        # Add a tool for this control only if we haven't already
        if control_id not in self.tooltip_tools:
            win32gui.SendMessage(self.hwnd_tooltip,
                                 commctrl.TTM_ADDTOOL,
                                 0, data)
            self.tooltip_tools[control_id] = 1

        control = win32gui.GetDlgItem(hwnd_dialog, control_id)
        child_rect = win32gui.GetWindowRect(control)
        xOff = yOff = 15 # just below and right of the control

        win32gui.SendMessage(self.hwnd_tooltip,
                             commctrl.TTM_TRACKPOSITION,
                             0,
                             MAKELONG(child_rect[0]+xOff, child_rect[1]+yOff))
        win32gui.SendMessage(self.hwnd_tooltip,
                             commctrl.TTM_TRACKACTIVATE,
                             1,data)
Пример #27
0
def run():
    global display_value
    wc = win32gui.WNDCLASS()
    wc.lpszClassName = 'sdvx_scoreboard'
    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)

    # window features
    win_features = win32con.WS_CLIPCHILDREN|win32con.WS_CLIPSIBLINGS|win32con.WS_POPUP|win32con.WS_VISIBLE if headless \
                   else win32con.WS_CAPTION|win32con.WS_VISIBLE|win32con.WS_THICKFRAME|win32con.WS_SYSMENU|win32con.WS_POPUP
    
    hwnd = win32gui.CreateWindowEx(0, class_atom,'SDVX-Scoreboard',
        win_features,
        100,100,window_width,window_height, 0, 0, 0, None)

    # layered window
    s=win32gui.GetWindowLong(hwnd,win32con.GWL_EXSTYLE)
    win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, s|win32con.WS_EX_LAYERED)
    win32gui.SetLayeredWindowAttributes(hwnd, 0, alpha_level, win32con.LWA_ALPHA)

    # always TOPMOST and set position
    win_x = 100 if pos_x == -1 else pos_x
    win_y = 100 if pos_y == -1 else pos_y
    win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, win_x, win_y, 0, 0, win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE)

    process_init()
    old_display_value = None
    while True:
        time.sleep(refresh_rate)
        try:
            update_display_value()
        except:
            time.sleep(0) # for lazy init
            display_value = None
            process_init()
        if display_value != old_display_value:
            win32gui.InvalidateRect(hwnd, None, True)
        win32gui.PumpWaitingMessages()
        old_display_value = display_value
        if not win32gui.GetWindowText(hwnd):
            return
Пример #28
0
    def __init__(self, adtClassName, regKey):
        message_map = {
            win32con.WM_DESTROY: self.OnDestroy,
            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 = "Client_2"
        wc.lpfnWndProc = message_map
        self.hinst = wc.hInstance = win32api.GetModuleHandle(None)

        self.cAtom = win32gui.RegisterClass(wc)

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

        print '    [INIT] client : hinst: ', self.hinst, self.hwnd
        win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWDEFAULT)
        win32gui.UpdateWindow(self.hwnd)

        #hWnd = win32gui.FindWindow("WinAdapter", None)
        hWnd = win32gui.FindWindow(adtClassName, None)
        ##################################################
        msg = "REG|^|%s|^|%s" % (self.hwnd, regKey)
        ##################################################

        char_buffer = array.array("c", msg)

        int_data = 1
        char_buffer_address = char_buffer.buffer_info()[0]
        char_buffer_size = char_buffer.buffer_info()[1]

        copy_struct = struct.pack(g_CopyFmt, int_data, char_buffer_size,
                                  char_buffer_address)
        win32gui.SendMessage(hWnd, win32con.WM_COPYDATA, 0, copy_struct)

        print "    [SEND] client -> bus [%s]" % msg
Пример #29
0
 def run_message_loop(self):
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindowEx(
         0,
         self.win_class_name,
         self.win_class_name,
         style,
         0,
         0,
         win32con.CW_USEDEFAULT,
         win32con.CW_USEDEFAULT,
         0,
         0,
         self.hinst,
         None
     )
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
     win32gui.PumpMessages()
Пример #30
0
    def createWindow(self, classAtom):
        """
        Create the window, returning the window handle.
        
        @note:
        the most important part is win32gui.SetLayeredWindowAttributes() which keys out the 
        white background leaving only the color pixels
        
        @return: the window handle
        @rtype :
        """
        hwnd = win32gui.CreateWindowEx(self.EX_WINDOW_STYLE, classAtom,
                                       self.appName, self.WINDOW_STYLE,
                                       self.cfg.windowLeft, self.cfg.windowTop,
                                       self.cfg.windowRight,
                                       self.cfg.windowBottom, 0, 0, 0, None)

        win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(255, 255, 255),
                                            255, win32con.LWA_COLORKEY)
        return hwnd