适用于Visual Studio 2008下的WTL setup.js文件和用法
国内非常流行的千千静听播放器的UI部分是用WTL做的,WTL做的界面效率比较高而且资源占用比较少。
作者原话:
问:千千静听是用什么语言写的,为什么支持这么多的格式还这么小巧?
千千静听是用VC6编写的,如果你还知道WTL,那么作者可以告诉你,界面是用WTL来编
写的,相对于MFC的庸肿,WTL更适合编写快速、精简并且占用资源少的程序。当然很多音频
编码库是用C语言来写的,这样更加高效而且小巧。
how to use it in visual studio 2008
1. wtl 8.0 doesn't support visual studio 2008;
2. if you download wtl 8.0, copy and save the code below as setup90.js
// Windows Template Library - WTL version 8.0
// Copyright (C) Microsoft Corporation. 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/osi3.0/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.
// Setup program for the WTL App Wizard for VC++ 9.0 (Orcas)
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;
}
try
{
var strVC9Key = "HKLM\\Software\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir";
strValue = WSShell.RegRead(strVC9Key);
}
catch(e)
{
try
{
var strVC9Key_x64 = "HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir";
strValue = WSShell.RegRead(strVC9Key_x64);
}
catch(e)
{
WScript.Echo("ERROR: Cannot find where Visual Studio 9.0 is installed.");
return;
}
}
var strDestFolder = FileSys.BuildPath(strValue, "vcprojects");
if(bDebug)
WScript.Echo("Destination: " + strDestFolder);
if(!FileSys.FolderExists(strDestFolder))
{
WScript.Echo("ERROR: Cannot find destination folder (should be: " + strDestFolder + ")");
return;
}
// 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(strLine.indexOf("Wizard=VsWizard.VsWizardEngine") != -1)
strLine += ".9.0";
else if(strLine.indexOf("WIZARD_VERSION") != -1)
strLine = "Param=\"WIZARD_VERSION = 9.0\"";
else if(strLine.indexOf("ABSOLUTE_PATH") != -1)
strLine = "Param=\"ABSOLUTE_PATH = " + strSourceFolder + "\"";
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 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!");
}
3. remember to copy the wtl include folder to the visual studio include folder and put its directory to the VS project include directory.
i.e.
C:\Program Files\Microsoft Visual Studio 9.0\VC\wtl8\Include