python 获取windows的句柄

import pyautogui
import win32con
import win32gui
import win32clipboard
import os

if  __name__== "__main__":

   
    #输入窗口标题
    handel = win32gui.FindWindow(None,"Spyder (Python 3.8)")
    #窗口句柄
    print (handel)
    app = win32gui.GetWindowText(handel)
    #窗口标题
    print(app)
    #设置窗口大小
    #win32gui.SetWindowPos(handel,win32con.HWND_TOPMOST,0,0,850,720,win32con.SWP_SHOWWINDOW)

    
#显示所有窗口的句柄和标题


# -*- coding: utf-8 -*-
"""
Created on Sun May  9 15:34:49 2021

@author: Administrator
"""



import win32gui

hwnd_title = {}

def get_all_hwnd(hwnd, mouse):
    if (win32gui.IsWindow(hwnd)
            and win32gui.IsWindowEnabled(hwnd)
            and win32gui.IsWindowVisible(hwnd)):
        hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)})


win32gui.EnumWindows(get_all_hwnd, 0)
for h, t in hwnd_title.items():
    if t :
        print (h, t.encode('utf-8').decode('utf-8'))
if __name__ == '__main__':
    pass


你可能感兴趣的:(python,python)