Jump to content

Detecting different versions of a running window...


Recommended Posts

Ok, lets say I have two copies of notepad open with a fresh file on each. The default name is "Untitled - Notepad" for each of them right now. I know I can use the ControlSend function to send input directly to a chosen window, but how can I allow it to differentiate between the active notepad, and the inactive notepad without creating a custom window title for one of them?

EDIT: I know I can use the AutoITv3 Window Info tool to find the Handle of each manually, I want to do this automatically to get the handle of the actively running window.

Edited by DoubleMcLovin
Link to comment
Share on other sites

This will get you the currently active window:

$hWin=WinGetHandle("[ACTIVE]")

If Notepad isn't active, you'll have to figure another way to distinguish which one is the one you want. I'm not sure if there's a way to get the Z-order list of Windows, but even then - what happens if Notepad is minimized?

Link to comment
Share on other sites

If Notepad isn't active, you'll have to figure another way to distinguish which one is the one you want. I'm not sure if there's a way to get the Z-order list of Windows, but even then - what happens if Notepad is minimized?

If notepad is minimized and I am using the COntrolSend function, shouldn't it still receive my input?
Link to comment
Share on other sites

Two or three things come to mind. when you say a "fresh file on each" do you mean a new empty document? If so, does it matter which one you use? If they are not empty, you can check for the window with title "Untitled - Notepad" and text - "whatever"

If it is simple a matter of sending to the same one each time (but it doesn't matter which one originally) then use WinGetHandle

Link to comment
Share on other sites

If notepad is minimized and I am using the COntrolSend function, shouldn't it still receive my input?

Wouldn't it then not be considered the 'active' notepad? My point is - how do you distinguish. But to answer your question - yes, many (but not all) applications will respond to ControlSend in minimized/hidden states.

Link to comment
Share on other sites

Of course notepad is just a simple example. My actual goal does not involve using notepad, it more closely resembles background processing so that I can continue to work in the foreground on my own while in the background a control is manipulated.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...