[VC++]VC編譯器有錯誤時就自動停止

posted in: C/C++程式設計 | 0

有時候當程式碼一大,在編譯時就要等很久
這時候如果裡面有錯誤的話更是令人抓狂…
Visual Studio又沒有手動停止編譯的功能,這時候該怎麼辦?

其實我們可以插入一個macro來實現這個功能
做法如下:

進到visual studio->Tools->Macros->Macro IDE,然後插入下面的程式碼

Private Sub OutputWindowEvents_OnPaneUpdated(ByVal pPane As OutputWindowPane) Handles                    OutputWindowEvents.PaneUpdated
        If Not (pPane.Name = "Build") Then Exit Sub
        pPane.TextDocument.Selection.SelectAll()
        Dim Context As String = pPane.TextDocument.Selection.Text
        pPane.TextDocument.Selection.EndOfDocument()
        Dim found As Integer = Context.IndexOf(": error ")
        If found > 0 Then '有找到錯誤就停止
            DTE.ExecuteCommand("Build.Cancel")
        End If
    End Sub

如下圖:

vs_error.jpg

這樣在發生第一個錯誤時就會停止編譯了

參考:http://zh-tw.w3support.net/index.php?db=so&id=134796

Leave a Reply

Your email address will not be published. Required fields are marked *