[Python learning] to hide the window

import win32gui  
import win32api,win32con 
import time

'''
Execute the following command
pip install pywin32
'''

# Gets the screen width and height
screen_width=win32api.GetSystemMetrics(win32con.SM_CXFULLSCREEN)
screen_height=win32api.GetSystemMetrics(win32con.SM_CYFULLSCREEN)
print(screen_width,screen_height)

while True:

    try:
        # Get the current window handle 
        hwnd = win32gui.GetForegroundWindow()
        # print(hwnd) 


        # Get the current window coordinates  
        left,top,right,bottom=win32gui.GetWindowRect(hwnd)
        print(left,top,right,bottom)

        # Get the mouse position
        cursor_x, cursor_y = win32gui.GetCursorPos ()
        print (cursor_x, cursor_y)

        if left<=cursor_x and cursor_x<=right and top<=cursor_y and cursor_y<=bottom:
            print ( 'in the window')

        '''
        Achieve change the current window position 
        Task manager invalid
        '''
        win32gui.SetWindowPos (hwnd, None, 100, 0, 600, 400, win32con.SWP_NOSENDCHANGING | win32con.SWP_SHOWWINDOW) 
        time.sleep(0.5)
    except:
        pass

Guess you like

Origin www.cnblogs.com/cyber-shady/p/11520439.html