python发送windows消息测试
import win32gui, win32con, win32api, win32event, win32process, time, psutil, datetime
tarExe = r"E:\test.x64.exe"
win32api.ShellExecute(0, 'open', tarExe, r'"C:\Users\test.png"','',1)
time.sleep(2)
# FindWindow(lpClassName=None, lpWindowName=None) 窗口类名 窗口标题名
handle = win32gui.FindWindow(None, "THUMB")
ID__EXIT_APP = 134
b=win32gui.GetDlgItem(handle, ID__EXIT_APP)
t1 = datetime.datetime.now()
# WPARAM MAKEWPARAM(WORD wLow, WORD wHigh); wParam = HIWORD<<16+LOWORD。
BN_CLICKED = 0
win32api.SendMessage(handle, win32con.WM_COMMAND, BN_CLICKED<<16 | ID__EXIT_APP, b)
thread,processId =win32process.GetWindowThreadProcessId(handle)
while psutil.pid_exists(processId): time.sleep(0.2)
t2 = datetime.datetime.now()
print("exit cost %s seconds"%(t2- t1).seconds)