Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was writing a function to get the handle of current active window in the Application. For that I am using Extern.Declare to declare and use WinAPI functions. I need to use EnumChildWindows which will enumerate through the child window by passing the top window handle using GetTopWindow WinAPI.

EnumChildWindows has a parameter that is a pointer to an application-defined callback function, which I understand, is a limitation of the Extern object. What could be the workaround for this?


My algorithm is something like this :

Dim hwnd ‘(Handle of my main Application)

top_hwnd = GetTopWindow (hwnd)

parent_hwnd = GetWindow (top_hwnd, GW_CHILD) ‘I need to do this to get the application handle since QTP/UFT gets confused with the Application handle and Ribbon handle

GetWindowHandleByClass(parent_hwnd , ClassName_child)

share|improve this question

Take a look at, and

This is a c# example, but you wrap this in a dll and import into QTP.

Also, depending on the window you might be over-engineering a bit.

If you top window is the parent, and the window you need is GW_PopUp with a class #32770 then perhaps you can use GetWindow instead.

share|improve this answer
I am using GetWindow(top_hwnd, GW_CHILD) to get the parent_hwnd. Since the parent has ‘n’ number of children, I need to enumerate through all of them to know if the specified window (identified through its parent and classname) is active and it is in focus. Here I use EnumChildWindows, however, I am uncertain about how to pass the second parameter which is a pointer to an application-defined callback function. I have modified my Question description with more information – user7324 Mar 26 '14 at 6:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.