Python ctypes销毁windows桌面

from ctypes import *
 
WM_CLOSE = 0x10
win_name = "FolderView" #windows桌面的窗口名称

while True:
    hwnd = windll.user32.WindowFromPoint(0, 0) #获取位于(0, 0)的窗口
    b = create_string_buffer(256)
    windll.user32.GetWindowTextW(hwnd, byref(b), 256) #获取窗口标题
    title = str(b.raw, encoding="utf-16").strip("\x00")
    #windll.user32.CloseWindow(hwnd) #最小化
    windll.user32.SendMessageA(hwnd, WM_CLOSE, 0, 0) #关闭
    
    if title == win_name:
        break

运行后,windows桌面上的图标全部消失,最大化的窗口也被关闭。

猜你喜欢

转载自blog.csdn.net/qq_48979387/article/details/125337028