问题
I'm trying to automate many repetitive tasks at work and this small problem got me stumped.
We are using an application for printing out labels for online-orders, the process is like this.
- Click the order
- Check order details and Click "Finish"
- 5 seconds of the program calculating
- Confirm that you wish to print the label
- Label prints and you're done
On busy days we gotta go trough this process for over 500 orders, because this task consumes a lot of useless time because of step 3. The user has to wait those 5 seconds before being able to click the Print button. Let's say we have 500 orders, that's 500 times 5 seconds, that's about 40 minutes. The entire sending process costs 2 hours, so 33% of all time is lost because of people waiting to click the button.
I'm trying to find a way to automate step 4 so users can stop interacting with the application after completing step 2.
So is there a way using C# to click a button in another form from a different application? The event has to trigger when the confirmation screen pops up. Note that this confirmation screen is not the default windows printing dialog, but a part of the application, so no messing with the preferences.
回答1:
I think you should look into the UI scripting tools like AutoIt and AutoHotkey instead of writing your own.
回答2:
This article on CodeProject might be useful to you:
- Automating Windows Applications by injecting COM objects into the process
回答3:
You may be able to click a button on the form with the User32 dll if you know the forms handle.
I use PInvoke.net to look up the methods
In order to work out whether the screen has opened / closed you could create a windows hook that fires when a screen opens or closes. You will need to have a C++ library to do this as its not possible in c#, but you only need to create a small C++ assembly then reference it from your c#. You can check the title of a window when it opens to see if its the window you want, then you can get the window handle and see when it closes.
Some information on how to implement hooks can be found here.
http://www.voidnish.com/Articles/ShowArticle.aspx?code=manipwindows
The C++ assembly I used once is called GlobalCBTHook.
Here is another link from code project that shows global window hooks
http://www.codeproject.com/KB/system/WilsonSystemGlobalHooks.aspx
The link above is the one that got me started
来源:https://stackoverflow.com/questions/6408547/interacting-with-other-applications-like-clicking-a-button