文章編號: 810455 - 上次校閱: 2007年11月13日 - 版次: 2.8
如何將 Visual C++ 6.0 自訂 AppWizard 遷移至 Visual C++.NET 的自訂精靈
系統提示 本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。
本文將告訴您如何在 Visual C++ 6.0 中建立自訂 AppWizard,以及如何移轉至 Visual C++.NET 的精靈。
本文將逐步告訴您,如何將 Microsoft Visual C++ 6.0 自訂 AppWizard 遷移至 Microsoft Visual C++.NET 的自訂精靈。在 Visual C++.NET 的自訂精靈技術會從自訂 AppWizard 技術在 Visual C++ 6.0 中有顯著的差異。您無法連接埠直接到新的技術在 Visual C++ 6.0 中建立一個自訂 AppWizard 專案。但是,您可以重複使用現有的範本檔案並修改現有的指示詞,可在新語法。
需求下列清單列出建議的硬體、 軟體、 網路基礎結構及您需要的服務套件:
Microsoft Windows 2000 作業系統或更新版本 Microsoft Visual Studio 6.0 Microsoft Visual Studio.NET 本文假設您已熟悉下列主題:
Microsoft Visual Studio 6.0 Microsoft Visual Studio.NET Microsoft Visual C++.NET Visual C++ 6.0 自訂 AppWizard建立 Visual C++ 6.0 自訂 AppWizard 啟動 Visual C++ 6.0。 按一下 [檔案 ] 功能表 新增] 。 [新增 ] 對話方塊隨即出現。 在 [新增 ] 對話方塊按一下 [專案 ] 索引標籤。 在 [專案 ] 索引標籤上按一下 [自訂 AppWizard ]。 在 [專案名稱 ] 方塊中輸入 MyVC6Custom ,],然後再按一下 [確定] ]。自訂 AppWizard-步驟 2 之 1 ] 對話方塊隨即出現。 按一下 您自己的自訂步驟 。 在 您會想如何許多自訂步驟? 方塊、 將自訂步驟數設定成 0、 按一下 [完成] ,然後再按一下 [確定] 。 會建立名為 MyVC6Custom"的自訂 AppWizard 專案。
建立自訂的專案檔案 啟動 [記事本] 或文字編輯器應用程式。 在 [記事本] 或 [文字編輯器中,貼上下列程式碼:
#if !defined(AFX_STDAFX_H__6857DB3B_9305_41BF_BFB7_9DD42655FED5__INCLUDED_)
#define AFX_STDAFX_H__6857DB3B_9305_41BF_BFB7_9DD42655FED5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <conio.h>
#endif
將檔案儲存為 SAfx.h 在下列資料夾:Path_to_VC6_Custom _AppWizard \MyVC6Custom\Template附註 Path_to_VC6_Custom _AppWizard 是您可在此建立 MyVC6Custom 專案路徑預留位置。 在 [記事本] 或 [文字編輯器中,貼上下列程式碼: 將檔案儲存為 SAfx.cpp 在下列資料夾:Path_to_VC6_Custom _AppWizard \MyVC6Custom\Template 在 [記事本] 或 [文字編輯器中,貼上下列程式碼:
// Win32 Console Application: Defines the entry point for the console application.
#include "stdafx.h"
int main(int argc, char* argv[])
{
printf("Hello World!\n");
getch();
return 0;
} 將檔案儲存為 Root.cpp 在下列資料夾:Path_to_VC6_Custom _AppWizard \MyVC6Custom\Template 自訂專案 找出下列的程式碼的 MyVC6Custom 專案 MyVC6Customaw.cpp 檔案中: void CMyVC6CustomAppWiz::CustomizeProject(IBuildProject* pProject)
{ 將下列程式碼加入您在步驟 1 中找到程式碼之後:
CComPtr<IConfigurations> pConfigs;
HRESULT hr=pProject->get_Configurations(&pConfigs);
if(FAILED(hr))
{
AfxMessageBox("An error occurred while obtaining the IConfigurations interface pointer");
return;
}
CComPtr<IConfiguration> pConfig;
CComVariant index;
VARIANT m_var = {0};
CComBSTR Name;
CString text;
CString output;
long Count=0;
pConfigs->get_Count(&Count);
// Iterate through all the configurations of the project.
for(int i=1; i <= Count; i++)
{
index=i;
hr=pConfigs->Item(index, &pConfig);
if(FAILED(hr))
{
AfxMessageBox("An error occurred while obtaining the IConfiguration pointer");
return;
}
pConfig->get_Name(&Name);
text = Name;
if (text.Find("Debug") == -1)
output = "Release";
else
output = "Debug";
text.Format("/out:\"%s/%s.exe\"",output,m_Dictionary["Root"]);
pConfig->AddToolSettings(L"link.exe", text.AllocSysString(), m_var);
pConfig->AddToolSettings(L"mfc", L"0", m_var);
pConfig->AddToolSettings(L"link.exe", L"/subsystem:console", m_var);
pConfig->AddToolSettings(L"link.exe", L"/incremental:yes", m_var);
pConfig->AddToolSettings(L"link.exe", L"/machine:I386", m_var);
// Change the preprocessor definitions.
pConfig->AddToolSettings(L"cl.exe", L"/nologo", m_var);
pConfig->AddToolSettings(L"cl.exe", L"/MLd", m_var);
pConfig->AddToolSettings(L"cl.exe", L"/W3", m_var);
pConfig->AddToolSettings(L"cl.exe", L"/Gm", m_var);
pConfig->AddToolSettings(L"cl.exe", L"/ZI", m_var);
pConfig->AddToolSettings(L"cl.exe", L"/Od", m_var);
pConfig->AddToolSettings(L"cl.exe", L"/D \"WIN32\"", m_var);
pConfig->AddToolSettings(L"cl.exe", L"/D \"_DEBUG\"", m_var);
pConfig->AddToolSettings(L"cl.exe", L"/D \"_CONSOLE\"", m_var);
// Change the libraries.
pConfig->AddToolSettings(L"link.exe", L"kernel32.lib", m_var);
pConfig->AddToolSettings(L"link.exe", L"user32.lib", m_var);
pConfig=NULL;
}
pConfigs=NULL; 將下列程式碼加入至 MyVC6Custom 專案的 StdAfx.h 檔: #include <atlbase.h>
#include <ObjModel\bldguid.h>
#include <ObjModel\bldauto.h> 將範本檔案複製到範本目錄 在 [工作區] 視窗中按一下 FileView ] 索引標籤、 範本檔案 ,] 上按一下滑鼠右鍵,然後按一下 [新增檔案到資料夾 。 出現 [插入檔案至專案 ] 對話方塊。 在 [插入檔案至專案 ] 對話方塊找出下列資料夾:Path_to_VC6_Custom _AppWizard \MyVC6Custom\Template 將 Root.cpp 檔案、 SAfx.cpp 的檔案和 SAfx.h 檔加入至樣板檔案資料夾。 範本檔案] 資料夾中 Confirm.inf ] 上按一下滑鼠右鍵]、 按一下 [開啟舊檔 ,及再取代 [使用下列文字的 [Confirm.inf 檔案中現有的文字]: 簡單的 Win32 主控台應用程式。 列印到主控台的"Hello,全球"!。 在 範本檔案 ] 資料夾上按一下滑鼠右鍵 Newproj.inf ]、 按一下 [開啟舊檔 ,] 然後將 Newproj.inf 檔案中現有的程式碼取代下列程式碼: $$// newproj.inf = template for list of template files
$$// format is 'sourceResName' \t 'destFileName'
$$// The source res name may be preceded by any combination of '=', '-', '!', '?', ':', '#', and/or '*'.
$$// '=' => the resource is binary
$$// '-' => the file should not be added to the project (all files are added to the project by default)
$$// '!' => the file should be marked exclude from build
$$// '?' => the file should be treated as a Help file
$$// ':' => the file should be treated as a resource
$$// '#' => the file should be treated as a template (implies '!')
$$// '*' => bypass the custom AppWizard's resources when loading
$$// if name starts with / => create new subdir
+root.cpp $$Root$$.cpp
+SAfx.h StdAfx.h
+SAfx.cpp StdAfx.cpp
附註 您必須分隔檔案名稱使用 TAB 鍵。不要使用空格鍵。 在工作區按 ResourceView ] 索引標籤],展開 MyVC6Custom 資源 、 範本 ,] 上按一下滑鼠右鍵,然後再按一下 [插入 ]。 [插入資源 ] 對話方塊隨即出現。 在 [插入資源 ] 對話方塊中,按一下 [匯入 ]。匯入資源 ] 對話方塊隨即出現。 在 [檔案類型 ] 方塊按一下 所有檔案 (* *) ,然後尋找下列資料夾:Path_to_VC6_Custom _AppWizard \MyVC6Custom\Template 按一下 Root.cpp ,然後再按一下 [匯入 。 [自訂資源類型 ] 對話方塊隨即出現。 在 [自訂資源類型 ] 對話方塊按一下 範本 ,再按 [確定] 。 IDR_TEMPLATE1 範本加入至 [範本] 資料夾。 IDR_TEMPLATE1 ] 上按一下滑鼠右鍵]、 按一下 [內容 ]、 [識別碼 ] 方塊中輸入 ROOT.CPP 」 ,然後按下 ENTER]。重複步驟 11 將 SAfx.h 檔案和 SAfx.cpp 檔案加入至 [範本] 資料夾,然後分別重新命名它們的 ID 屬性 SAFX.H"和"SAFX.CPP 」。 在 [檔案 ] 功能表上按一下 [全部儲存 ]。 在 建置 ] 功能表上按一下 [全部重建 ]。 建立 MyVC6Custom AppWizard 自訂 AppWizard。MyVC6Custom AppWizard 範本會加入至 Visual C++ 專案] 索引標籤。
Visual C++.NET 的自訂精靈建立 Visual C++.NET 的自訂精靈 啟動 Visual Studio.NET。 在 [檔案 ] 功能表上指向 [新增] ,然後按一下 [專案 ]。 出現 [新增專案 ] 對話方塊。 在 [專案類型 下, 按一下 [Visual C++ 專案 ]。 在 [範本 下, 按一下 [自訂精靈 ]。 在 [名稱 ] 方塊中輸入 MyVC7Custom ,],然後再按一下 [確定] ]。自訂精靈-MyVC7Custom ] 對話方塊隨即出現。 在 自訂精靈-MyVC7Custom ] 對話方塊按一下 [應用程式設定 ,按一下以清除 [使用者介面 ] 核取方塊然後再按一下 [完成] 。 將範本檔案複製到範本目錄 在 [方案總管] 中展開 [所有資料夾]。 ReadMe.txt ,] 上按一下滑鼠右鍵,然後按一下 [移除 ]。移動至下列資料夾:Path_to_VC6_Custom _AppWizard \MyVC6Custom\Templates 將 Root.cpp 檔案、 SAfx.cpp 的檔案和 SAfx.h 檔複製到 Path_to_VC7_Custom _Wizard \MyVC7Custom\Templates\1041 資料夾附註 Path_to_VC7_Custom _Wizard 是建立 MyVC7Custom 精靈的位置路徑的預留位置。 重新 SAfx.cpp 檔案命名到 StdAfx.cpp,並 SAfx.h 檔案重新命名為 StdAfx.h。 範本檔案 上按一下滑鼠右鍵、 指向 [新增 ],然後按一下 [現有項目 。 出現 [加入現有項目-MyVC7Custom ] 對話方塊。 在 [加入現有項目-MyVC7Custom ] 對話方塊找出下列資料夾:Path_to_VC7_Custom _Wizard \MyVC7Custom\Templates\1041附註 Path_to_VC7_Custom _Wizard 是建立 MyVC7Custom 精靈的位置路徑的預留位置。 將 Root.cpp 檔案、 StdAfx.cpp 的檔案和 StdAfx.h 檔加入至 [範本] 資料夾。 自訂專案 在 [方案總管] 中 Templates.inf ,] 上按一下滑鼠右鍵,然後按一下 [開啟舊檔 ]。 下列程式碼以取代現有的程式碼:root.cpp
StdAfx.cpp
StdAfx.h 在 [方案總管] 中 default.js ,] 上按一下滑鼠右鍵,然後按一下 [開啟舊檔 ]。 Default.js 檔案中找出下列的程式碼: function AddFilters(proj)
{ 取代現有的程式碼,您在步驟 4 以下列程式碼中找到 AddFilters 函式中: try
{
// Add the folders to your project.
var strSrcFilter1 = wizard.FindSymbol('SOURCE_FILTER');
var strSrcFilter2 = wizard.FindSymbol('HEADER_FILTER');
var strSrcFilter3 = wizard.FindSymbol('RESOURCE_FILTER');
var group1 = proj.Object.AddFilter('Source Files');
var group2 = proj.Object.AddFilter('Header Files');
var group3 = proj.Object.AddFilter('Resource Files');
group1.Filter = strSrcFilter1;
group2.Filter = strSrcFilter2;
group3.Filter = strSrcFilter3;
}
catch(e)
{
throw e;
} 的 AddFilters 函式指定專案的來源篩選器。 在 Default.js 檔案中找到下列的程式碼:function AddConfig(proj, strProjectName)
{ 取代現有的程式碼,您在步驟 6 以下列程式碼中找到 AddConfig 函式中:try
{
var config = proj.Object.Configurations('Debug');
config.IntermediateDirectory = 'Debug';
config.OutputDirectory = 'Debug';
var CLTool = config.Tools('VCCLCompilerTool');
CLTool.DebugInformationFormat = debugEnabled;
CLTool.SuppressStartupBanner=true;
CLTool.RuntimeLibrary=runtimeLibraryOption.rtMultiThreadedDebugDLL;
CLTool.WarningLevel=warningLevelOption.warningLevel_3;
CLTool.Optimization=optimizeOption.optimizeDisabled;
CLTool.MinimalRebuild=true;
CLTool.DebugInformationFormat=debugOption.debugEditAndContinue;
var LinkTool = config.Tools('VCLinkerTool');
LinkTool.ProgramDatabaseFile = "$(outdir)/" + strProjectName + ".pdb";
LinkTool.GenerateDebugInformation = true;
LinkTool.LinkIncremental = linkIncrementalYes;
LinkTool.OutputFile = "$(outdir)/" + strProjectName + ".exe";
LinkTool.SuppressStartupBanner=true; // nologo
LinkTool.AdditionalDependencies="user32.lib";
LinkTool.AdditionalDependencies="kernel32.lib";
config = proj.Object.Configurations('Release');
config.IntermediateDirectory = 'Release';
config.OutputDirectory = 'Release';
var CLTool = config.Tools('VCCLCompilerTool');
// TODO: Add compiler settings.
var LinkTool = config.Tools('VCLinkerTool');
// TODO: Add linker settings.
}
catch(e)
{
throw e;
} AddConfig 函數將新增專案組態。您可以提供編譯器和連結器設定。 Default.js 檔案中找出下列的程式碼: function GetTargetName(strName, strProjectName)
{ 取代現有的程式碼,您在步驟 8 以下列程式碼中找到 GetTargetName 函式中: try
{
var strTarget = strName;
if(strName == 'stdafx.h')
strTarget = 'StdAfx.h';
if(strName == 'stdafx.cpp')
strTarget = 'StdAfx.cpp';
if(strName == 'root.cpp')
strTarget = strProjectName + ".cpp";
return strTarget;
}
catch(e)
{
throw e;
} 的 GetTargetName 函式取得指定的檔案名稱。 在 [方案總管] 中 MyVC7Custom.vsz ,] 上按一下滑鼠右鍵,然後按一下 [開啟舊檔 ]。 在 MyVC7Custom.vsz 檔案中找到下列的程式碼:Param="SOURCE_FILTER = txt" 取代您在步驟 11 以下列程式碼中找到的程式碼: Param="SOURCE_FILTER = cpp"
Param="HEADER_FILTER = h"
Param="RESOURCE_FILTER = txt" 在 [檔案 ] 功能表上按一下 [全部儲存 ]。 找出下列資料夾:Path_to_VC7_Custom _Wizard \MyVC7Custom 到下列位置中複製 MyVC7Custom.ico 檔案]、 [MyVC7Custom.vsz 的檔案] 和 [MyVC7Custom.vsdir 檔案:Hard disk drive \Microsoft Visual Studio.NET 2003\Vc7\vcprojects 資料夾。Hard disk drive 為安裝 Visual Studio.NET 2003年磁碟機的預留位置。附註 如果您在 Microsoft Visual Studio.NET 2002年中建立自訂精靈,請至下列位置複製 MyVC7Custom.ico 檔案]、 [MyVC7Custom.vsz 的檔案] 和 [MyVC7Custom.vsdir 檔案:Hard disk drive \Microsoft Visual Studio.NET\Vc7\vcprojects 資料夾。Hard disk drive 為安裝 Visual Studio.NET 2002年磁碟機的預留位置。 建立 MyVC7Custom 自訂精靈的範本。您可以使用範本建立簡單的 Win32 主控台應用程式。
其他相關資訊 [VSZ 檔案 在 Visual Studio.NET 中每個精靈的起點是.vsz 檔案。此.vsz 檔案是文字檔來決定命名的精靈,以及何種資訊傳遞給精靈。檔案包含雙行標頭後面跟著選擇性的參數傳遞給精靈。
[VSDir 檔案 VSDir 檔案是以副檔名為.vsdir 的文字檔。檔案提供有關如何顯示檔案中包含的項目
加入項目 ] 對話方塊和 [
新增專案 ] 對話方塊的資訊。這些項目包含它們的名稱、 它們出現的順序與一起顯示的圖示。 一個 VSDir 檔案包含多個精靈、 資料夾及範本記錄。以新行字元分隔檔案中的每一筆記錄。管道 (|) 字元分隔每一筆記錄中的欄位。
[JScript 檔案 每個自訂的精靈會建立名 Default.js 為每個專案的 JScript 檔案。這個檔案包含函式,您可以用來自訂您的專案。您也可以到 Default.js 檔案新增自己的函式,為您的專案。
[Templates.inf 檔案 Templates.inf 檔案是文字檔,其中包含您專案的範本清單。您可以使用 Templates.inf 檔案中的範本指示詞,以自訂您的專案。當您使用範本指示詞時,請記住下列資訊:
您不能使用巢狀的 [! 如果] 指示詞中一個 [! 迴圈] 指示詞。 您可以使用巢狀一個 [! 迴圈] 在另一個指示詞 [! 迴圈] 指示詞或在 [! 如果] / [! 其他] 指示詞。 有沒有 [! elif] 指示詞。您不能使用巢狀 [! 如果] 中的指示詞 [! 如果] / [! 其他] 指示詞。因此為 $ $ ELIF 指示詞必須複製邏輯。例如下列程式碼是使用 Visual C++ 6.0 範本指示詞來建立一個 IF 其他迴圈的範例:$$IF (macro1) // Some code 1 $$ELIF (macro2) // Some code 2 $$ENDIF 這個程式碼可以轉換成下列程式碼,根據以 Visual C++.NET 範本指示詞:[!if macro1] // Some code 1 [!endif] [!if !macro1 and macro2] // Some code 2 [!endif] 您可以使用下列的範例來指定註解:[!if 0] This is a comment. [!endif] 如需詳細資訊請造訪下列 Microsoft 開發 o 人 h 員 ? 工 u 具 ? 網路 (MSDN) 網站]:
這篇文章中的資訊適用於: Microsoft Visual Studio .NET 2003 專業版 Microsoft Visual Studio .NET 2003 Enterprise Architect Microsoft Visual Studio .NET 2003 Enterprise Developer Microsoft Visual Studio .NET 2003 Academic Edition Microsoft Visual Studio .NET 2002 Professional Edition Microsoft Visual Studio .NET 2002 Enterprise Architect Microsoft Visual Studio .NET 2002 Enterprise Developer Microsoft Visual Studio .NET 2002 Academic Edition kbmt kbhowtomaster kbwizard kbideproject kbide kbcustomwizard kbappwizard kbmigrate kbenv kbcodegen kbhowto KB810455 KbMtzh
機器翻譯 重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:
810455 ?
(http://support.microsoft.com/kb/810455/en-us/
)
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。
請說明您希望我們對本篇文章進行什麼改善及需要改善的原因
謝謝您!您的意見將協助我們改進支援內容。如需更多協助選項,請造訪
說明及支援首頁 。