How to call a WinAPI function in QTP/UFT having a parameter as a pointer to callback function?



  • 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)



  • 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.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2