コード例 #1
0
ファイル: getlist.py プロジェクト: owner0220/winhandle
def main(argv):
	hwnd, childwnds = GetChildWindows('TeraCopy')
	listviewCtrl    = 0
 
	# TeraCopy의 윈도우 핸들
	print "%X %s" % (hwnd, win32gui.GetWindowText(hwnd))
 
	# TeraCopy 자식 윈도우의 핸들
	print "HWND     CtlrID\tClass\tWindow Text"
	print "==========================================="
 
	for child in childwnds:
		ctrl_id  = win32gui.GetDlgCtrlID(child)
		wnd_clas = win32gui.GetClassName(child)
		wnd_text = win32gui.GetWindowText(child)		
		print "%08X %6d\t%s\t%s" % (child, ctrl_id, wnd_clas, wnd_text)
 
		if wnd_clas == 'SysListView32':
			listviewCtrl = child
 
	itemlist = GetListViewItems(listviewCtrl)
 
	for itm in itemlist:
		print itm
 
	return 0
コード例 #2
0
 def getEditControl(self):
     # get application, if not found, set ctrl to None
     self.getAppWindow()
     if not self.app:
         self.__class__.ctrl = None
         return
     currentSel = None
     if self.ctrl:
         currentSel = mess.getSelection(self.ctrl)
     if currentSel and currentSel != (0, 0):
         return
     ctrls = mess.findControls(self.app, wantedClass=self.editcontrol)
     if len(ctrls):
         editHndle = ctrls[0]
         #print 'editHndle set to: %s'% editHndle
         if len(ctrls) > 1:
             for hndle in ctrls:
                 id = win32gui.GetDlgCtrlID(hndle)
                 if id == 0xd6:
                     editHndle = hndle
                     break
             else:
                 print('did not get valid id for aligen window')
                 return
     else:
         raise ValueError(
             "could not find the editHndle of the control: %s in application: %s"
             % (self.editcontrol, self.apppath))
     self.__class__.ctrl = editHndle
コード例 #3
0
    def getEditControl(self):
        # get application, if not found, set ctrl to None
        self.getAppWindow()
        if not self.app:
            self.__class__.ctrl = None
            return
        if tester == 'pythonwin':
            wTitle = win32gui.GetWindowText(self.app)
            filename = wTitle.split(
                '[')[-1][:-1]  # remove [ and ], leaving only the filenam

            def selectionFunction(hndle, gotTitle, gotClass):
                """special for selecting the Afx class with the same title as the complete window title bar
                being the filename in question
                
                special for pythonwin and only for the FIRST search action for child windows.
                After the correct Afx window has been identified, the Scintilla child window is the correct one.
                """
                if gotTitle == filename:
                    #print 'got afx with title: %s'% gotTitle
                    return True
        else:
            selectionFunction = None
        currentSel = None
        if self.ctrl:
            currentSel = mess.getSelection(self.ctrl)
        if currentSel and currentSel != (0, 0):
            return
        wC, wT = W["editcontrol"], W["edittext"]
        choiceControl = 0
        if type(wT) in [type(None), bytes, int]: wT = [wT]
        if type(wC) in [type(None), bytes, int]: wC = [wC]
        ctrl = self.app
        for wtext, wclass in zip(wT, wC):
            ctrls = mess.findControls(ctrl,
                                      wantedText=wtext,
                                      wantedClass=wclass,
                                      selectionFunction=selectionFunction)
            if selectionFunction:
                selectionFunction = None  # execute only for first findControls action pythonwin
                if tester == 'pythonwin':
                    choiceControl = -1

            if len(ctrls):
                ctrl = ctrls[choiceControl]
                #print 'editHndle set to: %s'% editHndle
                if len(ctrls) > 1:
                    for hndle in ctrls:
                        id = win32gui.GetDlgCtrlID(hndle)
                        if id == 0xd6:
                            ctrl = hndle
                            break
            else:
                pprint.pprint(mess.dumpWindow(self.app))
                raise ValueError(
                    "could not find the editHndle of the control: %s in application: %s"
                    % (self.editcontrol, self.apppath))

        self.__class__.ctrl = ctrl
        self.__class__.classname = win32gui.GetClassName(ctrl)
コード例 #4
0
def get_process_id_by_hwnd(hwnd: int):
    """Get process id by window handle (HWND).

    :param hwnd: Window handle (HWND)
    :return: HWND process ID
    """
    if window_exist_by_hwnd(hwnd):
        return win32gui.GetDlgCtrlID(hwnd)
    else:
        logger.debug('Could not find the HWND: {}'.format(hwnd))
        return False
