Is there an event triggered when dte.Solution.SolutionBuild.StartupProjects changes?

前提是你 提交于 2019-12-07 08:00:33

问题


I am building a visual studio 2010 Add-in for internal use in my company. I would like to customize the main window caption to display the name of the current start up project. I can set the caption of the main window with the following code:

            DTE d = GlobalClass.dte2 as DTE;
        IntPtr hWnd = new System.IntPtr(d.MainWindow.HWnd);


        if (d.Solution.SolutionBuild.StartupProjects != null)
        {
            object[] sStartUpProject = (object[])d.Solution.SolutionBuild.StartupProjects;

            string Caption = d.MainWindow.Caption + "Current Project: " + (string)sStartUpProject[0];

            SendMessage(hWnd, WM_SETTEXT, new IntPtr(0), Caption);
        }

I can fire this code whenever a window is created or activated, but this does not update the Caption if the user changes the startup project in the solution explorer (or my add-in) and doesn't move to another window in Visual Studio. I would like the caption to update as soon as the change was made.


回答1:


Yes, you need subscribe to IVsMonitorSelection events and handle SEID_StartupProject in OnElementValueChanged().

Check out this code, it's quite self-explaining:

https://bitbucket.org/thirteen/switchstartupproject/src/a80f0deb737c/SwitchStartupProject/SwitchStartupProjectPackage.cs



来源:https://stackoverflow.com/questions/4262514/is-there-an-event-triggered-when-dte-solution-solutionbuild-startupprojects-chan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!