How do I get the Active ChildWindow of an application?

I have this problem. I have a mainWindow handler for a specific application and I want to simulate a click on that application ...

I am using the sendMessage / postMessage api calls for this. The reason I am not using the .Net SendKeys function or keybd_event from the win32 api is because they simulate key presses globally. In my case, maybe the application can be minimized and still wants the simulation to be pressed.

The problem with sendMessage and postMessage is that you have to pass the handler to the exact child window you want to press the key in. For example, in notepad, if I post the key to mainWindow, nothing happens, I have to send the key to the child window, which is basically a white canvas where you can write.

With msPaint, for example, if a user creates a new document and opens a text field in that drawing and I want to simulate a key press, I need to get the child window of the main window's child window for it to work.

So I found a way that seemed to work for every situation, basically I used getWindow with GW_CHILD parameter to get the child window with the highest z value. Then I do it again for the child window and keep doing this until the specific child window has more childWindows ..

And it seemed to work and I was very happy!

However ... I've found cases where this doesn't work. Firefox is one of them. Firefox has a mainWindow and then it has a child window, which is almost the same as mainWindow, and then it has another child window, which is an area of ​​the website, i.e. The area under the address bar and menu. For example, if I'm on www.google.com and I want to simulate a key press on the focused search box, this works because getting the child window of the child window gives me the correct childWindow. However, if the user clicks on the address bar, for example, nothing changes in the way getWindow works. It will still end up with a child window that is in the address bar without doing anything, instead of simulating a key press on the address bar.

The thing is, I haven't found a way to get the active child window of a specific application. I can only use the GetWindow method to get the child window of a specific window and do that until I find a child window with no children. However, as you saw in the firefox case, the active window is actually the parent of the child window I get at the end.

I have tried other api calls such as getTopWindow but I have no luck.

Can anyone please tell me about this issue? Thanks!

+1


a source to share


2 answers


If the application violates the windowing rules for windows, you need an exception.

In Mozilla, it looks like (IIRC):

  • This is the "god" class window MozillaUIWindowClass

    and the line "- Mozilla Firefox" in the window text.
  • If you know the position of the address bar, you can use the following function:

And specify its HWND

windows "god" and the position of the address bar.



HWND ChildWindowFromPoint(HWND, POINT);

      

Perhaps the best solution, I came up with this since I needed to automate the mouse that is position based.

For more information, you may need to consult specific software sources or spend an entire day at Spy +.:>

0


a source


You can use GetGUIThreadInfo

to get information about the user interface of a specific process.

Once you have a main window, you can call GetWindowThreadProcessId

to get the thread id of the process. Then you can call GetGUIThreadInfo

to get information about active / focused windows etc.



I should also point out that some apps only have one window and all of its windowless controls (like Windows Live Messenger).

0


a source







All Articles