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

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

上一主题 下一主题
离线546242502
 

发帖
332
金钱
-3060
威望
-306
只看楼主 倒序阅读 0 发表于: 2015-08-14
ANSI 和 Unicode 版都不能实现了,不知道新版有木有替代这个的了,有的话就算了

http://bbs.hanzify.org/read-htm-tid-52213.html

代码:
  1. [Code]
  2. const
  3. OFN_OVERWRITEPROMPT = $2;
  4. type
  5. TOpenFileName = record
  6.   lStructSize: Longint;
  7.   hwndOwner: Longint;
  8.   hInstance: Longint;
  9.   lpstrFilter: PChar;
  10.   lpstrCustomFilter: PChar;
  11.   nMaxCustFilter: Longint;
  12.   nFilterIndex: Longint;
  13.   lpstrFile: PChar;
  14.   nMaxFile: Longint;
  15.   lpstrFileTitle: PChar;
  16.   nMaxFileTitle: Longint;
  17.   lpstrInitialDir: PChar;
  18.   lpstrTitle: PChar;
  19.   Flags: Longint;
  20.   nFileOffset: Word;
  21.   nFileExtension: Word;
  22.   lpstrDefExt: PChar;
  23.   lCustData: Longint;
  24.   lpfnHook: Longint;
  25.   lpTemplateName: PChar;
  26. end;
  27. function GetSaveFileName(var lpofn: TOpenFileName): boolean;
  28. external 'GetSaveFileNameA@comdlg32.dll';
  29. function GetMySaveFileName(sTitle: string; var SaveFN: string; sStartDir, sFilter, sDefExt: string): boolean;
  30. var
  31. F: TOpenFileName;
  32. S, Title, StartDir, Filter, DefExt: string;
  33. z: Char;
  34. iVal: boolean;
  35. begin
  36. S := ' ';
  37. SetLength(S, 512);
  38. Title := sTitle;
  39. StartDir := sStartDir;
  40. Filter := sFilter;
  41. DefExt := sDefExt;
  42. z := Chr(0);
  43. F.hwndOwner := StrToInt(ExpandConstant('{wizardhwnd}'));
  44. F.lStructSize := 76;
  45. F.Flags := OFN_OVERWRITEPROMPT;
  46. F.lpstrTitle := PChar(Title);
  47. if StartDir <> '' then
  48.   F.lpstrInitialDir := PChar(StartDir);
  49. if Filter <> '' then
  50. begin
  51.   StringChangeEx(Filter, '|', z, True);
  52.   Filter := Filter + z + z;
  53.   F.lpstrFilter := PChar(Filter);
  54. end;
  55. F.nFilterIndex := 1;
  56. if DefExt <> '' then
  57.   F.lpstrDefExt := PChar(DefExt);
  58. F.lpstrFile := PChar(S);
  59. F.nMaxFile := Length(S);
  60. iVal := GetSaveFileName(F);
  61. if iVal then
  62.   SaveFN := F.lpstrFile
  63. else
  64.   SaveFN := '';
  65. Result := iVal;
  66. end;
  67. procedure InitializeWizard();
  68. var
  69. yourfilename: string;
  70. begin
  71. if GetMySaveFileName('选择目标文件', yourfilename, ExpandConstant('{userdocs}'), '可执行程序文件 (*.exe)|*.exe|所有文件 (*.*)|*.*', 'exe') then
  72.   MsgBox('你将保存文件: ' + yourfilename, mbInformation, MB_OK);
  73. end;
  74. 注意:如果你使用的不是最新的 INNO 版本,请将
  75.   StringChangeEx(Filter, '|', z, True);
  76. 改成
  77.   StringChange(Filter, '|', z);


离线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
回 2楼(gnatix) 的帖子
gnatix:不过我那个代码也还是可以用的,和标准函数的效果完全一样。在 Unicode 下你可以这样调整一下: [Setup]AppName=My ProgramAppVerName=My Program version 1.5....... (2015-08-15 02:52) 

好像是我理解错了,原先的代码可以的