Filter build output and add sound





3.00/5 (6 votes)
As I started with VS.NET I had unfamiliarities. The build output had useless stuff and I couldn't make build sounds as I always had. I made the macro to fix it. See and learn (the macro is only for VS.NET)
Annoyance
Changing an IDE can be a difficult thing. All the useful tools you got used to suddenly don't work quite right. Upon starting with VS.NET I had two annoyances:
- In VC++ 6 I had nice sounds schemes, a sound for a "error in compile", "warning in compile" (no errors) and "compile succeeded" (no errors and no warnings). Sadly, in VC.NET the sounds system is kinda messed up - I couldn't set sound on warning and also it insisted playing some general sounds from the control panel (something that pissed me off).
- VS.NET generates in the build output some lines in the end that I don't need:
---------------------- Done ---------------------- Build: 1 succeeded, 0 failed, 0 skipped
And it scrolls up too much so I don't see the much more important - number of errors/warnings. This together with problem #1 can be annoying.
These problems are no way critical, but I want to feel comfortable and I prefer squashing annoyances to living with them.
Solution
To install the macro put it in your macro file under EnviromentEvents()
function.
Here is the macro:
Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Public Declare Function waveOutGetNumDevs Lib "winmm" () As Long
'just after the sound is ended Exit Function
Const SND_SYNC = &H0
'just after the beginning of the sound Exit Function
Const SND_ASYNC = &H1
'if the sound cannot be found no Error message
Const SND_NODEFAULT = &H2
'repeat the sound until the Function is called again
Const SND_LOOP = &H8
'if currently a sound is played the
'Function will return without playing the selected sound
Const SND_NOSTOP = &H10
Const Flags& = SND_ASYNC Or SND_NODEFAULT
Public Sub BuildEvents_OnBuildDone(ByVal _
Scope As EnvDTE.vsBuildScope, _
ByVal Action As EnvDTE.vsBuildAction) Handles _
BuildEvents.OnBuildDone
' Create a tool window handle for the Output window.
Dim win As Window =
DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
' Create handles to the Output window and its panes.
Dim OW As OutputWindow = win.Object
Dim OWp As OutputWindowPane
Dim Loc As Integer
OWp = OW.OutputWindowPanes.Item(1)
OWp.TextDocument.Selection.SelectAll()
Dim Context As String = OWp.TextDocument.Selection.Text
OWp.TextDocument.Selection.CharLeft()
Loc = InStr(Context, "---------- Done -----------")
OWp = OW.OutputWindowPanes.Item(2)
OWp.Activate()
OWp.Clear()
OWp.OutputString(Mid(Context, 1, Loc - 7))
OWp.TextDocument.Selection.GotoLine_
(OWp.TextDocument.EndPoint().Line())
'Play sounds
If InStr(Context, "0 error(s)") = 0 Then
sndPlaySound("Error.wav", SND_SYNC) ' Edit
ElseIf InStr(Context, "0 warning(s)") = 0 Then
sndPlaySound("Warning.wav", SND_SYNC) ' Edit
Else
sndPlaySound("Fine.wav", SND_SYNC) ' Edit
End If
End Sub
Don't forget to edit the wav file names to suit it to your needs. After that go back to your project and work as usual.