向VS2015添加WTL项目向导(ATL/WTL Application Wizard)

刚装了个VS2015社区版,微软地球良心企业啊~~Embarcader能学点不?

VS装得再高端我也只会用个WTL,到目前为止(2015/08/09)WTL官网上还是只有WTL9.0版,最高支持到VS2013。

打开WTL里的AppWiz\Setup.js,经试验只要在里面的几个数组里加入2015(14.0)相关的字符串,再执行一次Setup.js就可以了。

附修改过的Setup.js

// Windows Template Library - WTL version 9.0
// Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
//
// This file is a part of the Windows Template Library.
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license. You must not remove this notice, or
// any other, from this software.

// WTL App Wizard universal setup program for Visual Studio

main();

function main()
{
	// Decode command line arguments
	var bDebug = false;
	var bElevated = false;
	var Args = WScript.Arguments;
	for(var i = 0; i < Args.length; i++)
	{
		if(Args(i) == "/debug")
			bDebug = true;
		else if(Args(i) == "/elevated")
			bElevated = true;
	}

	// See if UAC is enabled
	var Shell = WScript.CreateObject("Shell.Application");
	if(!bElevated && Shell.IsRestricted("System", "EnableLUA"))
	{
		// Check that the script is being run interactively.
		if(!WScript.Interactive)
		{
			WScript.Echo("ERROR: Elevation required.");
			return;
		}

		// Now relaunch the script, using the "RunAs" verb to elevate
		var strParams = "\"" + WScript.ScriptFullName + "\"";
		if (bDebug)
			strParams += " /debug";
		strParams += " /elevated";
		Shell.ShellExecute(WScript.FullName, strParams, null, "RunAs");
		return;
	}

	// Create shell object
	var WSShell = WScript.CreateObject("WScript.Shell");
	// Create file system object
	var FileSys = WScript.CreateObject("Scripting.FileSystemObject");

	// Get the folder containing the script file
	var strValue = FileSys.GetParentFolderName(WScript.ScriptFullName);
	if(strValue == null || strValue == "")
		strValue = ".";

	var strSourceFolder = FileSys.BuildPath(strValue, "Files");
	if(bDebug)
		WScript.Echo("Source: " + strSourceFolder);

	if(!FileSys.FolderExists(strSourceFolder))
	{
		WScript.Echo("ERROR: Cannot find Wizard folder (should be: " + strSourceFolder + ")");
		return;
	}

	MessageBox(WSShell, "Setup will search for installed versions of Visual Studio,\nand ask to add the WTL App Wizard for each of them.");

	var strRegKey_32 = "HKLM\\Software\\";
	var strRegKey_64 = "HKLM\\Software\\Wow6432Node\\";

	var nVersions = 12;

	var astrRegKeyVer = new Array();
	astrRegKeyVer[0] = "Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[1] = "Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir";
	astrRegKeyVer[2] = "Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[3] = "Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[4] = "Microsoft\\VisualStudio\\10.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[5] = "Microsoft\\VisualStudio\\11.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[6] = "Microsoft\\VisualStudio\\12.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[7] = "Microsoft\\VisualStudio\\14.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[8] = "Microsoft\\VCExpress\\8.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[9] = "Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[10] = "Microsoft\\VCExpress\\10.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[11] = "Microsoft\\VCExpress\\11.0\\Setup\\VC\\ProductDir";
	astrRegKeyVer[12] = "Microsoft\\VCExpress\\12.0\\Setup\\VC\\ProductDir";

	var astrFolder = new Array();
	astrFolder[0] = "vcprojects";
	astrFolder[1] = "vcprojects";
	astrFolder[2] = "vcprojects";
	astrFolder[3] = "vcprojects";
	astrFolder[4] = "vcprojects";
	astrFolder[5] = "vcprojects";
	astrFolder[6] = "vcprojects";
	astrFolder[7] = "vcprojects";
	astrFolder[8] = "Express\\vcprojects";
	astrFolder[9] = "Express\\vcprojects";
	astrFolder[10] = "Express\\vcprojects";
	astrFolder[11] = "vcprojects_WDExpress";
	astrFolder[12] = "vcprojects_WDExpress";

	var astrVersions = new Array();
	astrVersions[0] = "Visual Studio 2002 (7.0)";
	astrVersions[1] = "Visual Studio 2003 (7.1)";
	astrVersions[2] = "Visual Studio 2005 (8.0)";
	astrVersions[3] = "Visual Studio 2008 (9.0)";
	astrVersions[4] = "Visual Studio 2010 (10.0)";
	astrVersions[5] = "Visual Studio 2012 (11.0)";
	astrVersions[6] = "Visual Studio 2013 (12.0)";
	astrVersions[7] = "Visual Studio 2015 (14.0)";
	astrVersions[8] = "Visual Studio 2005 Express (8.0)";
	astrVersions[9] = "Visual Studio 2008 Express (9.0)";
	astrVersions[10] = "Visual Studio 2010 Express (10.0)";
	astrVersions[11] = "Visual Studio 2012 Express (11.0)";
	astrVersions[12] = "Visual Studio 2013 Express (12.0)";

	var abExpress = new Array();
	abExpress[0] = false;
	abExpress[1] = false;
	abExpress[2] = false;
	abExpress[3] = false;
	abExpress[4] = false;
	abExpress[5] = false;
	abExpress[6] = false;
	abExpress[7] = false;
	abExpress[8] = true;
	abExpress[9] = true;
	abExpress[10] = true;
	abExpress[11] = true;
	abExpress[12] = true;

	var astrWizVer = new Array();
	astrWizVer[0] = "7.0";
	astrWizVer[1] = "7.1";
	astrWizVer[2] = "8.0";
	astrWizVer[3] = "9.0";
	astrWizVer[4] = "10.0";
	astrWizVer[5] = "11.0";
	astrWizVer[6] = "12.0";
	astrWizVer[7] = "14.0";
	astrWizVer[8] = "8.0";
	astrWizVer[9] = "9.0";
	astrWizVer[10] = "10.0";
	astrWizVer[11] = "11.0";
	astrWizVer[12] = "12.0";

	var nSpecial = 4;

	var nWizSpecial = 0;

	var bFound = false;
	for(var i = 0; i < nVersions; i++)
	{
		if(bDebug)
			WScript.Echo("Looking for: " + astrVersions[i]);

		try
		{
			var strVCKey = strRegKey_32 + astrRegKeyVer[i];
			strValue = WSShell.RegRead(strVCKey);
		}
		catch(e)
		{
			try
			{
				var strVCKey_x64 = strRegKey_64 + astrRegKeyVer[i];
				strValue = WSShell.RegRead(strVCKey_x64);
			}
			catch(e)
			{
				continue;
			}
		}

		var strDestFolder = FileSys.BuildPath(strValue, astrFolder[i]);
		if(bDebug)
			WScript.Echo("Destination: " + strDestFolder);
		if(!FileSys.FolderExists(strDestFolder))
			continue;

		if(i == nSpecial)   // special case for VS2010
		{
			var strCheckFile = FileSys.BuildPath(strDestFolder, "vc.vsdir");
			if(!FileSys.FileExists(strCheckFile))
				continue;
		}

		bFound = true;
		var strMsg = "Found: " + astrVersions[i] + "\n\nInstall WTL App Wizard?";
		var bRet = MessageBox(WSShell, strMsg, true);
		if(bRet)
		{
			var bWizSpecial = (i == nWizSpecial);   // special case for VS2002
			SetupWizard(WSShell, FileSys, strSourceFolder, strDestFolder, astrWizVer[i], bWizSpecial, abExpress[i], bDebug);
		}
	}

	if(bFound)
		MessageBox(WSShell, "Done!");
	else
		MessageBox(WSShell, "Setup could not find Visual Studio installed");
}

