Win32gui: locate and handle windows Save As input box exceptions, win32gui input box
When you use win32 to locate a Windows application, you need to automatically save the report. The name input box cannot be located in win32gui. findjavaswex.
Note: Use the python language
The problem is described as follows:
Code:
Save_w_hld = win32gui. findWindow (U' #32770 ', u "Save as") win32gui. setForegroundWindow (save_w_hld) save_name_edit = win32gui. find1_wex (save_w_hld, None, u'edit', None) print save_name_edit
Result:
0, that is, the handle whose classname is 'edit' is not found.
Analysis:
[Save as] the window belongs to the Windows built-in window. I tried other methods.
For example, 1. GetDlgItem obtains the input box handle by ID. The handle with the window ID 1001 is not unique. Not feasible
2. after you click Save As, the cursor is in the name input box by default. If you directly use SendMessage to write a new name abc and enter save_w_hld in the handle, the file name is not changed, the 'save as 'dialog box is changed to 'abc '. It does not work either.
Solution:
Use the coordinates of the Main Window, move the mouse to the namebox according to the displacement, use GetCursorPos to get the point, and then use WindowFromPoint to get the handle of the point.
1 save_w_hld = win32gui. findWindow (U' #32770 ', u "Save as") 2 win32gui. setForegroundWindow (save_w_hld) 3 win32gui. moveWindow (save_w_hld, 798,537, False) 4 left, top, right, bottom = win32gui. getWindowRect (save_w_hld) 5 win32api. setCursorPos (left + 200, top + 355) 6 POS = win32gui. getCursorPos () 7 edit = win32gui. windowFromPoint (POS) 8 win32api. sendMessage (edit, win32con. WM_SETTEXT, None, "abc") 9 print 'OK'
The displacement method is unstable. You can set the size of the main window to minimize the uncertainty.