예제 #1
0
        def init(gui, ctrl, parent):
            ctrl.place(gui)
            ctrl.sel_set = set()

            ctrl.parent = parent.hwnd
            ctrl.height = 0
            InitCommonControls()
            ctrl.hwnd = create_control(
                ctrl.parent,
                WC_LISTVIEW,
                style=LVS_SHOWSELALWAYS | LVS_REPORT,
                tabstop=True,
                ex_style=WS_EX_CLIENTEDGE,
            )
            parent.notify[ctrl.hwnd] = partial(gui.List.notify, gui, ctrl)

            style = SendMessage(ctrl.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
            style |= LVS_EX_FULLROWSELECT
            SendMessage(ctrl.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, style)

            ctrl.column_refs = list()
            for (i, heading) in enumerate(ctrl.columns):
                (param, obj) = PackLVCOLUMN(
                    fmt=LVCFMT_LEFT,
                    text=heading,
                    cx=50,
                )
                ctrl.column_refs.append(obj)
                SendMessage(ctrl.hwnd, LVM_INSERTCOLUMNW, i, param)

            ctrl.items = list()
예제 #2
0
def QQSend(receiver, msg, send: 'bool' = True):
    clipboard = paste()
    copy(msg)
    windows = getAllWindows()
    result = False
    for each in range(len(windows)):
        if windows[each] == receiver:
            result = True
            break
        elif windows[each].find(receiver) != -1 and windows[each].find(
                '个会话') != -1:
            receiver = windows[each]
            result = True
            break
    if result:
        QQ = FindWindow('TXGuiFoundation', receiver)
        ShowWindow(QQ, 1)
        SendMessage(QQ, WM_PASTE, 0, 0)
        if send:
            SendMessage(QQ, WM_KEYDOWN, VK_RETURN)
            ShowWindow(QQ, 6)
        copy(clipboard)
        return 0
    else:
        copy(clipboard)
        return -1
예제 #3
0
 def mouse_move_distance(self, pos1, distance):
     """
     后台鼠标移动
         :param distance:
         :param self:
         :param pos1: (x,y) 起点坐标
     """
     l = MAKELONG(pos1[0], pos1[1])
     SendMessage(self.hwnd, win32con.WM_MOUSEMOVE, 0, l)
     time.sleep(0.01)
     l = MAKELONG(pos1[0] + distance[0], pos1[1] + distance[1])
     SendMessage(self.hwnd, win32con.WM_MOUSEMOVE, 0, l)
예제 #4
0
 def __call__(self, message = u""):
     hwnd = HandleLch()
     if hwnd:
         message = eg.ParseString(message)
         edit = GetDlgItem(hwnd, 1002)
         buttonId = 1003
         button = GetDlgItem(hwnd, buttonId)
         for line in message.strip().split("\n"):
             locBuf = create_string_buffer(line.encode(eg.systemEncoding))
             SendMessage(edit,WM_SETTEXT,0,addressof(locBuf))
             SendMessage(hwnd,WM_COMMAND,buttonId+65536*BN_CLICKED, button)
             sleep(0.5)
 def GetUserCount(self, hWnd=None):
     hwnd = hWnd or HandleLch()
     if hwnd:
         treeView = GetDlgItem(hwnd, 1000)
         if treeView:
             return SendMessage(treeView, TVM_GETCOUNT, 0, 0)
     return None
예제 #6
0
 def run(self):
     self.BuildWindow()
     self.started = True
     while self.started:
         PumpWaitingMessages()
         if self.do_update:
             SendMessage(self.progbar, PBM_SETPOS,
                         int(self.position % self.max_val), 0)
             percentage = int(round(100.0 * self.position / self.max_val))
             SendMessage(self.dialog, WM_SETTEXT, 0,
                         self.title + ' (%d%%)' % percentage)
             #            SendMessage(self.progbar, PBM_STEPIT, 0, 0)
             self.do_update = False
         sleep(0.1)
     PostQuitMessage(0)
     DestroyWindow(self.dialog)
예제 #7
0
def set_max_pop_delay_on_tooltip(tooltip):
    '''
    Sets maximum auto-pop delay (delay before hiding) on an instance of
    wx.ToolTip.
    NOTE: The tooltip's SetDelay method is used just to identify the correct
    tooltip.
    '''
    test_value = 12345
    # Set initial delay just to identify tooltip.
    tooltip.SetDelay(test_value)
    handles = []
    EnumWindows(_get_tooltip_handles, handles)
    for hwnd in handles:
        if SendMessage(hwnd, TTM_GETDELAYTIME, TTDT_INITIAL) == test_value:
            SendMessage(hwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, 32767)
    tooltip.SetDelay(500)  # Restore default value
예제 #8
0
    def __init__(self):
        self.hwnd = FindWindow(None, "扫雷")  # 获取扫雷游戏窗口的句柄
        assert self.hwnd, "请先打开扫雷,再运行该脚本程序"
        SendMessage(self.hwnd, WM_SYSCOMMAND, SC_RESTORE, 0)  # 还原最小化
        SetForegroundWindow(self.hwnd)  # 窗口置顶

        self.pixel_size = 16  # 每个格子的大小固定,为16个像素
        self.left, self.top, self.right, self.bottom = GetWindowRect(
            self.hwnd)  # 获取窗口坐标
        self.rank = None  # 扫雷游戏的等级,分为:高级、中级、初级,不包含自定义模式
        self.max_mines = 0  # 扫雷游戏的所有雷的数目

        # 去除窗口边框,只保留所有格子
        self.left = self.left + 15  # 左边框15个像素宽
        self.right = self.right - 11  # 右边框11个像素宽
        self.bottom = self.bottom - 11  # 下边框11个像素宽
        self.top = self.top + 101  # 尚边框101个像素宽

        # 获得游戏横向和纵向的格子数目
        self.height = int(
            (self.bottom - self.top) / self.pixel_size)  # 扫雷游戏的纵向格子数目
        assert self.height in [16, 16, 9]
        self.length = int(
            (self.right - self.left) / self.pixel_size)  # 扫雷游戏的横向格子数目
        assert self.length in [30, 16, 9]

        # 获取游戏难度级别
        self.get_rank()
        self.get_max_mines()
예제 #9
0
 def get(gui, ctrl, item):
     values = list()
     for col in range(len(ctrl.columns)):
         (lvitem, obj) = EmptyLVITEM(0, col, LVIF_TEXT)
         SendMessage(ctrl.hwnd, LVM_GETITEMTEXTW, item, lvitem)
         (_, _, _, _, text, _, _, _) = UnpackLVITEM(lvitem)
         values.append(text)
     return values
 def GetLineCount(self, hWnd=None, lines=None):
     hwnd = hWnd or HandleLch()
     if hwnd:
         edit = GetDlgItem(hwnd, 1001)
         if edit:
             count = SendMessage(edit, EM_GETLINECOUNT, 0, 0)
             lns = []
             if lines is not None and count > lines:
                 rows = count - lines
                 locBuf = create_string_buffer(512)
                 locBuf.value = "\x00\x01\x00\x00" + 508 * "\x00"
                 for row in range(rows):
                     tchars = SendMessage(edit, EM_GETLINE,
                                          count - (rows + 1 - row),
                                          addressof(locBuf))
                     lns.append(locBuf.value[:tchars].replace("\x0D", ""))
                 self.lastMessage = "".join(lns).decode(eg.systemEncoding)
             return count, self.lastMessage
     return None, None
예제 #11
0
 def mouse_drag(self, pos1, pos2):
     """
     后台鼠标拖拽
         :param self:
         :param pos1: (x,y) 起点坐标
         :param pos2: (x,y) 终点坐标
     """
     import numpy
     move_x = numpy.linspace(pos1[0], pos2[0], num=20, endpoint=True)[0:]
     move_y = numpy.linspace(pos1[1], pos2[1], num=20, endpoint=True)[0:]
     SendMessage(self.hwnd, win32con.WM_LBUTTONDOWN, 0,
                 MAKELONG(pos1[0], pos1[1]))
     for i in range(20):
         x = int(round(move_x[i]))
         y = int(round(move_y[i]))
         SendMessage(self.hwnd, win32con.WM_MOUSEMOVE, 0, MAKELONG(x, y))
         time.sleep(0.01)
     SendMessage(self.hwnd, win32con.WM_LBUTTONUP, 0,
                 MAKELONG(pos2[0], pos2[1]))
예제 #12
0
 def get_message_text(self):
     """ Получаем win32 MT Alert window/panel/message Текст """
     title = self.get_windows_title()
     window = FindWindow(WINDOW_ID, title)
     panel = FindWindowEx(window, 0, "Edit", None)
     bufferlength = pack('i', 255)
     linetext = bufferlength + "".ljust(253)
     linelength = SendMessage(panel, EM_GETLINE, 0, linetext)
     text = ''.join(linetext[:linelength])
     return text
예제 #13
0
 def setenv(self, name, value):
     import win32con
     from win32gui import SendMessage
     r = six.moves.winreg
     assert self.scope == 'user', 'setenv supported only for user env'
     key = r.OpenKey(self.root, self.subkey, 0, r.KEY_ALL_ACCESS)
     r.SetValueEx(key, name, 0, r.REG_EXPAND_SZ, value)
     # LOG.info('SetValueEx %s == %s', name, value)
     r.CloseKey(key)
     SendMessage(
         win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, self.subkey)
예제 #14
0
def tar():
    '''
    AutoCAD 2010解压安装
    :return:
    '''
    lable = 'AutoCAD 2010'
    while True:
        # 根据类名及标题名查询句柄
        w = FindWindow(None, lable)
        if w > 0:
            break
    if w > 0:
        # 将软件窗口置于最前
        SetForegroundWindow(w)
        # 更改解压路径
        e = FindWindowEx(w, None, 'ComboBox', None)
        SendMessage(e, win32con.WM_SETTEXT, None, r'D:\Autodesk\AutoCAD_2010_Simplified_Chinese_MLD_WIN_64bit')
        # 开始解压
        b = FindWindowEx(w, None, 'Button', 'Install')
        SendMessage(b, win32con.BM_CLICK, None, None)
        print('%x,%x,%x' % (w, e, b))
예제 #15
0
    def BuildWindow(self):
        width = 400
        height = 100
        self.dialog = CreateWindowEx(
            win32con.WS_EX_TOPMOST,
            WC_DIALOG,
            self.title + ' (0%)',
            win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW,
            int(round(
                GetSystemMetrics(win32con.SM_CXSCREEN) * .5 - width * .5)),
            int(round(
                GetSystemMetrics(win32con.SM_CYSCREEN) * .5 - height * .5)),
            width,
            height,
            0,
            0,
            self.hinst,
            None)
        self.progbar = CreateWindow(
            #                             win32con.WS_EX_DLGMODALFRAME,
            'msctls_progress32',
            '',
            win32con.WS_VISIBLE | win32con.WS_CHILD,
            10,
            10,
            width - 30,
            20,
            self.dialog,
            0,
            0,
            None)
        if self.can_abort:
            self.button = CreateWindow(
                #                             win32con.WS_EX_DLGMODALFRAME,
                'BUTTON',
                'Cancel',
                win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.BS_PUSHBUTTON,  # @IgnorePep8
                int(width / 2.75),
                40,
                100,
                20,
                self.dialog,
                0,
                0,
                None)
        self.oldWndProc = SetWindowLong(
            self.dialog,
            win32con.GWL_WNDPROC,
            self.DlgProc)
        SendMessage(self.progbar, PBM_SETRANGE, 0, MAKELPARAM(0, self.max_val))
#        win32gui.SendMessage(self.progbar, PBM_SETSTEP, 0, 10)
#        win32gui.SendMessage(self.progbar, PBM_SETMARQUEE, 0, 0)
        ShowWindow(self.progbar, win32con.SW_SHOW)
 def __call__(self, mode=0):
     hwnd = HandleLch()
     if hwnd:
         onLineId = 1009
         busyId = 1010
         disconnectId = 1011
         buttonId = (onLineId, busyId, disconnectId)
         for i in range(len(buttonId)):
             button = GetDlgItem(hwnd, buttonId[i])
             state = SendMessage(button, BM_GETCHECK, 0, 0)
             if state & BST_CHECKED:
                 break
         return i if mode else self.text.status + " " + self.text.states[i]
예제 #17
0
 def SendCommand(self, cmd, room, value, wait=True):
     if wait:
         event = CreateEvent(None, 0, 0, None)
         self.event = (COMMANDS[cmd], event)
     hwnd = GetHwnd()
     if hwnd:
         SendMessage(hwnd, WM_COMMAND, COMMANDS[cmd] + room, value)
         if wait:
             eg.actionThread.WaitOnEvent(event)
             res = self.result
             self.result = None
             return res
     else:
         eg.PrintError(self.text.err1)
예제 #18
0
        def add(gui, ctrl, columns, selected=False):
            item = len(ctrl.items)
            columns = iter(columns)
            (param, obj) = PackLVITEM(
                item=item,
                text=next(columns),
                stateMask=LVIS_SELECTED,
                state=LVIS_SELECTED * selected,
            )
            ctrl.items.append([obj])
            cb = ctrl.selected
            ctrl.selected = None
            item = SendMessage(ctrl.hwnd, LVM_INSERTITEMW, 0, param)
            ctrl.selected = cb

            for (col, text) in enumerate(columns, 1):
                (param, obj) = PackLVITEM(text=text, subItem=col)
                ctrl.items[-1].append(obj)
                SendMessage(ctrl.hwnd, LVM_SETITEMTEXTW, item, param)

            if selected:
                ctrl.sel_set.add(item)
                if ctrl.selected:
                    ctrl.selected()
예제 #19
0
    def mouse_move(self, pos1, pos2):
        """
        后台鼠标移动
            :param self:
            :param pos1: (x,y) 起点坐标
            :param pos2: (x,y) 终点坐标
        """
        # PostMessage(self.hwnd, win32con.WM_CAPTURECHANGED, win32con.MK_LBUTTON,
        #             MAKELONG(pos1[0], pos1[1]))
        step_width_list = []
        step_height_list = []
        step_list = []
        width = pos2[0] - pos1[0]
        height = pos2[1] - pos1[1]
        step_width = 6
        step_height = 6

        if width < 0:
            step_width = -step_width
        if height < 0:
            step_height = -step_height

        for i in range(pos1[0], pos2[0], step_width):
            step_width_list.append(i)
        for i in range(pos1[1], pos2[1], step_height):
            step_height_list.append(i)

        if len(step_width_list) < len(step_height_list):
            for i in range(len(step_height_list)):
                if i < len(step_width_list):
                    step_list.append([step_width_list[i], step_height_list[i]])
                else:
                    step_list.append([pos2[0], step_height_list[i]])
        else:
            for i in range(len(step_width_list)):
                if i < len(step_height_list):
                    step_list.append([step_width_list[i], step_height_list[i]])
                else:
                    step_list.append([step_width_list[i], pos2[1]])
        for pos in step_list:
            l = MAKELONG(pos[0], pos[1])
            SendMessage(self.hwnd, win32con.WM_MOUSEMOVE, 0, l)
            time.sleep(0.01)
예제 #20
0
    def showFixCross(self, time):

        if (self.firstFocus == False):
            self.fixCrossWin.focus_force()
            SendMessage(self.hwnd, WM_SETFOCUS, None, None)
            #SetFocus(self.hwnd)

        # focus on the fixation cross window
        self.fixCrossWin.focus_force()

        if (self.firstFocus == True):
            self.hwnd = GetFocus()
            #print "hwnd: " + str(self.hwnd)
            self.firstFocus = False

        #self.fixCrossWin.focus_set()s
        # log the presentation of the cross
        self.logger.write("FIXCROSS")

        # focus on the main window again and run it
        self.after(time, self.hideFixCrossWin)
예제 #21
0
def create_control(
    parent,
    wndclass,
    text=None,
    tabstop=False,
    style=0,
    id=None,
    x=0,
    y=0,
    width=0,
    height=0,
    ex_style=0,
):
    style |= tabstop * WS_TABSTOP
    hwnd = CreateWindowEx(WS_EX_NOPARENTNOTIFY | ex_style, wndclass, text,
                          WS_CHILD | WS_VISIBLE | style, x, y, width, height,
                          parent, id, None, None)
    redraw = 0
    SendMessage(hwnd, WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT),
                MAKELONG(redraw, 0))
    return hwnd
