MainWindowHandle is set to zero by QsExternalApplicationAdapter.

Mar 6, 2013 at 11:14 PM
I am trying QuickStarts for the technology survey of CCA.
MainWindowHandle is set to zero inside QsExternalApplicationAdapter, why is it?


public override bool NotifyContextChange(Context context)
{
  IntPtr ptr = MainWindowHandle;
// Find the control (first name) by position
IntPtr childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intFirstNameCoordX, intFirstNameCoordY));

As solution, I acquired the handle by FindWindow.


public override bool NotifyContextChange(Context context)
{
  IntPtr ptr = MainWindowHandle;
ptr = Win32API.FindWindow("WindowsForms10.Window.8.app.0.2bf8098_r11_ad1", "QSExternalApp");

// Find the control (first name) by position
IntPtr childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intFirstNameCoordX, intFirstNameCoordY));

Why is MainWindowHandle set to zero?

Moreover, since it does not go into tab of mainpanel as at now, I think that it will put into tab using SetWindows.
Therefore, handle of tab which serves as parents is needed.
Is it possible to acquire handle of tab from the inside of Adapter?
Mar 7, 2013 at 12:51 PM
Hello mmizuno,

According to the documentation that property is not what you are looking for,

"Designated MainWindowHandle for integration purposes, may not be the same as Process.MainWindowHandle "

In my experience with adapters I don't derive from ApplicationAdapter but from WinDataDrivenAdapter or from UIADataDrivenAdapter, then in the constructor I have access to the application object, then I can do this,
    public QsExternalAppAdapter(XmlDocument appInitString, object appObject)
        : base(appInitString, appObject)
    {
        try
        {
            this.hWndMainWindow = (IntPtr)appObject;
        }
        catch (InvalidCastException ex)
        {
            Logging.Error("MyApp", "Uh uh", ex);
            throw;
        }
        catch (Exception badex)
        {
            Logging.Error("MyApp", "Uh uh", badex);
            throw;
        }
    }
Where hWndMainWindow is just a private IntPtr hWndMainWindow