当前位置: 首页>>代码示例>>Python>>正文


Python win32process.GetWindowThreadProcessId方法代码示例

本文整理汇总了Python中win32process.GetWindowThreadProcessId方法的典型用法代码示例。如果您正苦于以下问题:Python win32process.GetWindowThreadProcessId方法的具体用法?Python win32process.GetWindowThreadProcessId怎么用?Python win32process.GetWindowThreadProcessId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32process的用法示例。


在下文中一共展示了win32process.GetWindowThreadProcessId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GetHwnds

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def GetHwnds(pid = None, processName = None):
    if pid:
        pass
    elif processName:
        pids = GetPids(processName = processName)
        if pids:
            pid = pids[0]
        else:
            return False
    else:
        return False

    def callback(hwnd, hwnds):
        if IsWindowVisible(hwnd):
            _, result = GetWindowThreadProcessId(hwnd)
            if result == pid:
                hwnds.append(hwnd)
        return True

    from win32gui import EnumWindows, IsWindowVisible
    from win32process import GetWindowThreadProcessId
    hwnds = []
    EnumWindows(callback, hwnds)
    return hwnds 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:26,代码来源:Utils.py

示例2: __close__

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def __close__(self, hwnd, dummy):
        """
        EnumWindows callback - sends WM_CLOSE to any window
        owned by this process.
        """
        TId, PId = win32process.GetWindowThreadProcessId(hwnd)
        if PId == self.PId:
            win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:winprocess.py

示例3: get_current_layout

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def get_current_layout(cls):
        # Get the current window's keyboard layout.
        thread_id = win32process.GetWindowThreadProcessId(
            win32gui.GetForegroundWindow()
        )[0]
        return win32api.GetKeyboardLayout(thread_id) 
开发者ID:dictation-toolbox,项目名称:dragonfly,代码行数:8,代码来源:_win32.py

示例4: get_hwnds_for_pid

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def get_hwnds_for_pid(pid):
    def callback(hwnd, hwnds):
        # if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
        _, found_pid = win32process.GetWindowThreadProcessId(hwnd)
        # print hwnd
        if found_pid == pid:
            hwnds.append(hwnd)
        return True
    hwnds = []
    win32gui.EnumWindows(callback, hwnds)
    return hwnds 
开发者ID:turingsec,项目名称:marsnake,代码行数:13,代码来源:winpty.py

示例5: get_app_path

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def get_app_path(hwnd) -> Optional[str]:
    """Get application path given hwnd."""
    path = None
    _, pid = win32process.GetWindowThreadProcessId(hwnd)
    for p in c.query('SELECT ExecutablePath FROM Win32_Process WHERE ProcessId = %s' % str(pid)):
        path = p.ExecutablePath
        break
    return path 
开发者ID:ActivityWatch,项目名称:aw-watcher-window,代码行数:10,代码来源:windows.py

示例6: get_app_name

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def get_app_name(hwnd) -> Optional[str]:
    """Get application filename given hwnd."""
    name = None
    _, pid = win32process.GetWindowThreadProcessId(hwnd)
    for p in c.query('SELECT Name FROM Win32_Process WHERE ProcessId = %s' % str(pid)):
        name = p.Name
        break
    return name 
开发者ID:ActivityWatch,项目名称:aw-watcher-window,代码行数:10,代码来源:windows.py

示例7: activeWindowName

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def activeWindowName():
	hwnd = win32gui.GetForegroundWindow()
	tid, current_pid = win32process.GetWindowThreadProcessId(hwnd)
	return psutil.Process(current_pid).name() 
开发者ID:xulusjb,项目名称:PUBG,代码行数:6,代码来源:main.py

示例8: enum_window_callback

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def enum_window_callback(hwnd, pid):
    tid, current_pid = win32process.GetWindowThreadProcessId(hwnd)
    if pid == current_pid and win32gui.IsWindowVisible(hwnd):
        win32gui.SetForegroundWindow(hwnd)
        l("window activated") 
开发者ID:xulusjb,项目名称:PUBG,代码行数:7,代码来源:main.py

示例9: enumCallback

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def enumCallback(hwnd, windowName):
            """
            Will get called by win32gui.EnumWindows, once for each
            top level application window.
            """

            try:

                # Get window title
                title = win32gui.GetWindowText(hwnd)

                # Is this our guy?
                if title.find(windowName) == -1:
                    return

                (threadId, processId) = win32process.GetWindowThreadProcessId(hwnd)

                # Send WM_CLOSE message
                try:
                    win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
                    win32gui.PostQuitMessage(hwnd)
                except:
                    pass

                # Give it upto 5 sec
                for i in range(100):
                    if win32process.GetExitCodeProcess(processId) != win32con.STILL_ACTIVE:
                        # Process exited already
                        return

                    time.sleep(0.25)

                try:
                    # Kill application
                    win32process.TerminateProcess(processId, 0)
                except:
                    pass
            except:
                pass 
开发者ID:MozillaSecurity,项目名称:peach,代码行数:41,代码来源:tcp.py

