论坛风格切换切换到宽版
  • 1816阅读
  • 3回复

老虎版主,您这个脚本可以修正下么 [复制链接]

上一主题 下一主题
离线546242502
 

发帖
332
金钱
-3060
威望
-306
只看楼主 倒序阅读 0 发表于: 2015-08-14
用户被禁言,该主题自动屏蔽!
离线gnatix

发帖
7696
金钱
-8279
威望
-828
只看该作者 1 发表于: 2015-08-15
新的 INNO 已经有这个标准函数了。

Pascal Scripting: GetSaveFileName
Prototype:
function GetSaveFileName(const Prompt: String; var FileName: String; const InitialDirectory, Filter, DefaultExtension: String): Boolean;

Description:
Displays a dialog box that enables the user to select a new file. Returns True if the user selected a file, False otherwise. The name of the selected file is returned in the FileName string.

Remarks:
An example Filter: 'Text files (*.txt)|*.txt|All files (*.*)|*.*'

Example:
var
  Filename: String;
begin
  // Set the initial filename
  Filename := '';
  if GetSaveFileName('', Filename, '',
     'Text Documents (*.txt)|*.txt|All Files|*.*', 'txt') then
  begin
    // Successful; user clicked OK
    // Filename contains the selected filename
  end;
end;
离线gnatix

发帖
7696
金钱
-8279
威望
-828
只看该作者 2 发表于: 2015-08-15
不过我那个代码也还是可以用的,和标准函数的效果完全一样。在 Unicode 下你可以这样调整一下:

[Setup]
AppName=My Program
AppVerName=My Program version 1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program

[CustomMessages]
cm1=选择目标文件
cm2=可执行程序文件 (*.exe)|*.exe|所有文件 (*.*)|*.*
cm3=你将保存文件:

[Code]
const
OFN_OVERWRITEPROMPT = $2;

type
TOpenFileName = record
  lStructSize: Longint;
  hwndOwner: Longint;
  hInstance: Longint;
  lpstrFilter: String;
  lpstrCustomFilter: String;
  nMaxCustFilter: Longint;
  nFilterIndex: Longint;
  lpstrFile: String;
  nMaxFile: Longint;
  lpstrFileTitle: String;
  nMaxFileTitle: Longint;
  lpstrInitialDir: String;
  lpstrTitle: String;
  Flags: Longint;
  nFileOffset: Word;
  nFileExtension: Word;
  lpstrDefExt: String;
  lCustData: Longint;
  lpfnHook: Longint;
  lpTemplateName: String;
end;

function GetSaveFileName(var lpofn: TOpenFileName): boolean;
external 'GetSaveFileNameW@comdlg32.dll';

function GetMySaveFileName(sTitle: string; var SaveFN: string; sStartDir, sFilter, sDefExt: string): boolean;
var
F: TOpenFileName;
S, Title, StartDir, Filter, DefExt: string;
z: Char;
iVal: boolean;
begin
S := ' ';
SetLength(S, 512);

Title := sTitle;
StartDir := sStartDir;
Filter := sFilter;
DefExt := sDefExt;

z := Chr(0);

F.hwndOwner := StrToInt(ExpandConstant('{wizardhwnd}'));
F.lStructSize := 76;
F.Flags := OFN_OVERWRITEPROMPT;

F.lpstrTitle := Title;

if StartDir <> '' then
  F.lpstrInitialDir := StartDir;

if Filter <> '' then
begin
  StringChangeEx(Filter, '|', z, True);
  Filter := Filter + z + z;
  F.lpstrFilter := Filter;
end;

F.nFilterIndex := 1;

if DefExt <> '' then
  F.lpstrDefExt := DefExt;

F.lpstrFile := S;
F.nMaxFile := Length(S);

iVal := GetSaveFileName(F);

if iVal then
  SaveFN := F.lpstrFile
else
  SaveFN := '';

Result := iVal;
end;

procedure InitializeWizard();
var
yourfilename: string;
begin
if GetMySaveFileName(CustomMessage('cm1'), yourfilename, ExpandConstant('{userdocs}'), CustomMessage('cm2'), 'exe') then
  MsgBox(CustomMessage('cm3') + ' ' + yourfilename, mbInformation, MB_OK);
end;
离线546242502

发帖
332
金钱
-3060
威望
-306
只看该作者 3 发表于: 2015-08-15
用户被禁言,该主题自动屏蔽!