I\'m implementing a task-bar replacement, dock-like application-switcher style program. It\'s doing some unique stuff with OpenGL, and with keyboard shortcuts, so the way it
I saw some great answers above, but needed extra functionality where window name would be a more flexible parameter. On failure it returns false:
from win32gui import IsWindowVisible, GetWindowText, EnumWindows,\
ShowWindow, SetForegroundWindow, SystemParametersInfo
#Sub-Functions
def window_enum_handler(hwnd, resultList):
if IsWindowVisible(hwnd) and GetWindowText(hwnd) != '':
resultList.append((hwnd, GetWindowText(hwnd)))
#Prime-Functions
def winFocus(partial_window_name):
SystemParametersInfo(8193, 0, 2 | 1)
handles=[]
EnumWindows(window_enum_handler, handles)
for i in handles:
if str(partial_window_name).upper() in str(i[1]).upper():
ShowWindow(i[0], 3)
SetForegroundWindow(i[0])
return True
print(partial_window_name + " was not found")
return False
winFocus("not existing window")
winFocus("ChroME")