示例10: __init__

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def __init__(self, window_name=None, exe_file=None, exclude_border=True):
        hwnd = 0

        # first check window_name
        if window_name is not None:
            hwnd = win32gui.FindWindow(None, window_name)
            if hwnd == 0:
                def callback(h, extra):
                    if window_name in win32gui.GetWindowText(h):
                        extra.append(h)
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> not found!" % window_name)

        # check exe_file by checking all processes current running.
        elif exe_file is not None:
            pid = find_process_id(exe_file)
            if pid is not None:
                def callback(h, extra):
                    if win32gui.IsWindowVisible(h) and win32gui.IsWindowEnabled(h):
                        _, p = win32process.GetWindowThreadProcessId(h)
                        if p == pid:
                            extra.append(h)
                        return True
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                #TODO: get main window from all windows.
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> is not running!" % exe_file)

        # if window_name & exe_file both are None, use the screen.
        if hwnd == 0:
            hwnd = win32gui.GetDesktopWindow()

        self.hwnd = hwnd
        self.exclude_border = exclude_border 
开发者ID:NetEaseGame,项目名称:ATX,代码行数:43,代码来源:windows.py

示例11: __init__

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def __init__(self, parent=True, console=False):
        """Get the handle of the currently focused window."""
        self.hwnd = get_window_handle(parent, console)
        self.pid = win32process.GetWindowThreadProcessId(self.hwnd)[1] 
开发者ID:Peter92,项目名称:MouseTracks,代码行数:6,代码来源:main.py

示例12: main

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def main():
    # Find Super Hexagon process id by searching window names
    window_handle = win32ui.FindWindow(None, u"Super Hexagon").GetSafeHwnd()
    pid = win32process.GetWindowThreadProcessId(window_handle)[1]

    memory = Memory(pid)
    hexagon = SuperHexagon(memory)
    logic = Logic(hexagon)
    logic.start()
    memory.close_handle() 
开发者ID:Darkman,项目名称:Super-Hexagon-Bot,代码行数:12,代码来源:super_hexagon_bot.py

示例13: get_window_list

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def get_window_list():
    titles = []
    t = []
    pidList = [(p.pid, p.name()) for p in psutil.process_iter()]

    def enumWindowsProc(hwnd, lParam):
        """ append window titles which match a pid """
        if (lParam is None) or ((lParam is not None) and (win32process.GetWindowThreadProcessId(hwnd)[1] == lParam)):
            text = win32gui.GetWindowText(hwnd)
            if text:
                wStyle = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE)
                if wStyle & win32con.WS_VISIBLE:
                    t.append("%s" % (text))
                    return

    def enumProcWnds(pid=None):
        win32gui.EnumWindows(enumWindowsProc, pid)

    for pid, pName in pidList:
        enumProcWnds(pid)
        if t:
            for title in t:
                titles.append("('{0}', '{1}')".format(pName, title))
            t = []
    titles = sorted(titles, key=lambda x: x[0].lower())
    return titles 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:28,代码来源:Demo_Save_Windows_As_Images.py

示例14: GetProcessNameFromHwnd

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def GetProcessNameFromHwnd(self, hwnd):
		'''Acquire the process name from the window handle for use in the log filename.
		'''
		threadpid, procpid = win32process.GetWindowThreadProcessId(hwnd)
		
		# PROCESS_QUERY_INFORMATION (0x0400) or PROCESS_VM_READ (0x0010) or PROCESS_ALL_ACCESS (0x1F0FFF)
		
		mypyproc = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, False, procpid)
		procname = win32process.GetModuleFileNameEx(mypyproc, 0)
		return procname 
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:12,代码来源:logwriter.py

示例15: BringHwndToFront

# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import GetWindowThreadProcessId [as 别名]
def BringHwndToFront(hWnd, invalidate=True):
    if hWnd is None:
        return
    hWnd = GetAncestor(hWnd, GA_ROOT)
    if not IsWindow(hWnd):
        return

    # If the window is in a minimized state, restore now
    if IsIconic(hWnd):
        ShowWindow(hWnd, SW_RESTORE)
        BringWindowToTop(hWnd)
        UpdateWindow(hWnd)

    # Check to see if we are the foreground thread
    foregroundHwnd = GetForegroundWindow()
    foregroundThreadID = GetWindowThreadProcessId(foregroundHwnd, None)
    ourThreadID = GetCurrentThreadId()

    # If not, attach our thread's 'input' to the foreground thread's
    if foregroundThreadID != ourThreadID:
        AttachThreadInput(foregroundThreadID, ourThreadID, True)

    ShowWindow(hWnd, SW_SHOWNA)
    BringWindowToTop(hWnd)
    # Force our window to redraw
    if invalidate:
        InvalidateRect(hWnd, None, True)
    if foregroundThreadID != ourThreadID:
        AttachThreadInput(foregroundThreadID, ourThreadID, False) 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:31,代码来源:Utils.py


注:本文中的win32process.GetWindowThreadProcessId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。