I want to detect a click on any window's minimize button with win32gui. I have a idea to use WM.NCHITTEST but I have no idea how to use it.
I want to detect a click on any window's minimize button with win32gui. I have a idea to use WM.NCHITTEST but I have no idea how to use it.
I figured it out.
The following snippet first waits for a right click and then get's the click positions(x and y axis) and then performs the hittest to know the type of area on which the click was performed:
import win32gui, win32api
previous_state = win32api.GetKeyState(0x02)
while True:
a = win32api.GetKeyState(0x02)
if a != previous_state:
previous_state = a
if a < 0:
Clickx, Clicky = win32gui.GetCursorPos()
window = win32gui.GetForegroundWindow()
win32gui.SetForegroundWindow(window)
WM_NCHITTEST_result = win32gui.SendMessage(window, 0x0084,"",Clickx)
if WM_NCHITTEST_result == 8: # check if click is on the minimize btn
# Do something here
Officialy the hittest is performed with:
Clickx, Clicky = win32gui.GetCursorPos()
WM_NCHITTEST_result = win32gui.SendMessage(window, 0x0084,"",Clickx)
and the result is checked if it was a minimize click:
if WM_NCHITTEST_result == 8: