1

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?

UPDATE

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)

2

Take a look at http://msdn.microsoft.com/en-us/library/windows/desktop/ms633494(v=vs.85).aspx, and http://www.pinvoke.net/default.aspx/user32/enumchildwindows.html

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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