Im on Windows7 and I need to simulate a mouse click( without moving the cursor ) in a window that is minimized or hidden
Is this possible ? And if so, then how can I do this( what APIs should I use, and will work in all windowses ) ?

OBS: I need only the code scheme in general, not in a specific language.

4 solutions

Solution 2

[Edit]
Please note, this is brittle in the way described below. Restarting the "client" application generates a new classname based on the Hash of the AppDomain. This means the code below will work once and only once. Please see my other next answer for a less brittle Windows7-specific implementation. If doing this in c++, you will need to call the equivalent code as the second answer.

Yes. In principle, this is easy.
1. Use User32.dll (.net needs to import this)
2. Use FindWindow to get an address pointer to the window containing the control.
3. Use FindWIndowEx to get an address pointer to the button you want to click
4. Use SendMessage to place a button click message onto the windows message queue.

Now it depends which language you are using, I will assume c# here (and give links to a c++ version). The C++ version is simpler as it can import windows assemblies directly.

First import the relevant methods from user32 (I tested on 64 bit win7, so don't be put off by the name):

Now for the business end I created a dummy app. The form had a caption "FormToBeCaptured" (this is important). On it there was a text box and a button with the text "Add" in it. The event handler was hooked up so that if the button is pressed it appends "a" to the existing text in the text box.

The first two lines initalize empty pointers. The 3rd line finds the window via its caption, you may need to find another way to do this, but this is the simplest.
This line was problematic (it gets the Pointer to the button to be pressed via its caption:

The class name was "Button" in windows XP. In Windows 7 (possibly Vista too) this seems no longer to be the case. I used SPY++ (it is installed with Visual Studio) to examine the window. It seems the class name is now "WindowsForms10.BUTTON.app.0.bf7771_r15_ad1". This seems a bit brittle to me - you may need to check the class name on your machine, it may break on update too. If the class name is different in spy++, change it obviously.

The last line sends a message to the Windows Message Queue with the pointer to the button, the message as BM_CLICK and the lParam and wParam as IntPtr.Zero, in effect null.

As I say this is brittle, it will probably change between windows versions and possibly between updates. I've suggested spy++, but also you might find the following useful:

Solution 3

This solution is better for Win7 (and probably Vista - I can't check on this)
As I said in my original answer, finding the button control is brittle as it relies on the class name. Each time the application being targeted is run, the class name changes in Window7. Luckily I re-ran the code and spotted this, the last time I did this stuff was under XP and much seems to have changed under the hood. I have kept the original answer as it explains the basics which I want to keep, and editing it will make it even harder to read.

Anway instead of the FindWindowEx method, we can loop through the child controls to find a control captioned "Add" with a class name that starts with

Solution 1

mouse event handle by windows and always response to screen
and in application handle by function inside the code

if you have source code of minimized or hidden window and you can modify this , you can use other way to communication between 2 application
otherwise
try change status of window then
use mouse event simulation method
bat user may be detect you

"mouse event handle by windows and always response to screen"
Actually, this isn't strictly true, but you need to go down to the OS level rather than the application level.

All interaction with the GUI works by queuing messages through the Windows Message Queue.As long as you have the address pointer to the thing you want to interact with and the message code, you can interact with it. This works even if the target is hidden. If you think about it this is logical: otherwise Windows would not be able to un-minimise a minimised window.

Please look at my answers, they give the instructions to do this. I tested this code on Windows 7, but have used the method in the 1st answer under XP.