function MessageBox(WSShell, strText, bYesNo)
{
	var nType = bYesNo ? (4 + 32) : 0;   // 4 = Yes/No buttons, 32 = Questionmark icon, 0 = OK button
	var nRetBtn = WSShell.Popup(strText, 0, "WTL App Wizard Setup", nType);
	return (nRetBtn == 6);   // 6 = Yes;
}

function SetupWizard(WSShell, FileSys, strSourceFolder, strDestFolder, strWizVer, bWizSpecial, bExpress, bDebug)
{
	// Copy files
	try
	{
		var strSrc = FileSys.BuildPath(strSourceFolder, "WTLAppWiz.ico");
		var strDest = FileSys.BuildPath(strDestFolder, "WTLAppWiz.ico");
		FileSys.CopyFile(strSrc, strDest);

		strSrc = FileSys.BuildPath(strSourceFolder, "WTLAppWiz.vsdir");
		strDest = FileSys.BuildPath(strDestFolder, "WTLAppWiz.vsdir");
		FileSys.CopyFile(strSrc, strDest);
	}
	catch(e)
	{
		var strError = "no info";
		if(e.description.length != 0)
			strError = e.description;
		WScript.Echo("ERROR: Cannot copy file (" + strError + ")");
		return;
	}

	// Read and write WTLAppWiz.vsz, add engine version and replace path when found
	try
	{
		var strSrc = FileSys.BuildPath(strSourceFolder, "WTLAppWiz.vsz");
		var strDest = FileSys.BuildPath(strDestFolder, "WTLAppWiz.vsz");

		var ForReading = 1;
		var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
		if(fileSrc == null)
		{
			WScript.Echo("ERROR: Cannot open source file " + strSrc);
			return;
		}

		var ForWriting = 2;
		var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
		if(fileDest == null)
		{
			WScript.Echo("ERROR: Cannot open destination file" + strDest);
			return;
		}

		while(!fileSrc.AtEndOfStream)
		{
			var strLine = fileSrc.ReadLine();
			if(!bWizSpecial && (strLine.indexOf("Wizard=VsWizard.VsWizardEngine") != -1))
				strLine += "." + strWizVer;
			else if(strLine.indexOf("WIZARD_VERSION") != -1)
				strLine = "Param=\"WIZARD_VERSION = " + strWizVer + "\"";
			else if(strLine.indexOf("ABSOLUTE_PATH") != -1)
				strLine = "Param=\"ABSOLUTE_PATH = " + strSourceFolder + "\"";
			fileDest.WriteLine(strLine);
		}

		if(bExpress)
			fileDest.WriteLine("Param=\"VC_EXPRESS = 1\"");

		fileSrc.Close();
		fileDest.Close();
	}
	catch(e)
	{
		var strError = "no info";
		if(e.description.length != 0)
			strError = e.description;
		WScript.Echo("ERROR: Cannot read and write WTLAppWiz.vsz (" + strError + ")");
		return;
	}

	// Create WTL folder
	var strDestWTLFolder = "";
	try
	{
		strDestWTLFolder = FileSys.BuildPath(strDestFolder, "WTL");
		if(!FileSys.FolderExists(strDestWTLFolder))
			FileSys.CreateFolder(strDestWTLFolder);
		if(bDebug)
			WScript.Echo("WTL Folder: " + strDestWTLFolder);
	}
	catch(e)
	{
		var strError = "no info";
		if(e.description.length != 0)
			strError = e.description;
		WScript.Echo("ERROR: Cannot create WTL folder (" + strError + ")");
		return;
	}

	// Read and write additional WTLAppWiz.vsdir, add path to the wizard location
	try
	{
		var strSrc = FileSys.BuildPath(strSourceFolder, "WTLAppWiz.vsdir");
		var strDest = FileSys.BuildPath(strDestWTLFolder, "WTLAppWiz.vsdir");

		var ForReading = 1;
		var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
		if(fileSrc == null)
		{
			WScript.Echo("ERROR: Cannot open source file " + strSrc);
			return;
		}

		var ForWriting = 2;
		var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
		if(fileDest == null)
		{
			WScript.Echo("ERROR: Cannot open destination file" + strDest);
			return;
		}

		while(!fileSrc.AtEndOfStream)
		{
			var strLine = fileSrc.ReadLine();
			if(strLine.indexOf("WTLAppWiz.vsz|") != -1)
				strLine = "..\\" + strLine;
			fileDest.WriteLine(strLine);
		}

		fileSrc.Close();
		fileDest.Close();
	}
	catch(e)
	{
		var strError = "no info";
		if(e.description.length != 0)
			strError = e.description;
		WScript.Echo("ERROR: Cannot read and write WTL\\WTLAppWiz.vsdir (" + strError + ")");
		return;
	}

	WScript.Echo("App Wizard successfully installed!");
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-06 09:53:08

向VS2015添加WTL项目向导(ATL/WTL Application Wizard)的相关文章

将WTL应用向导添加到VS2019

WTL 简介 WTL 全称是 Windows Template Library,像 MFC 一样使用 C++ 的面向对象技术对 Win32 接口进行了封装,使之便于开发 Windows 程序.相对于 MFC 这个庞然大物,WTL 保持了小而美,只包含了界面开发相关的特性. 下载 WTL 首先下载最新版本的 WTL,下载地址(https://sourceforge.net/projects/wtl/files/WTL%2010/).下载后将其解压,包含文件如下:AppWizard:包含了应用向导相

详解WTL应用向导

之前向 VS2019 中添加了 WTL 应用向导,今天来分析下该应用向导安装的相关文件,最终达到拷贝相关文件到 VS2019 的相应目录中即可直接使用 WTL 应用向导的目的. 在 VS2017 之前的版本中,应用向导安装的目录是 VStudio 安装目录下的 VC\vcprojects 目录,在 VS2017 及 VS2019 中,应用向导安装的目录是 VStudio 安装目录下的 Common7\IDE\VC\vcprojects 目录. 应用向导 下载 WTL 并解压,与向导有关的文件存储

[ATL/WTL]_[中级]_[保存CBitmap到文件-保存屏幕内容到文件]

场景: 1. 在做图片处理时,比方放大后或加特效后须要保存CBitmap(HBITMAP)到文件. 2.截取屏幕内容到文件时. 3.不须要增加第3方库时. 说明: 这段代码部分来自网上.第一次学atl/wtl.gdi不是非常熟悉.以后转换为wtl版本号吧. 当然wtl项目直接用也没问题. 如今想想wxWidgets的wxImage类对这类操作方便多了.仅仅须要调用一个SaveFile方法. 保存HBITMAP到文件: static bool SaveBitmapToFile(CBitmap& b

[ATL/WTL]_[保存CBitmap到文件-保存屏幕内容到文件]

场景: 1. 在做图片处理时,比如放大后或加特效后需要保存CBitmap(HBITMAP)到文件. 2.截取屏幕内容到文件时. 3.不需要加入第3方库时. 说明: 这段代码部分来自网上,第一次学atl/wtl,gdi不是很熟悉,以后转换为wtl版本吧.当然wtl项目直接用也没问题. 现在想想wxWidgets的wxImage类对这类操作方便多了.只需要调用一个SaveFile方法. 保存HBITMAP到文件: static bool SaveBitmapToFile(CBitmap& bitma

创建有个性的对话框之ATL/WTL篇

前记    这几个嵌入类其实很早之间就完成了,2003年的时候我在CodeProject上发布了这些代码,不过当时使用了紫色作为按钮的边框,导致几个无聊的LY在哪里争吵关于Gays的问题,呵呵,看来不仅语言要接轨,颜色的认识也要和西方接轨哟.现在刚好趁这个机会整理一下代码,写篇文章纪念之. 本文的目的是使用ATL/WTL做一个与“创建有个性的对话框之MFC篇”的个性对话框一样的对话框.ATL/WTL一套模板库,创建ATL/WTL应用程序不可避免的要用到C++的模板与多继承方面的知识,在看本文之前

[ATL/WTL]_[中级]_[原生的复选框(checkbox button)和单选按钮(radio button)实现透明背景效果解决方案]

场景: 1. mfc,wtl的原生控件都是通过父窗口拦截 WM_CTLCOLORSTATIC 事件来修改子控件的颜色和背景色,CStatic可以通过返回HOLLOW_BRUSH来绘制透明背景: m_HollowBrush = AtlGetStockBrush(HOLLOW_BRUSH); 但是如果使用manifest文件使用最新 外观样式的话,返回HOLLOW_BRUSH对checkbox和radio button没有任何效果,原背景还是存在.虽然通过自绘一个checkbox和radio but

【C/C++】STL,ATL,WTL之间的联系和区别

STL即 Standard Template Library (标准模板库) STL是惠普实验室开发的一系列软件的统称.它是由Alexander Stepanov.Meng Lee和David R Musser在惠普实验室工作时所开发出来的.现在虽说它主要出现在C++中,但在被引入C++之前该技术就已经存在了很长的一段时间.STL的代码从广义上讲分为三类:algorithm(算法).container(容器)和iterator(迭代器),几乎所有的代码都采用了模板类和模版函数的方式,这相比于传统

VS2015 新Web项目(C#6)出现CS1617异常的解决

VS2015 新Web项目(C#6)出现CS1617错误的解决 VS2015新增了对C#6的支持. 在新的Web项目模板中通过引入nuget包Microsoft.CodeDom.Providers.DotNetCompilerPlatform:1.0.0并在web.config中添加 <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs"

java添加菜单项目

java添加菜单项目,布布扣,bubuko.com