コード例 #5
0
 def __matchWindow__(hwnd, title):
     if not isRaw and isRawWindow(hwnd):
         return False
     if type(title) == int:
         return win32gui.GetDlgCtrlID(hwnd) == title
     text = re.split('(\r|\n)+', getWindowText(hwnd))[0].strip()
     if text == title or re.match('^' + title + '$', text, re.S):
         return True
     clazz = getWindowClass(hwnd).strip()
     if clazz == title or re.match('^' + title + '$', clazz, re.S):
         return True
     return False
コード例 #6
0
ファイル: control_picker.py プロジェクト: owner0220/winhandle
    def pick_control(self, target_class_name, target_control_id=None):
        for child_window in self.child_windows:
            window_class = win32gui.GetClassName(child_window)
            control_id = win32gui.GetDlgCtrlID(child_window)

            if window_class != target_class_name:
                continue

            if target_control_id:
                if target_control_id == control_id:
                    return child_window
            else:
                return child_window
コード例 #7
0
def main(argv):
    hwnd, childwnds = GetChildWindows('Everything')
    print("%X %s" % (hwnd, win32gui.GetWindowText(hwnd)))

    print("HWND     CtlrID\tClass\tWindow Text")
    print("===========================================")

    for child in childwnds:
        ctrl_id = win32gui.GetDlgCtrlID(child)
        wnd_clas = win32gui.GetClassName(child)
        wnd_text = win32gui.GetWindowText(child)
        print("%08X %6d\t%s\t%s" % (child, ctrl_id, wnd_clas, wnd_text))

    return 0
コード例 #8
0
def main(argv):
	hwnd, childwnds = GetChildWindows('TeraCopy')
	print "%X %s" % (hwnd, win32gui.GetWindowText(hwnd))
 
	print "HWND     CtlrID\tClass\tWindow Text"
	print "==========================================="
 
	for child in childwnds:
		ctrl_id  = win32gui.GetDlgCtrlID(child)
		wnd_clas = win32gui.GetClassName(child)
		wnd_text = win32gui.GetWindowText(child)		
		print "%08X %6d\t%s\t%s" % (child, ctrl_id, wnd_clas, wnd_text)
 
	return 0
コード例 #9
0
    def update(self):

        win_title = get_active_window_title()
        handle = ctypes.windll.user32.FindWindowW(0,
                                                  get_title_string(win_title))

        self.wh.configure(text='Window Handle: ' + hex(handle))

        if win_title.lower() in ['パスワード', 'password', 'pass word']:
            self.handlenum = hex(handle)
            print("ok : " + self.handlenum)
            cid = win32gui.GetDlgCtrlID(handle)
            cls = win32gui.GetClassName(handle)
            length = win32gui.SendMessage(handle, win32con.WM_GETTEXTLENGTH, 0,
                                          0)
            buff = ctypes.create_unicode_buffer(length + 1)
            win32gui.SendMessage(handle, win32con.WM_GETTEXT, length + 1, buff)
            print(cid, cls, buff.value)

            hchild = win32gui.GetWindow(handle, win32con.GW_CHILD)
            length = win32gui.SendMessage(hchild, win32con.WM_GETTEXTLENGTH, 0,
                                          0)
            buff = ctypes.create_unicode_buffer(length + 1)
            win32gui.SendMessage(hchild, win32con.WM_GETTEXT, length + 1, buff)
            print(buff.value)

            # ctypes.windll.user32.SendMessageW(handle, win32con.WM_CHAR, 0x61, 0)

            handle2 = win32gui.GetWindow(handle, win32con.GW_HWNDNEXT)
            length = win32gui.SendMessage(handle2, win32con.WM_GETTEXTLENGTH,
                                          0, 0)
            buff = ctypes.create_unicode_buffer(length + 1)
            win32gui.SendMessage(handle2, win32con.WM_GETTEXT, length + 1,
                                 buff)
            print(buff.value)

            hWnd_child = get_hwnd_search_control(handle, 0, 0, "OK")
            print("ターゲットのハンドル", hex(hWnd_child))

            result = win32gui.PostMessage(handle, win32con.BM_CLICK, 0, 0)
            print(result)

            rect = win32gui.GetWindowRect(handle)
            print("ターゲットの位置:", rect)
            txt = win32gui.GetWindowText()
            print("ターゲットのテキスト:", txt)

        # 200ms周期で再表示
        self.master.after(200, self.update)
