Beispiel #1
0
def get_main_handle(proc_name):
    from win32gui import GetWindow, IsWindowVisible
    from win32con import GW_OWNER
    from psutil import process_iter

    pids = []
    proc_name = proc_name.lower()
    if ".exe" not in proc_name:
        proc_name = ".".join([proc_name, "exe"])
    for proc in process_iter():
        if proc.name().lower() == proc_name:
            pids.append(proc.pid)
            # don't break, multiple same proc_names are possible e.g: chrome

    handle_list = []
    for pid in pids:
        handle_list.extend(get_hwnds_for_pid(pid))

    main_handle = -1
    for h in handle_list:  # pyhandles
        if GetWindow(h, GW_OWNER) == 0 and IsWindowVisible(h):
            main_handle = h
            break

    return main_handle
def get_target_position_hwnd(target_mouse_position_x, target_mouse_position_y):
    """
    get hwnd value what the target position's program
    :param target_mouse_position_x: target mouse position x
    :param target_mouse_position_y: target mouse position y
    :return:
    """
    data = []

    def callback(hwnd, param):
        (left, top, right, bottom) = GetWindowRect(hwnd)
        if target_mouse_position_x > right or target_mouse_position_x < left:
            return
        if target_mouse_position_y > bottom or target_mouse_position_y < top:
            return
        data.append(hwnd)

    EnumWindows(callback, None)
    for hwnd in data:
        window_text = GetWindowText(hwnd)
        if not window_text or window_text.strip() == '':
            continue
        if not IsWindowVisible(hwnd):
            continue
        return hwnd
Beispiel #3
0
 def callback(hwnd,
              hwnds):  # in order to minimize it to the SystemTray later
     if IsWindowVisible(hwnd) and IsWindowEnabled(hwnd):
         _, found_pid = GetWindowThreadProcessId(hwnd)
         if found_pid == pid:
             hwnds.append(hwnd)
     return True
Beispiel #4
0
 def callback(hwnd, mouse):
     if IsWindow(hwnd) and IsWindowEnabled(
             hwnd) and IsWindowVisible(hwnd):
         title = GetWindowText(hwnd)
         if const.NAME_WINDOW_TITLE in title:
             rect = list(GetWindowRect(hwnd))
             rect.append(hwnd)
             hwndList.append(rect)
Beispiel #5
0
 def foo(self, hwnd, mouse):
     # 去掉下面这句就所有都输出了,但是我不需要那么多
     if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
         print(hwnd)
         if GetWindowText(hwnd) == 'IB Gateway':
             SetForegroundWindow(hwnd)
             print('ok')
             return
Beispiel #6
0
    def foo(hwnd, mouse):
        #去掉下面这句就所有都输出了,但是我不需要那么多
        if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
            if (subset):
                if (title_name in GetWindowText(hwnd)):
                    titles.add(hwnd)

            if (GetWindowText(hwnd) == title_name): titles.add(hwnd)
Beispiel #7
0
 def get_pid(hwnd, ignored):
     if not found and IsWindow(hwnd) and IsWindowEnabled(
             hwnd) and IsWindowVisible(hwnd):
         _hwnd, _pid = GetWindowThreadProcessId(hwnd)
         if check_is_mc(hwnd, _pid):
             if debug:
                 print(
                     "[DEBUG]find_mc->get_pid: _hwnd = %s | hwnd = %s | _pid = %s"
                     % (_hwnd, hwnd, _pid))
Beispiel #8
0
 def get_pid(hwnd, ignored):
     if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
         pid = GetWindowThreadProcessId(hwnd)[1]
         if "dwm" in psutil.Process(pid).name() and "minecraft".upper(
         ) in str(GetWindowText(hwnd)).upper():
             if debug:
                 print("[DEBUG]find_mc_dwm(): pid = %s | hwnd = %s" %
                       (pid, hwnd))
             global dmw
             dmw = hwnd
Beispiel #9
0
def on_enumerate(_window, params):
    global windows_in_fs_1
    global windows_in_fs_2

    if is_in_full_screen_1(_window) and not blacklisted(_window):
        windows_in_fs_1 = windows_in_fs_1 + 1
        print("FS 1: {0} {1} Visible: {2}", GetWindowText(_window),
              GetWindowThreadProcessId(_window)[1], IsWindowVisible(_window))

    if is_in_full_screen_2(_window) and not blacklisted(_window):
        windows_in_fs_2 = windows_in_fs_2 + 1
Beispiel #10
0
def winEnumHandler(hwnd, _):
    global focused_window
    global spotify_install_path
    global block
    if IsWindowVisible(hwnd):
        wintext = GetWindowText(hwnd)
        _, pid = win32process.GetWindowThreadProcessId(hwnd)

        if wintext != None and wintext != "" and wintext != " ":
            if not block:
                #  and (wintext == "Spotify Free" or wintext == "Advertisement"):
                # if wintext == "Spotify Free" or wintext == "Advertisement":
                adcheck()
            song_name(wintext, pid)
Beispiel #11
0
def enum_windows_callback(hwnd, mouse):
    pid = c_ulong()
    # if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
    try:
        if IsWindow(hwnd) and IsWindowVisible(hwnd):
            # if IsWindow(hwnd):
            user32.GetWindowThreadProcessId(hwnd, byref(pid))
            caption = GetWindowText(hwnd)
            if len(caption) == 0:
                return
            global handles, pids, captions
            handles.append(hwnd)
            pids.append(pid.value)
            captions.append(caption)
    except NameError:
        pass
