import win32gui
#设置为最前窗口
win32gui.SetForegroundWindow(hwnd)
#获取最前窗口句柄
hwnd = win32gui.GetForegroundWindow()
#获取窗口标题
GetWindowText(hwnd)
#通过类名或查标题找窗口
hwnd = win32gui.FindWindow(None, "C:\Windows\system32\cmd.exe")
#获取所有活动窗口的标题
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from win32gui import *
titles = set()
def foo(hwnd,nouse):
#去掉下面这句就所有都输出了,但是我不需要那么多
if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
titles.add(GetWindowText(hwnd))
#www.iplaypy.com
EnumWindows(foo, 0)
lt = [t for t in titles if t]
lt.sort()
for t in lt:
print t