本文整理汇总了Python中win32gui.IsWindowEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python win32gui.IsWindowEnabled方法的具体用法?Python win32gui.IsWindowEnabled怎么用?Python win32gui.IsWindowEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32gui
的用法示例。
在下文中一共展示了win32gui.IsWindowEnabled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_hwnds_for_pid
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import IsWindowEnabled [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
示例2: __init__
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import IsWindowEnabled [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
示例3: _enumWindows
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import IsWindowEnabled [as 别名]
def _enumWindows(self, hwnd, _):
"""遍历回调函数"""
if hwnd == self.myhwnd:
return # 防止自己嵌入自己
if win32gui.IsWindow(hwnd) and win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
phwnd = win32gui.GetParent(hwnd)
title = win32gui.GetWindowText(hwnd)
name = win32gui.GetClassName(hwnd)
self.windowList.addItem(
'{0}|{1}|\t标题:{2}\t|\t类名:{3}'.format(hwnd, phwnd, title, name))
示例4: get_all_hwnd
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import IsWindowEnabled [as 别名]
def get_all_hwnd(hwnd, mouse):
'''
获取所有阴阳师窗口
'''
if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
if win32gui.GetWindowText(hwnd) == u'阴阳师-网易游戏':
hwndlist.append(hwnd)
示例5: _getHandleThroughFilename
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import IsWindowEnabled [as 别名]
def _getHandleThroughFilename(self):
Psapi = ctypes.WinDLL('Psapi.dll')
EnumProcesses = Psapi.EnumProcesses
EnumProcesses.restype = ctypes.wintypes.BOOL
GetProcessImageFileName = Psapi.GetProcessImageFileNameA
GetProcessImageFileName.restype = ctypes.wintypes.DWORD
Kernel32 = ctypes.WinDLL('kernel32.dll')
OpenProcess = Kernel32.OpenProcess
OpenProcess.restype = ctypes.wintypes.HANDLE
TerminateProcess = Kernel32.TerminateProcess
TerminateProcess.restype = ctypes.wintypes.BOOL
CloseHandle = Kernel32.CloseHandle
MAX_PATH = 260
PROCESS_TERMINATE = 0x0001
PROCESS_QUERY_INFORMATION = 0x0400
count = 32
while True:
ProcessIds = (ctypes.wintypes.DWORD*count)()
cb = ctypes.sizeof(ProcessIds)
BytesReturned = ctypes.wintypes.DWORD()
if EnumProcesses(ctypes.byref(ProcessIds), cb, ctypes.byref(BytesReturned)):
if BytesReturned.value<cb:
break
else:
count *= 2
else:
raise Exception('Call to EnumProcesses failed')
for index in range(BytesReturned.value / ctypes.sizeof(ctypes.wintypes.DWORD)):
ProcessId = ProcessIds[index]
hProcess = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, False, ProcessId)
if hProcess:
ImageFileName = (ctypes.c_char*MAX_PATH)()
if GetProcessImageFileName(hProcess, ImageFileName, MAX_PATH)>0:
filename = os.path.basename(ImageFileName.value)
if filename == self.filename:
break
#TerminateProcess(hProcess, 1)
CloseHandle(hProcess)
def get_hwnds_for_pid(pid):
def callback (hwnd, hwnds):
if win32gui.IsWindowVisible (hwnd) and win32gui.IsWindowEnabled (hwnd):
_, found_pid = win32process.GetWindowThreadProcessId (hwnd)
if found_pid == pid:
hwnds.append (hwnd)
return True
hwnds = []
win32gui.EnumWindows(callback, hwnds)
return hwnds
return get_hwnds_for_pid(ProcessId)