0

i am working on Visual Studio extensions. There is a WindowPane that hosts an Editor Window along with a hierarchy of Window Forms, so from one of these Window Forms i am trying to give focus to the open Editor Window by using the Mouse_Click event. I am trying to do this because, if there is any other Auto Hide ToolWindow(like solution explorer) visible, the Editor Window does not gain focus on Mouse_Click of the hosted Window Form within the Editor Window.

I have tried the following code, but gives a null reference exception on the IVsWindowFrame.

        IVsUIShell vsUIShell = (IVsUIShell)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsUIShell));
        Guid guid = typeof(SampleEditorPane).GUID;
        IVsWindowFrame vsWindowFrame;
        int status = vsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fFindFirst, ref guid, out vsWindowFrame);

        if (status != VSConstants.S_OK)
            status = vsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref guid, out vsWindowFrame);

        if (status == VSConstants.S_OK)
            ErrorHandler.ThrowOnFailure(vsWindowFrame.Show());

Is there any other way i can set focus to the active Editor Window?.

Visual Studio also provides a shortcut ALT + f7 to browser through and select any active Tool Windows.Even if i could implement the above scenario, it would definitely help.

Thanks in advance. Any help is appreciated.

codeMORE
  • 21
  • 2
  • The following thread provide two method to find related toolwindow, please check if you used from your own package.https://stackoverflow.com/questions/29414722/how-to-open-a-tool-window-of-a-visual-studio-extension-programmatically – Zhanglong Wu - MSFT May 26 '17 at 05:56
  • i get a null reference exception on vsWindowFrame, not sure why this happens even though the SimpleEditorWindow is visible. Maybe the window is not completely initialized. – codeMORE May 30 '17 at 04:58

0 Answers0