예제 #22
0
def monoff():
    if platform == 'linux':
        from os import system
        system('xset dpms force off')
    elif platform == 'win32' or platform == 'cygwin':
        from win32gui import SendMessage
        from win32con import HWND_BROADCAST, WM_SYSCOMMAND
        from os import getpid, system
        from threading import Timer
        SC_MONITORPOWER = 0xF170
        SC_MONITORPOWER_OFF = 2
        def end_thread():
            pid = getpid()
            system('taskkill /pid %s /f' % pid)
        monoff_thread = Timer(1,end_thread)
        monoff_thread.start()
        SendMessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_MONITORPOWER,SC_MONITORPOWER_OFF)
        monoff_thread.cancel()
    elif platform == 'darwin':
        from os import system
        system('pmset displaysleepnow')
    else:
        raise Exception('Monoff does not support this platform: %s' % repr(platform))
예제 #23
0
def set_env(name, value):
    key = OpenKey(HKEY_CURRENT_USER, 'Environment', 0, KEY_ALL_ACCESS)
    SetValueEx(key, name, 0, REG_EXPAND_SZ, value)
    CloseKey(key)
    SendMessage(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0,
                'Environment')
 def __call__(self, state=0):
     hwnd = HandleLch()
     if hwnd:
         onLineId = 1009
         busyId = 1010
         disconnectId = 1011
         buttonId = (onLineId, busyId, disconnectId)
         for current in range(len(buttonId)):
             button = GetDlgItem(hwnd, buttonId[current])
             st = SendMessage(button, BM_GETCHECK, 0, 0)
             if st & BST_CHECKED:
                 break
         if current == 2 and state == 1:
             SendMessage(hwnd, WM_COMMAND, buttonId[0] + 65536 * BN_CLICKED,
                         GetDlgItem(hwnd, buttonId[0]))
             button = GetDlgItem(hwnd, buttonId[current])
             SendMessage(button, BM_SETSTATE, 0, 0)
             SendMessage(button, BM_SETCHECK, False, 0)
             button = GetDlgItem(hwnd, buttonId[0])
             SendMessage(button, BM_SETSTATE, 1, 0)
             SendMessage(button, BM_SETCHECK, True, 0)
             current = 0
             sleep(2)
         SendMessage(hwnd, WM_COMMAND, buttonId[state] + 65536 * BN_CLICKED,
                     GetDlgItem(hwnd, buttonId[state]))
         button = GetDlgItem(hwnd, buttonId[current])
         SendMessage(button, BM_SETSTATE, 0, 0)
         SendMessage(button, BM_SETCHECK, False, 0)
         button = GetDlgItem(hwnd, buttonId[state])
         SendMessage(button, BM_SETSTATE, 1, 0)
         SendMessage(button, BM_SETCHECK, True, 0)
