Para Visual Studio 2008, una forma un poco mejor de escribir la macro a partir de la respuesta aceptada es utilizar los eventos de la solución en lugar de los del documento; esto le permite editar siempre la barra de título, incluso si no tiene un documento seleccionado.
Aquí está la macro que mi compañero de trabajo y yo armamos en función de la otra: querrá cambiar las líneas 15-18 para extraer el nombre de su rama del directorio de origen para la configuración que tenga.
Private timer As System.Threading.Timer
Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, ByVal lpstring As String) As Boolean
Private _branchName As String = String.Empty
Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
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, 25)
End If
Dim sourceIndex As Integer = DTE.Solution.FullName.IndexOf("\Source")
Dim shortTitle As String = DTE.Solution.FullName.Substring(0, sourceIndex)
Dim lastIndex As Integer = shortTitle.LastIndexOf("\")
_branchName = shortTitle.Substring(lastIndex + 1)
showTitle(_branchName)
Catch ex As Exception
End Try
End Sub
Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing
If Not timer Is Nothing Then
timer.Dispose()
End If
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
showTitle(_branchName)
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