【问题标题】:How to change MsgBox message caption at runtime?如何在运行时更改 MsgBox 消息标题?
【发布时间】:2012-03-12 15:19:28
【问题描述】:

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

[Setup]
SetupAppTitle=myAppName

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

【问题讨论】:

    标签: inno-setup msgbox


    【解决方案1】:

    我不认为更改应用程序标题(如果可能)仅用于显示对话框标题是一个好主意。所以我会使用 Windows MessageBox,它甚至被 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;
    

    【讨论】:

    • @TLama,如果 Unicode 版本中有 PChar,它实际上可能定义为 PWideChar(替换 PAnsiChar)。也就是说,如果 OP 需要显示 Unicode 标题/消息(如果没有,您可以使用 Ansi 版本)。虽然我无法测试它......
    • @TLama,在这种情况下,我认为只需将 PAnsiChar 更改为 string 即可;)
    • @kobik,谢谢,你是对的that 可能会成功。
    • @GregoryKotsaftis,没有区别。
    【解决方案2】:

    这就是我最终做到的:

    [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;
    

    感谢大家的帮助!

    【讨论】:

    • 很好的“用法”;)请确保您接受@TLama 的回答是正确的。
    • 啊,我明白了,您缺少 MB_TASKMODAL 标志 (MB_TASKMODAL = $00002000;)。 MessageBox 的标签还有很多,kobik 只选择了其中的几个。当然,当您设置了正确的窗口句柄时,当您尝试从中设置焦点时,它会导致消息框闪烁。
    • Java 是完全独立的平台。但是无论如何,如果您指定hWnd 或使用MB_TASKMODAL 而不指定hWnd,唯一的区别是,在第一种情况下,当您尝试聚焦向导时,您的窗口会闪烁。在第二种情况下不会。正是因为这种所有权;-)
    • 这就是我的观点!感谢所有人为我指出正确的方向。我仍然不得不快速解析 inno 的代码以找到适合我需要的答案......(我投票赞成我得到的任何帮助!)
    • 查看时间,@Mar 12 我已经解决了这个问题,但是由于我是新手,直到有一天我才能发布我的答案。所以我不得不等待......我从来没有使用过 TLama 的解决方案,因为我已经有了一个(我前几天提供的那个)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 2018-01-16
    相关资源
    最近更新 更多