如何使用inno setup pascal脚本显示阻止消息框

时间:2015-07-10 10:48:29

标签: inno-setup mutex pascal messagebox

我正在使用inno setup(pascal脚本)为我的应用程序创建安装程序,在我的设置中,要求如果用户运行设置两次,则必须通过检查显示“另一个实例已在运行”的消息互斥体,我已经实现了,现在问题是它显示消息框,但如果用户仍然尝试再次运行设置,上面的消息将多次显示,我不想要。所以我的消息框应该阻止他做他的机器上的任何东西,直到消息框关闭。

编辑:我想阻止用户运行设置的当前窗口,以防止用户再次从同一位置运行设置。

我的示例代码:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
const
  MB_APPLMODAL =   $00002000;
  MB_SYSTEMMODAL = $00001000;
  MB_ICONHAND = $00000010;
  MB_ICONQUESTION = $00000020;
  MB_ICONEXCLAMATION = $00000030;
  MB_ICONASTERISK = $00000040;
  MB_ICONSTOP = MB_ICONHAND;
  MB_ICONINFORMATION = MB_ICONASTERISK;

#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

function MessageBox(hWnd: HWND; lpText, lpCaption: string;
  uType: UINT): Integer; external 'MessageBox{#AW}@user32.dll stdcall';

function SysModalMsgBox(Owner: HWND; const Text: string; MsgType: TMsgBoxType;
  Buttons: Integer): Integer;
var
  Flags: UINT;
  Caption: string;
begin
  Flags := Buttons;

  case MsgType of
    mbInformation: Flags := Flags or MB_ICONINFORMATION;
    mbConfirmation: Flags := Flags or MB_ICONQUESTION;
    mbError: Flags := Flags or MB_ICONEXCLAMATION;
    mbCriticalError: Flags := Flags or MB_ICONSTOP;
  end;

  if not IsUninstaller then
    Caption := SetupMessage(msgSetupAppTitle)
  else
    Caption := SetupMessage(msgUninstallAppTitle);  

  Result := MessageBox(Owner, Text, Caption, MB_SYSTEMMODAL);
end;

procedure InitializeWizard;
begin
  Sleep(5000);
  SysModalMsgBox(WizardForm.Handle, 'Another instance is runinng please try again!',mbInformation , MB_OK);

end;

0 个答案:

没有答案