コード例 #10
0
def get_hwnd_search_control(hWnd, target_control_id, target_control_class,
                            target_control_title):
    try:
        htarget = 0

        if hWnd != 0:
            # チェック情報取得
            cid = win32gui.GetDlgCtrlID(hWnd)
            cls = win32gui.GetClassName(hWnd)

            # ターゲットテキスト取得
            length = win32gui.SendMessage(hWnd, win32con.WM_GETTEXTLENGTH, 0,
                                          0)
            buff = ctypes.create_unicode_buffer(length + 1)
            win32gui.SendMessage(hWnd, win32con.WM_GETTEXT, length + 1, buff)

            # チェック
            if win32gui.IsWindowVisible(hWnd):
                if target_control_id == 0 or target_control_id == cid:
                    if target_control_class == 0 or target_control_class == cls:
                        if target_control_title == "" or target_control_title == buff.value:
                            # ターゲット確認
                            htarget = hWnd

            # 渡されたハンドルがNGの場合、その子およびその階層をチェック
            if htarget == 0:
                hChild = win32gui.GetWindow(hWnd, win32con.GW_CHILD)
                while (hChild):
                    htmp = get_hwnd_search_control(hChild, target_control_id,
                                                   target_control_class,
                                                   target_control_title)
                    if htmp != 0:
                        htarget = htmp
                        break

                    hChild = win32gui.GetWindow(hChild, win32con.GW_HWNDNEXT)
        else:
            htarget = 0

        return htarget

    except Exception as err:
        # 取得失敗
        print("【ERROR】get_hwnd_search_control【ERROR】")
        print(err)
        return 0
コード例 #11
0
ファイル: Frame1.py プロジェクト: sundafa/KeymouseGo
 def onKeyboardEvent(event):
     global ttt
     if ttt == 0:
         ttt = event.Time - 1000
     pos = win32gui.GetCursorPos()
     rhwnd = win32gui.WindowFromPoint(pos)
     cname = win32gui.GetClassName(rhwnd)
     dcid = win32gui.GetDlgCtrlID(rhwnd)
     # print event.Message, event.MessageName
     delay = event.Time - ttt
     record.append(['EK', event.MessageName, (event.KeyID, event.Key), delay])
     # event.Key is useless, just for remark
     ttt = event.Time
     ts = self.tnumrd.GetLabel()
     ts = ts.replace(' actions recorded','')
     ts = str(eval(ts)+1)
     ts = ts + ' actions recorded'
     self.tnumrd.SetLabel(ts)
     return True
コード例 #12
0
    def sendISNtowindow(self):
        hld = win32gui.FindWindow(None, self.windowname)
        if hld > 0:
            btdlg = win32gui.FindWindowEx(hld, None, 'Button', None)  # child
            # print('Button: %x' %btdlg)

            eddlg1 = win32gui.FindWindowEx(hld, None, 'Edit', None)  # child
            # print('Edit: %x' %eddlg1)
            id = win32gui.GetDlgCtrlID(eddlg1)
            for i in range(6):
                if DATA.ISN[i]:
                    win32api.SendMessage(win32gui.GetDlgItem(hld, id),
                                         win32con.WM_SETTEXT, 0, DATA.ISN[i])
                id += 1
        win32gui.SetForegroundWindow(btdlg)
        time.sleep(0.3)
        win32api.SendMessage(btdlg, win32con.WM_LBUTTONDOWN, 0, 0)
        time.sleep(0.3)
        win32api.SendMessage(btdlg, win32con.WM_LBUTTONUP, 0, 0)
コード例 #13
0
ファイル: main.py プロジェクト: AlanIIE/auto-send-message
    def sendmsg(self):
        qq=win32gui.FindWindow(None,self.receiver)
        win32gui.GetClassName(qq)  # 获取窗口classname
        title = win32gui.GetWindowText(qq)  # 获取窗口标题
        win32gui.GetDlgCtrlID(qq)
        win32gui.SetForegroundWindow(qq)  # 激活窗口

		#粘贴内容
        win32api.keybd_event(17, 0, 0, 0)  # ctrl键位码是17
        win32api.keybd_event(86, 0, 0, 0)  # v键位码是86
        win32api.keybd_event(86, 0, win32con.KEYEVENTF_KEYUP, 0)  # 释放按键
        win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0)

		#发送内容
        win32api.keybd_event(18, 0, 0, 0)  # Alt
        win32api.keybd_event(83, 0, 0, 0)  # s
        win32api.keybd_event(83, 0, win32con.KEYEVENTF_KEYUP, 0)  # 释放按键
        win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0)

        print("sucessfuly send",self.msg)
