I really love using macros in VC++. They make things highly customizable, like I like them.
Not how MS wants me to use it.
So, I took the liberty to add to Thomas Mahler’s wonderful
macro for increasing build number. I added support for increasing ALL the build numbers
avaliable in the .rc file. I also added backing up the file, because I noticed in certain
situations, it would occasionally change settings and lines other than the build
numbers. So use with caution.
I added putting the current compile date/time
to the 2nd line. I also include here, a couple macros for backing up the current active document,
and restoring the .rc file.
First, the small macros-
Sub CurrentDateTime()
‘DESCRIPTION: Saves current date/time to the rc file, on line 2.Dim strMonth
Dim strDay
Dim strYear
Dim strHour
Dim strMinute
Dim strSecondDocuments.Open (ActiveProject.Name + “.rc”), “Text”
Windows(ActiveProject.Name + “.rc”).Active = TRUE
ActiveDocument.Selection.GoToLine 2
ActiveDocument.Selection.SelectLine
ActiveDocument.Selection.DeletestrMonth = CStr(DatePart(“m”, Now))
strDay = CStr(DatePArt(“d”, Now))
strYear = CStr(DatePart(“yyyy”, Now))
strHour = CStr(DatePart(“h”, Now))
strMinute = CStr(DatePArt(“n”, Now))
strSecond = CStr(DatePart(“s”, Now))ActiveDocument.Selection.Text =”// Last compiled “+strMonth + “/” +strDay +”/” +strYear+” at “+ strHour+”:”+strMinute+”:”+strSecond+ + vbCrLf
ActiveDocument.Selection.NewLine
ActiveDocument.Save (ActiveProject.Name + “.rc”)
ActiveDocument.Close()End Sub
Sub saveBackUpRC()
‘DESCRIPTION: Backs up rc file.Documents.Open (ActiveProject.Name + “.rc”), “Text”
Windows(ActiveProject.Name + “.rc”).Active = TRUE
ActiveDocument.Save (ActiveProject.Name + “.rc”+”~”)
ActiveDocument.Close()End Sub
Sub restoreRcFile
‘DESCRIPTION: Restores back up of rc file.Documents.Open (ActiveProject.Name + “.rc~”), “Text”
Windows(ActiveProject.Name + “.rc~”).Active = TRUE
ActiveDocument.Save (ActiveProject.Name + “.rc”)
ActiveDocument.Close()End Sub
Sub saveActiveDocBackup()
‘DESCRIPTION: Backs up current active document.Dim Wnd
Wnd = ActiveDocument.FullName
ActiveDocument.Save(ActiveDocument.fullname + “~”)
ActiveDocument.Close()
Documents.Open Wnd, “Text”End Sub
Now, the improved build increase macro
Sub IncResVersion()
‘DESCRIPTION: Build active project and increase version counters in rc script.
‘ Map it to F7 for ease of use. (c)’98 Th. Mahler and parts by LJP.Dim strMonth
Dim strDay
Dim strYear
Dim strHour
Dim strMinute
Dim strSecondDim Wnd
‘ open the project’s resource script:
Wnd = ActiveProject.Name + “.rc”
Documents.Open (ActiveProject.Name + “.rc”), “Text”
Windows(ActiveProject.Name + “.rc”).Active = True‘ SAVE BACK-UP OF FILE >>>>
ActiveDocument.Save (ActiveProject.Name + “.rc”+”~”)ActiveDocument.Close()
Documents.Open Wnd, “Text”‘Go to 2nd line in rc file, delete it, and get current time/date
ActiveDocument.Selection.GoToLine 2
ActiveDocument.Selection.SelectLine
ActiveDocument.Selection.DeletestrMonth = CStr(DatePart(“m”, Now))
strDay = CStr(DatePArt(“d”, Now))
strYear = CStr(DatePart(“yyyy”, Now))
strHour = CStr(DatePart(“h”, Now))
strMinute = CStr(DatePArt(“n”, Now))
strSecond = CStr(DatePart(“s”, Now))‘write current date/time and add newline – formatted for USA
ActiveDocument.Selection.Text =”// Last compiled “+strMonth+ “/”+strDay +”/”+strYear+” at “+strHour+”:”+strMinute+”:”+strSecond + vbCrLf
ActiveDocument.Selection.NewLine‘ find line with FileVersion Information:
ActiveDocument.Selection.FindText “FILEVERSION”, dsMatchForward + dsMatchFromStart + dsMatchCase‘ move to eol and then to end of build number:
ActiveDocument.Selection.EndOfLine‘ mark Build Number and store in strVersion
ActiveDocument.Selection.WordLeft 1 ‘dsExtend does not work in my VisualStudio???
Dim strVersion3
strVersion3 = ActiveDocument.Selection.Text‘ Increase Version and write back to file:
ActiveDocument.Selection.ReplaceText strVersion3 , strVersion3+1ActiveDocument.Selection.FindText “PRODUCTVERSION”, dsMatchForward + dsMatchFromStart + dsMatchCase
‘ move to eol and then to end of build number:
ActiveDocument.Selection.EndOfLine‘ mark Build Number and store in strVersion
ActiveDocument.Selection.WordLeft 1 ‘dsExtend does not work in my VisualStudio???
Dim strVersion4
strVersion4 = ActiveDocument.Selection.Text‘ Increase Version and write back to file:
ActiveDocument.Selection.ReplaceText strVersion4 , strVersion4+1ActiveDocument.Selection.FindText “VALUE “”FileVersion””,”, dsMatchForward + dsMatchFromStart + dsMatchCase
‘ move to eol and then to end of build number:
ActiveDocument.Selection.EndOfLine
ActiveDocument.Selection.CharLeft dsMove, 3‘ mark Build Number and store in strVersion
ActiveDocument.Selection.WordLeft 1 ‘dsExtend does not work in my VisualStudio???
Dim strVersion
strVersion = ActiveDocument.Selection.Text‘ Increase Version and write back to file:
ActiveDocument.Selection.ReplaceText strVersion , strVersion+1ActiveDocument.Selection.FindText “VALUE “”ProductVersion””,”, dsMatchForward + dsMatchFromStart + dsMatchCase
‘ move to eol and then to end of build number:
ActiveDocument.Selection.EndOfLine
ActiveDocument.Selection.CharLeft dsMove, 3‘ mark Build Number and store in strVersion
ActiveDocument.Selection.WordLeft 1 ‘dsExtend does not work in my VisualStudio???
Dim strVersion2
strVersion2 = ActiveDocument.Selection.Text‘ Increase Version and write back to file:
ActiveDocument.Selection.ReplaceText strVersion2 , strVersion2+1ActiveDocument.Close()
‘build active project
ExecuteCommand “BuildToggleBuild”
Documents.SaveAll TrueEnd Sub