Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5972583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:40:42+00:00 2026-05-22T20:40:42+00:00

I have a VSPackage with a dockable tool window containing form data. If there

  • 0

I have a VSPackage with a dockable tool window containing form data. If there are unsaved changes in this form, I would like to cancel a close to either the tool window and the visual studio IDE if the user clicks cancel on saving changes before closing. I can perform the save test on close, but I don’t see any event handler methods or other options to actually cancel the close.

Here is some blurb from the package:

    private DTE2 _applicationObject = null;
    ///--------------------------------------------------------------------------------
    /// <summary>This property gets the visual studio IDE application object.</summary>
    ///--------------------------------------------------------------------------------
    public DTE2 ApplicationObject
    {
        get
        {
            if (_applicationObject == null)
            {
                // Get an instance of the currently running Visual Studio IDE
                DTE dte = (DTE)GetService(typeof(DTE));
                _applicationObject = dte as DTE2;
            }
            return _applicationObject;
        }
    }
    ///--------------------------------------------------------------------------------
    /// <summary>
    /// Initialization of the package; this method is called right after the package is sited, so this is the place
    /// where you can put all the initilaization code that rely on services provided by VisualStudio.
    /// </summary>
    ///--------------------------------------------------------------------------------
    protected override void Initialize()
    {
        Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
        base.Initialize();

        // add the event handlers
        if (ApplicationObject != null)
        {
            // wire up window events
            PackageWindowEvents = (WindowEvents)ApplicationObject.Events.get_WindowEvents(null);
            PackageWindowEvents.WindowClosing += new _dispWindowEvents_WindowClosingEventHandler(PackageWindowEvents_WindowClosing);

            // wire up solution events
            PackageSolutionEvents = ApplicationObject.Events.SolutionEvents;
            PackageSolutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(CheckOpenCurrentSolution);

            // wire up DTE events
            PackageDTEEvents = ApplicationObject.Events.DTEEvents;
            PackageDTEEvents.OnBeginShutdown += new _dispDTEEvents_OnBeginShutdownEventHandler(HandleVisualStudioShutdown);
        }
    }

    void PackageWindowEvents_WindowClosing(Window window)
    {
        // handle save/cancel scenarios
    }

And some blurb from the ToolWindowPane that implements IVsWindowFrameNotify3:

    protected override void OnClose()
    {
        base.OnClose();
    }
    public int OnClose(ref uint pgrfSaveOptions)
    {
        return (int)__FRAMECLOSE.FRAMECLOSE_PromptSave;
    }

The OnClose and WindowClosing methods fire when expected, but I’m not finding a way to cancel the close. What am I missing? Are there different events required to cancel a close?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:40:43+00:00Added an answer on May 22, 2026 at 8:40 pm

    For completeness, there IS a useful way to cancel a close with a tool window (provided by user Chicobo on the msdn forum and repeated here).

    1. In your ToolWindowPane class, implement the IVsWindowFrameNotify2 interface, which provides a method OnClose.

    2. To cancel the window closing, consider using :

      public int OnClose(ref uint pgrfSaveOptions)
      {
          // Check if your content is dirty here, then
      
          // Prompt a dialog
          MessageBoxResult res = MessageBox.Show("This Document has been modified. Do you want to save the changes ?",
                        "Unsaved changes", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
          // If the users wants to save
          if (res == MessageBoxResult.Yes)
          {
              // Handle with your "save method here"
          }
      
          if (res == MessageBoxResult.Cancel)
          {
              // If "cancel" is clicked, abort the close
              return VSConstants.E_ABORT;
          }
      
          // Else, exit
          return VSConstants.S_OK;
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a VSPackage that I would like to get information similar to that
Have have this line of code in my form when I create a new
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you managed to get Aptana Studio debugging to work? I tried following this,
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have converted devise new session from erb to Haml but doens't work, this is
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:
Have a look at this url: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jquery_ui_methods#column_chooser I have got the Column Chooser dialog
Have not done this before, so obviously I suck at it. Here 64 pixels
Have not done this before ( except in java , look how Steve McLeod

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.