Use win32gui.GetClassName to create a window on the excel using the location of the excel, but the positions on both sides do not match.Why isn't the coordinates right?
def main(cl_hwnd):
global hWindow
cl_left, cl_top, cl_right, cl_bottom = win32gui.GetClientRect(cl_hwnd)
cl_width = cl_right - cl_left
cl_height = cl_bottom - cl_top
cl_x_top, cl_y_top = win32gui.ClientToScreen(cl_hwnd, (cl_left, cl_top))
if __name__ == '__main__':
while True:
time.sleep(1)
classname = win32gui.GetClassName(win32gui.GetForegroundWindow())
print(classname)
if classname == 'XLMAIN':
cl_hwnd = win32gui.FindWindow(classname, None)
if cl_hwnd:
main(cl_hwnd)
break