0

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?

image

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
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
thon13
  • 1
  • Take a look at `GetWindowRect`. `GetClientRect` gets the size of the client (not including the non-client) area. You want the entire window, not just the client area of the window. – Andy Sep 05 '20 at 04:43
  • Your code doesn't create a window. – David Heffernan Sep 05 '20 at 06:43

0 Answers0