I have written a vb.net
application to start an external application ( notepad.exe ) and then open the txt file located in at "D:\\test.txt" . I have used keyboard events to achive this.
Step1: Open the notepad
Process.Start("notepad.exe")
Step 2: Raised the keyboard event Ctrl + O to open the Open dialog box
keybd_event(VK_CONTROL, &H45, 0, 0)
keybd_event(VK_O, 0, 0, 0)
keybd_event(VK_CONTROL, &H45, KEYEVENTF_KEYUP, 0)
Step 3: Wait for 2 seconds.
Thread.Sleep(2000)
Step 4: Raised the keyboard event to type the File path "D:\\Test.txt" in the File Name textbox.
Issue: Occassionally the Open dialog box operation takes more time (exceeds 2000 ms) to open, as a result the file path typing event started before opening the open dialog box. I have increased the sleep time, but the issue not fixed completely.
Is there any way to check whether the Open dialog box is opened using the notepad process id?
I have tried using EnumChildWindows , but i didn't get the result.
The PID will change every time you open or close notepad. I would suggest to use the Image Name to check to see if it is open. beware of this option though because if you have to instances open this will cause an issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.