views:

238

answers:

1

I have a test that launches an app and verifies it has launched through calls to GetForegroundWindow(). The test is run on a remote machine that we usually access through remote desktop. When we have a rdp session open to the machine, the test completes and all is well. However, once we close the remote desktop, the test fails because GetForegroundWindow is always returning Null. I've checked that the active desktop after I disconnect is still 'Default', so I'm sure I am not running into this issue. Any ideas what might be causing this?

Thanks in advance

A: 

I'm assuming that have GetForegroundWindow returns, you have some way to validate that the returned HWND is from the app of interest and not some other window.

In any case, use EnumWindows to get all the windows on the screen. Find the HWND that matches the app you are looking for.

If you don't have a way to validate the HWND, then call EnumWindows before launching the app to get the total count of windows on the screen. Then launch your app via your automation script. Poll the window count via EnumWindows until the count increases by one.

selbie