各位大侠,我想让我的程序每编译一次,版本号就自动增加1。如何在VC中实现?

解决方案 »

  1.   

    当前位置:网易精华区>>讨论区精华>>编程开发>>C/C++>>编辑、编译、调试与发行>>Macro to set version info(VC6)  主题:Macro to set version info(VC6) 
    发信人: jiangsheng()
    整理人: wenbobo(2002-12-27 15:59:45), 站内信件  
    I have tens of projects in my workspace. It is so boring to update ver
    sion info(mainly,the version number) and I wrote this macro to replace
     version info for every project. 
    Usage: 
    Input version information,include following: 
    1.company name. 
    2.Trade. 
    3.Copyright. 
    4.File Version. 
    5.Product Version. 
    Note:if you input an empty string,then no changes are made on correspo
    nd version information. 
    The macro will prompt you if you want the changes applies to all proje
    ct. If you select NO, the macro will prompt for every project just bef
    ore apply changes.You can stop the macro by clicking "Cancel". 
    Note: hide wizard bar to skip reloading RC file for better performance

    Sub SetProjectVersionInfo() 
    'DESCRIPTION: Set version information in rc script for one or more pro
    ject(s) in current workspace .Company Name,Trade,LegalCopyright,an
    d version number.If some information is empty, then no changes are mad
    e on correspond version information. 
    'Created by Jiang Sheng at 2000-6-21 16:48 
    DIM strCompanyName 
    DIM strTrade 
    DIM strLegalCopyright 
    DIM strFileVersion 
    DIM strProductVersion 
    DIM bAllProject 
    DIM bApply 
    DIM nResult 
    bAllProject=1 
    Dim oneProject 
    if Application.Projects.Count =0 then 
    MsgBox("No project available.") 
    Exit Sub 
    end if 
    strCompanyName= InputBox ("Please input company name:"& Chr(13) & Chr
    (10)&"Empty means no changes.","Input Company Name") 
    strTrade= InputBox ("Please input legal trades:"& Chr(13) & C
    hr(10)&"Empty means no changes.","Input Legal Trades") 
    strLegalCopyright= InputBox ("Please input legal copyright:"& Chr(13)
     & Chr(10)&"Empty means no changes.","Input Legal Copyright") 
    strFileVersion= InputBox ("Please input file version:"& Chr(13) & Chr
    (10)&"Empty means no changes."& Chr(13) & Chr(10)& "Version must in x,
    x,x,x format.","Input File Version") 
    strProductVersion= InputBox ("Please input product version:"& Chr(13)
     & Chr(10)&"Empty means no changes."& Chr(13) & Chr(10)& "Version must
     in x,x,x,x format.","Input Product Version") nResult=MsgBox("Apply changes for all projects?",VbYesNoCancel) 
    SELECT CASE nResult 
    case vbYes 
    bAllProject=1 
    case vbNo 
    bAllProject=0 
    case vbCancel 
    Exit Sub 
    End SELECT  
    For Each oneProject in Application.Projects 
    if bAllProject=0 then  
    nResult=MsgBox("Apply changes for project "+oneProject.Name+"?",VbY
    esNo) 
    else 
    bApply=1 
    end if 
    SELECT CASE nResult 
    case vbYes 
    bApply=1 
    case vbNo 
    bApply=0 
    case vbCancel 
    Exit Sub 
    End SELECT  
    if bApply then 
    set ActiveProject=Projects(oneProject.Name) 
    Dim strTemp 
    Dim documentObject 
    ' open the project's resource script: strTemp = ActiveProject.FullName 
    Wnd = Left(strTemp, Len(strTemp) - 3) + "rc" Documents.Open (Wnd), "Text" 
    For Each documentObject in Application.Documents 
    if documentObject.FullName = Wnd then  
    documentObject.Active = True 
    exit for 
    end if  
    Next   ' SAVE BACK-UP OF FILE >>>> 
    ActiveDocument.Save (Wnd+"~") ActiveDocument.Close()  
    Documents.Open Wnd, "Text" 
    if strCompanyName<>"" then  
    ActiveDocument.Selection.FindText "VALUE ""CompanyName"", """, dsM
    atchForward + dsMatchFromStart + dsMatchCase 
    ActiveDocument.Selection.CharRight 
    ActiveDocument.Selection.EndOfLine dsExtend 
    ActiveDocument.Selection.CharLeft dsExtend, 3  
    ActiveDocument.Selection.Text=strCompanyName 
    end if 
    if strTrade<>"" then  
    ActiveDocument.Selection.FindText "VALUE ""LegalTrades"", """,
     dsMatchForward + dsMatchFromStart + dsMatchCase 
    ActiveDocument.Selection.CharRight 
    ActiveDocument.Selection.EndOfLine dsExtend 
    ActiveDocument.Selection.CharLeft dsExtend, 3  
    ActiveDocument.Selection.Text=strTrade 
    end if 
    if strLegalCopyright<>"" then  
    ActiveDocument.Selection.FindText "VALUE ""LegalCopyright"", """, 
    dsMatchForward + dsMatchFromStart + dsMatchCase 
    ActiveDocument.Selection.CharRight 
    ActiveDocument.Selection.EndOfLine dsExtend 
    ActiveDocument.Selection.CharLeft dsExtend, 3  
    ActiveDocument.Selection.Text=strLegalCopyright 
    end if 
    if strFileVersion<>"" then  
    ActiveDocument.Selection.FindText "FILEVERSION", dsMatchForward + 
    dsMatchFromStart + dsMatchCase + dsMatchWord 
    ActiveDocument.Selection.WordRight 
    ActiveDocument.Selection.EndOfLine dsExtend 
    ActiveDocument.Selection.Text=strFileVersion ActiveDocument.Selection.FindText "VALUE ""FileVersion"",", dsMatc
    hForward + dsMatchFromStart + dsMatchCase   
    ActiveDocument.Selection.WordRight dsMove,2 
    ActiveDocument.Selection.EndOfLine dsExtend 
    ActiveDocument.Selection.CharLeft dsExtend, 3  
    ActiveDocument.Selection.Text=strFileVersion 
    end if if strProductVersion<>"" then  
    ActiveDocument.Selection.FindText "PRODUCTVERSION", dsMatchForward
     + dsMatchFromStart + dsMatchCase + dsMatchWord 
    ActiveDocument.Selection.WordRight 
    ActiveDocument.Selection.EndOfLine dsExtend 
    ActiveDocument.Selection.Text=strFileVersion 
    ActiveDocument.Selection.FindText "VALUE ""ProductVersion"",", dsM
    atchForward + dsMatchFromStart + dsMatchCase   
    ActiveDocument.Selection.WordRight dsMove,2 
    ActiveDocument.Selection.EndOfLine dsExtend 
    ActiveDocument.Selection.CharLeft dsExtend, 3  
    ActiveDocument.Selection.Text=strProductVersion 
    end if 
    ActiveDocument.Save() 
    ActiveDocument.Close()  
    End if 
    Next 
    End Sub --
    HE WHO CONTROLS THE PAST, COMMANDS THE FUTURE. 
    HE WHO CONTROLS THE FUTURE CONQUERS THE PAST.※ 来源:.网易虚拟社区 http://club.netease.com.[FROM: 202.96.44.196]