예제 #25
0
 def mouse_active(self):
     SendMessage(self.hwnd, win32con.WM_SETFOCUS)  # 起作用
     SendMessage(self.hwnd, win32con.WM_NCMBUTTONDOWN)  # 起作用
 def __call__(self):
     hwnd = HandleLch()
     if hwnd:
         buff = create_string_buffer("")
         SendMessage(GetDlgItem(hwnd, 1001), WM_SETTEXT, 0, addressof(buff))
         self.plugin.observThread.ResetLinesCount()
예제 #27
0
 def setenvironment(self, name, value, user=True):
     root, subkey = getenvironmentkeys(user)
     key = OpenKey(root, subkey, 0, KEY_ALL_ACCESS)
     SetValueEx(key, name, 0, REG_EXPAND_SZ, value)
     CloseKey(key)
     SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, subkey)
예제 #28
0
 def clear(gui, ctrl):
     SendMessage(ctrl.hwnd, LVM_DELETEALLITEMS)
     del ctrl.items[:]
     ctrl.sel_set.clear()
예제 #29
0
# -*- enoding:utf-8 -*-

# 生成 buffer 对象
import win32con
from win32gui import PyMakeBuffer, SendMessage, PyGetBufferAddressAndLen, PyGetString

length = 10000

# hWnd=68214
hWnd = 72710000

buf = PyMakeBuffer(length)
length2 = SendMessage(hWnd, win32con.WM_GETTEXT, length, buf) + 1
print(length2)
buf = PyMakeBuffer(length2)
print('get: ', SendMessage(hWnd, win32con.WM_GETTEXT, length2, buf))

address, length = PyGetBufferAddressAndLen(buf)
text = PyGetString(address, length)

print('text: ', text)
예제 #30
0
 def remove(gui, ctrl, item):
     ctrl.items.pop(item)
     SendMessage(ctrl.hwnd, LVM_DELETEITEM, item)