locked
Close a Tool Window when Visual Studio closes RRS feed

  • Question

  • Hello,

    I have an extension VS package that includes a custom tool window that opens as a tab when clicking on a menu item (just like right clicking a project properties and getting the project properties editor).

    I don't want this window to stay open when the user closes and re-opens visual studio. How can I accomplish this?

    Note: The tool window is not at all related to the currently open solution

    Thanks,

    Tyler Doerksen


    Tyler D - Imaginet

    Wednesday, September 26, 2012 8:07 PM

Answers

  • Ok I think I found the solution I was looking for. And it was staring me right in the face.

    [ProvideToolWindow(typeof(EditorShellToolWindow), Transient = true)]

    Setting the Transient to true sets the DontForceCreate registry entry to "1"

    More information can be found in this article http://msdn.microsoft.com/en-us/library/bb165062.aspx

    "This registers the tool window named DynamicWindowPane as a transient window that is not persisted when Visual Studio is closed and reopened."

    Thanks!



    Tyler D - Imaginet

    • Marked as answer by Tyler Doerksen Friday, September 28, 2012 3:35 PM
    Friday, September 28, 2012 3:35 PM

All replies

  • Hi Tyler,

    We can use the event of WindowClosing and add the toolwindows.close() in it.

    You can try the code as following below:

    dte.Events.WindowEvents.WindowClosing +=

    new _dispWindowEvents_WindowClosingEventHandler(window_colsing);

    More information you can refer to:

    http://msdn.microsoft.com/en-us/library/envdte._dispwindowevents_event.windowclosing.aspx

    I found an article about How to: Create and Control Tool Windows as following below you can refer to:

    http://msdn.microsoft.com/en-us/library/dwtd01y4.aspx

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Ego Jiang Friday, September 28, 2012 5:44 AM
    Friday, September 28, 2012 5:42 AM
  • Thank you for the response Ego. However, the links and guidance that you posted refer to Visual Studio Add-In's not VSPackages.

    I tried to follow a similar route with the package but it does not seem to be working here is the event handler that I placed in my code

    private void WindowEventsOnWindowClosing(Window window)
    {
        var toolWindow = this.FindToolWindow(typeof(EditorShellToolWindow), 0, false);
    
        if (toolWindow != null && toolWindow.Frame != null)
        {
            ((IVsWindowFrame)toolWindow.Frame).CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
        }
    }


    The portion that I am unsure about is the 

    (uint)__FRAMECLOSE.FRAMECLOSE_NoSave

    My Tool window saves constantly and does not require saving. Do you know if this approach will work for VSPackages?

    Also this may be another solution. I was looking at this article http://msdn.microsoft.com/en-us/library/bb165452.aspx and see that there is a registry entry called "DontForceCreate" but I am not sure how to directly manipulate that entry with the package attributes.

     

    Tyler D - Imaginet

    Friday, September 28, 2012 3:03 PM
  • Ok I think I found the solution I was looking for. And it was staring me right in the face.

    [ProvideToolWindow(typeof(EditorShellToolWindow), Transient = true)]

    Setting the Transient to true sets the DontForceCreate registry entry to "1"

    More information can be found in this article http://msdn.microsoft.com/en-us/library/bb165062.aspx

    "This registers the tool window named DynamicWindowPane as a transient window that is not persisted when Visual Studio is closed and reopened."

    Thanks!



    Tyler D - Imaginet

    • Marked as answer by Tyler Doerksen Friday, September 28, 2012 3:35 PM
    Friday, September 28, 2012 3:35 PM
  • Hi Tyler,

    I’m glad to hear that you got it working.

    Thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 1, 2012 12:26 AM
  • Yes, this is the proper way to do it. Trying to muck with the window during shutdown is dodgy, you have to ensure it happens before the window profile is persisted, and I am not sure if there is a time whereby we guarantee that it is 'the last point in time before window profile serialization happens', so even if you found something that appeared to work using that mechanism it could break going forward as we don't guarantee callback ordering unless it is explicitly specified or someone from the team says it is a safe assumption.

    Ryan

    Monday, October 1, 2012 4:37 AM
  • I was facing the same problem. Solved in a clean manner! Thanks! :)
    Thursday, October 13, 2016 11:53 AM