http://blogs.clariusconsulting.net/pga

Pablo Galiano's Blog

Go Back to
pga′s Latest post

Handling windows events inside VS

Suppose that we have a tool window and we want to handle the events when it is moved, resized, re docked, etc.

For doing that we only need to implement the Microsoft.VisualStudio.Shell.Interop.IVsWindowFrameNotify3 interface on the tool window.

The following code snippet does the trick:

[Guid("315b41f1-903f-4fcc-af56-a7ad9e84c910")]

public
class
MyToolWindow : ToolWindowPane, IVsWindowFrameNotify3

{

    privateMyControl control;

 

    public MyToolWindow()

        :

        base(null)

    {

        this.Caption = Resources.ToolWindowTitle;

        this.BitmapResourceID = 301;

        this.BitmapIndex = 1;

 

        control = newMyControl(this);

    }

 

    overridepublicIWin32Window Window

    {

        get

        {

            return (IWin32Window)control;

        }

    }

 

    #region IVsWindowFrameNotify3 Members

 

    publicint OnClose(refuint pgrfSaveOptions)

    {

        returnVSConstants.S_OK;

    }


 

    publicint OnDockableChange(int fDockable, int x, int y, int w, int h)

    {

        returnVSConstants.S_OK;

    }


 

    publicint OnMove(int x, int y, int w, int h)

    {

        returnVSConstants.S_OK;

    }


 

    publicint OnSize(int x, int y, int w, int h)

    {

        returnVSConstants.S_OK;

    }


 

    publicint OnShow(int fShow)

    {

        returnVSConstants.S_OK;

    }

 

    #endregion

}

 

One important thing to mention is that when the user click on the “X” of a tool window, VS doesn’t close it, it only hides it. When the IDE shuts down that is the only time when the tool window is closed.

 

Pablo

Comments