コード例 #14
0
ファイル: Frame1.py プロジェクト: sundafa/KeymouseGo
 def onMouseEvent(event):
     global ttt
     if ttt == 0:
         ttt = event.Time
     if event.MessageName == 'mouse move':
         return True
     pos = win32gui.GetCursorPos()
     rhwnd = win32gui.WindowFromPoint(pos)
     pos = win32gui.ScreenToClient(rhwnd, pos)
     cname = win32gui.GetClassName(rhwnd)
     dcid = win32gui.GetDlgCtrlID(rhwnd)  
     # print event.Message, event.MessageName
     delay = event.Time - ttt
     record.append(['EM', event.MessageName, event.Position, delay])
     ttt = event.Time
     ts = self.tnumrd.GetLabel()
     ts = ts.replace(' actions recorded','')
     ts = str(eval(ts)+1)
     ts = ts + ' actions recorded'
     self.tnumrd.SetLabel(ts)
     return True
コード例 #15
0
def runWindowsCycle():
    for matchStr, resultIdx, subMatchStr, action in CONFIG:
        finder = WindowFinder(matchStr)
        finder.findWindow()

        if subMatchStr != None:
            results = []
            for curResult in finder.results:
                results += WindowFinder.resolve(subMatchStr,
                                                curResult[resultIdx])
            resultIdx = -1

        results = map(lambda x: x[resultIdx], finder.results)

        logResult(finder.resultStr)

        if action[0] == ET_WINDOW_MESSAGE:
            _, wmMsg, wParam, lParam = action
            for curResult in results:
                hwnd = curResult
                print '%s Sending window message %s to window %s, text=%s, class=%s' % (
                    time.ctime(), wmMsg, hwnd, win32gui.GetWindowText(hwnd),
                    win32gui.GetClassName(hwnd))
                win32gui.SendMessage(hwnd, wmMsg, wParam, lParam)
        elif action[0] == ET_POST_WINDOW_MESSAGE:
            _, wmMsg, wParam, lParam = action
            for curResult in results:
                hwnd = curResult
                print '%s Posting window message %s to window %s, text=%s, class=%s' % (
                    time.ctime(), wmMsg, hwnd, win32gui.GetWindowText(hwnd),
                    win32gui.GetClassName(hwnd))
                win32gui.PostMessage(hwnd, wmMsg, wParam, lParam)
        elif action[0] == ET_KILL_PROCESS:
            for curResult in results:
                processId = win32process.GetWindowThreadProcessId(curResult)[1]
                print '%s Kill process id %s' % (time.ctime(), processId)
                killProcess(processId)
        if action[0] == ET_PUSH_BUTTON:
            _, buttonMatchStr = action
            for curResult in results:
                buttonHwnds = WindowFinder.resolve(buttonMatchStr, curResult)
                buttonHwnds = map(lambda x: x[0], buttonHwnds)
                for buttonHwnd in buttonHwnds:
                    buttonDlgId = win32gui.GetDlgCtrlID(buttonHwnd)
                    print '%s Pushing button id=%s, text=%s, class=%s, parentWindow=%s' % (
                        time.ctime(), buttonHwnd,
                        win32gui.GetWindowText(buttonHwnd),
                        win32gui.GetClassName(buttonHwnd), buttonDlgId)
                    win32gui.SendMessage(curResult, win32con.WM_COMMAND,
                                         buttonDlgId, 0)
        if action[0] == ET_PRESS_KEY:
            _, theKey = action
            for curResult in results:
                hwnd = curResult
                print '%s Sending key %s to window %s, text=%s, class=%s' % (
                    time.ctime(), theKey, hwnd, win32gui.GetWindowText(hwnd),
                    win32gui.GetClassName(hwnd))
                win32gui.SendMessage(hwnd, win32con.WM_KEYDOWN,
                                     ord(theKey.upper()), 0x00310001)
                win32gui.SendMessage(hwnd, win32con.WM_CHAR, ord(theKey),
                                     0x00310001)
コード例 #16
0
 def __init__(self, hwnd):
     self.__hwnd = hwnd
     self.__count = 0
     self.__class_name = win32gui.GetClassName(self.__hwnd)
     self.__id = win32gui.GetDlgCtrlID(hwnd)
コード例 #17
0
 def __enumWindowHandler__(hwnd, wndList):
     text = re.split('[\r|\n]+', getWindowText(hwnd))[0].strip()
     clazz = getWindowClass(hwnd).strip()
     ctrlId = win32gui.GetDlgCtrlID(hwnd)
     wndList.append((hwnd, text, clazz, ctrlId))
コード例 #18
0
 def _windowEnumerationHandler(hwnd, resultList):
     resultList.append(
         (hwnd, win32gui.GetClassName(hwnd),
          win32gui.GetDlgCtrlID(hwnd)))