Beispiel #12
0
def main():
    print("Inside main")
    for hwnd, text, cls in enum_windows():
        if IsWindowEnabled(hwnd) and IsWindowVisible(hwnd) and text:
            if not inside_desktop(hwnd):
                left, top, right, bottom = GetWindowPlacement(hwnd)[4]
                width = right - left
                height = bottom - top
                (x, y) = GetWindowRect(GetDesktopWindow())[:2]
                try:
                    MoveWindow(hwnd, x, y, width, height, 1)
                    print ("moved '%s'" % text)
                except:
                    # Ignore windows we can't move.
                    print("Can't move")
                    pass
Beispiel #13
0
def try1():
    window_list = get_ordered_window()
    for hwnd in window_list:
        (left, top, right, bottom) = GetWindowRect(hwnd)
        if left <= 0 and top <= 0 and right <= 0 and bottom <= 0:
            continue
        window_text = GetWindowText(hwnd)
        if not window_text or window_text.strip() == '':
            continue
        if target_value_x > right or target_value_x < left:
            continue
        if target_value_y > bottom or target_value_y < top:
            continue
        if not IsWindowVisible(hwnd):
            continue
        print(window_text)
        print(left, top, right, bottom)
        print("-------------------------------------")
Beispiel #14
0
 def _callBack_popWin(self, hwin, args):
     """ this callback function is called with handle of each top-level
     window. Window handles are used to check the of window in question is
     visible and if so it's title strings checked to see if it is a standard
     application (e.g. not the start button or natlink voice command itself).
     Populate dictionary of window title keys to window handle values. """
     #print '.' #self.nullTitles
     #nullTitles = self.nullTitles.append(self.skipTitle)
     #print nullTitles
     if IsWindowVisible(hwin):
         winText = GetWindowText(hwin).strip()
         nt = self.nullTitles + [
             self.skipTitle,
         ]
         if winText and winText not in nt:  # and\
             # enable duplicates #winText not in args.values():
             if winText.count('WinSCP') and winText != 'WinSCP Login':
                 if winText in args.values():
                     return
             args.update({hwin: winText})
Beispiel #15
0
def foo(hwnd, mouse):
    titles = set()
    # 判断是不是窗口、是不是可用的、是不是可见的
    if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
        # 把得到的结果赋值给a
        a = win32gui.GetWindowText(hwnd)
        # 打出
        print(win32gui.GetWindowText(hwnd))
        # 不为空时
        if a != '':
            # 当'Program Manager'不在a内时:
            if 'Program Manager' not in a:
                if '开始' not in a:
                    if '管理员' not in a:
                        # 关闭窗口
                        win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
                        # 最小化窗口
                        # win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
        # 把所有的窗口添加到titles集内
        titles.add(GetWindowText(hwnd))
Beispiel #16
0
def get_target_position_window():
    data = []

    def callback(hwnd, param):
        (left, top, right, bottom) = GetWindowRect(hwnd)
        if target_value_x > right or target_value_x < left:
            return
        if target_value_y > bottom or target_value_y < top:
            return
        data.append(hwnd)

    EnumWindows(callback, None)
    target_hwnd = None
    for hwnd in data:
        window_text = GetWindowText(hwnd)
        if not window_text or window_text.strip() == '':
            continue
        if not IsWindowVisible(hwnd):
            continue
        target_hwnd = hwnd
        break
    window_text = GetWindowText(target_hwnd)
    print(window_text)
Beispiel #17
0
 def callback(hwnd, hwnds):
     if IsWindowVisible(hwnd) and IsWindowEnabled(hwnd):
         _, found_pid = GetWindowThreadProcessId(hwnd)
         if found_pid == pid:
             hwnds.append(hwnd)
         return True
 def foo(hwnd,mouse):
  #去掉下面这句就所有都输出了,但是我不需要那么多
  if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
      if(GetClassName(hwnd) == class_name):     titles.add(hwnd)
Beispiel #19
0
def foo(hwnd, mouse):
    #去掉下面这句就所有都输出了,但是我不需要那么多
    if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
        titles.add(GetWindowText(hwnd))
 def EnumFunc(hWndChild, lParam):
     if IsWindowVisible(hWndChild):
         data[0] = True
         return False
     return True
 def _f(hwnd, mouse):
     if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd) and not IsIconic(hwnd):
         titles.add(GetWindowText(hwnd))
Beispiel #22
0
def get_window_pos(hwnd, hwnd_list):
    if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
        #
        hwnd_list.append(hwnd)
Beispiel #23
0
def winEnumHandler(hwnd, windows):
    if IsWindowVisible(hwnd):
        curWindow = getAppName(hwnd)
        if curWindow is not '' and curWindow not in windows:
            windows.append(curWindow)
Beispiel #24
0
 def menu(handle, m):
     if IsWindow(handle) and IsWindowEnabled(handle) and IsWindowVisible(
             handle):
         titles.add(GetWindowText(handle))
 def callback(hwnd, hwnds):
     if IsWindowVisible(hwnd):
         _, result = GetWindowThreadProcessId(hwnd)
         if result == pid:
             hwnds.append(hwnd)
     return True
Beispiel #26
0
def _callback(hwnd, hwnds):
    if IsWindowVisible(hwnd) and IsWindowEnabled(hwnd):
        _, found_pid = GetWindowThreadProcessId(hwnd)
        hwnds.add(found_pid)
    return True
Beispiel #27
0
 def client(hwnd, lParam):
     global tibia
     if IsWindowVisible(hwnd):
         if 'Tibia -' in GetWindowText(hwnd):
             tibia = GetWindowText(hwnd)
             print(GetWindowText(hwnd))