Win32gui: locate and handle windows Save As input box exceptions, win32gui input box

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.