如何在运行时更改MsgBox消息标题?

时间:2012-03-12 15:19:28

标签: inno-setup msgbox

我需要在运行时更改MsgBox消息框的默认标题。目前,它不断显示SetupAppTitle指令的值作为标题:

[Setup]
SetupAppTitle=myAppName

但这是在编译时指定的。如何在运行时执行此操作,例如来自[Code]部分?

2 个答案:

答案 0 :(得分:5)

我不认为更改应用程序标题(如果可能)仅对显示对话框标题是一个好主意。所以我会使用MessageBox甚至使用的Windows MsgBox。以下是Inno Setup的Ansi / Unicode版本的简单示例:

[Code]
const
  MB_ICONERROR = $10;
  MB_ICONQUESTION = $20;
  MB_ICONWARNING = $30;
  MB_ICONINFORMATION = $40;

#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';

procedure ButtonOnClick(Sender: TObject);
begin
  MessageBox(0, 'Message Text', 'Message Caption', MB_OK or MB_ICONINFORMATION);
end;

答案 1 :(得分:1)

这就是我最终做到的:

[Code]
{ https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505.aspx }
{ Use Windows MessageBox() function as an MsgBox() replacement. }
{ MessageBoxW is the UNICODE version of this API call. }
const
  { these are not exported in Inno Setup! }
  MB_ICONERROR = $00000010;
  MB_ICONWARNING = $00000030;
  MB_ICONINFORMATION = $00000040;
  MB_ICONQUESTION = $00000020;

function _MessageBoxW_(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer;
  external 'MessageBoxW@user32.dll stdcall';

{ Usage: SysMsgBox('Error', 'Shit happens!', MB_OK or MB_ICONERROR); }
{        res =: SysMsgBox('Question', 'blah blah', MB_YESNO or  MB_ICONQUESTION); }
function SysMsgBox(const Caption, Message: String; const Flags: Integer): Integer;
begin
  Result :=
    _MessageBoxW_(StrToInt(ExpandConstant('{wizardhwnd}')), Message, Caption, Flags);
end;

感谢大家的帮助!