如何更改Visual Studio的标题栏文本

时间:2009-02-23 10:42:53

标签: visual-studio visual-studio-2008

我们在相同代码的几个不同分支上工作,当同时处理两个分支时,它可能会变得混乱和浪费时间。

目前,VS标题栏的文字为<solution-name> - Visual Studio

我是否可以编写一个扩展文件<solution-name>: <branch-name> - <Visual Studio>

11 个答案:

答案 0 :(得分:56)

我刚刚创建了一个可以帮助的小型Visual Studio扩展: http://visualstudiogallery.msdn.microsoft.com/f3f23845-5b1e-4811-882f-60b7181fa6d6

  

这个小扩展程序会检测到   每当两个Visual实例   Studio正在运行并更改   Visual Studio的窗口标题   包括的父文件夹名称   解。因此会改变    SolutionFolder - Microsoft Visual Studio 成    SolutionFolderParent \ SolutionFolder - Microsoft Visual Studio

     

这在特别有用时   分支解决方案:它变成了   可以轻松识别哪个   在这种情况下,你正在研究的分支机构   两者都有相同的   解决方案名称。

官方网页: http://erwinmayer.com/labs/visual-studio-2010-extension-rename-visual-studio-window-title/

答案 1 :(得分:18)

查看VSCommands 2010 Lite的最新版本。它引入了一个名为Friendly Solution Name的功能,您可以在其中设置正则表达式模式以从文件夹结构中提取分支名称并将其放在Visual Studio主窗口标题中。更多详情:http://vscommands.com/releasenotes/3.6.8.0http://vscommands.com/releasenotes/3.6.9.0

MSDN Download Page

答案 2 :(得分:3)

尝试设置MainWindow.Caption会引发异常。您必须使用Win32 SetWindowText函数来更改标题,但要注意:Visual Studio会重置标题栏文本,因此您应该实现一个Timer来继续设置所需的文本。来自加载项的Connect类的以下代码将永久(或者,只要加载项正在运行)将标题栏文本保留为“Hello World!”

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    resetTitleTimer = new Timer(new TimerCallback(SetMainWindowTitle), "Hello world!", 0, 10);
}

[DllImport("user32.dll")]
private static extern bool SetWindowText(IntPtr hWnd, string lpString);
private void SetMainWindowTitle(object state)
{
    IntPtr hWnd = (IntPtr)_applicationObject.MainWindow.HWnd;
    SetWindowText(hWnd, "Hello World!");            
}

答案 3 :(得分:1)

我添加了一个带有不同名称的符号链接,其目标是解决方案文件。使用符号链接打开解决方案,窗口标题具有符号链接名称。

在Windows中: mklink BlawBranch.sln Blaw.sln

编辑: 如果目标.sln文件由我们的源代码控制更新,则发现硬链接中断。符号链接没有相同的问题。

答案 4 :(得分:1)

另一个扩展,通过将其定义为表达式来更改Visual Studio标题栏:http://visualstudiogallery.msdn.microsoft.com/2e8ebfe4-023f-4c4d-9b7a-d05bbc5cb239

使用“标题表达式”的设置使这个插件非常灵活。

答案 5 :(得分:0)

说实话,我不确定我是否正确地理解了你的问题,但我在这里问了一个似乎是关于类似问题的问题:

Working with different versions/branches of the same Visual Studio 2005 solution

答案 6 :(得分:0)

也许更简单的解决方案是使用虚拟桌面?空间布置更容易记住,您可以将任何相关窗口与相应的VS分组,并且切换会更简单。

答案 7 :(得分:0)

任何基于Visual Studio的IDE都有一个名称为AppName的属性,应该可以解决这个问题。

答案 8 :(得分:0)

http://www.helixoft.com/blog/archives/32设置标题到当前文件名。它也适用于Visual Studio 10

  Private timer As System.Threading.Timer
Private ideTitle As String = Nothing
Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, _
ByVal lpstring As String) As Boolean

'''<summary>Called when any window in VS gets activated.</summary>
'''<param name="GotFocus">Window that got focus.</param>
'''<param name="LostFocus">Window that lost focus.</param>
Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated
    Try
        If timer Is Nothing Then
            ' Create timer which refreshes the caption because
            ' IDE resets the caption very often
            Dim autoEvent As New System.Threading.AutoResetEvent(False)
            Dim timerDelegate As System.Threading.TimerCallback = _
                AddressOf tick
            timer = New System.Threading.Timer(timerDelegate, autoEvent, 0, 200)
        End If

        If GotFocus.Document Is Nothing Then
            ideTitle = Nothing
        Else
            ideTitle = GotFocus.Document.FullName
            showTitle(ideTitle)
        End If
    Catch ex As System.Exception
    End Try
End Sub

''' <summary>Dispose the timer on IDE shutdown.</summary>
Public Sub DTEEvents_OnBeginShutdown() Handles DTEEvents.OnBeginShutdown
    If Not timer Is Nothing Then
        timer.Dispose()
    End If
End Sub

'''<summary>Called by timer.</summary>
Public Sub tick(ByVal state As Object)
    Try
        If Not ideTitle Is Nothing Then
            showTitle(ideTitle)
        End If
    Catch ex As System.Exception
    End Try
End Sub

'''<summary>Shows the title in main window.</summary>
Private Sub showTitle(ByVal title As String)
    SetWindowText(New System.IntPtr(DTE.MainWindow.HWnd), title & " - " & DTE.Name)
End Sub

答案 9 :(得分:0)

2012年,您必须设置System.Windows.Application.Current.MainWindow.Title才能使其生效。这将更新TaskBarItem标题和MainWindow标题。

这只能从主线程中进行,因为Visual Studio会在各个点上更新标题,你必须连接一些事件并将其重置为你想要的任何事件(在我的AddIn中,我使用其中一些EnvDTE.SolutionEvents。)

希望这有帮助。

答案 10 :(得分:-1)

在VS自动化模型中有

_DTE.MainWindow.Capation

你可以从这开始。

请参阅http://msdn.microsoft.com/en-us/library/envdte._dte.mainwindow.aspx

相关问题