delphi MessageBox MB_OKCANCEL 按钮文字编辑
时间: 2023-08-13 22:42:27 浏览: 81
你可以使用 Windows API 函数 SetWindowText 来编辑 MessageBox 中的按钮文字。以下是一个示例代码:
```delphi
function CustomMessageBox(const AMessage: PChar; const ATitle: PChar; const AButtonType: UINT): Integer;
var
ButtonText: array[0..255] of Char;
begin
// 获取按钮的文本
if AButtonType and MB_OK = MB_OK then
StrCopy(ButtonText, '自定义 OK 按钮文本')
else if AButtonType and MB_CANCELTRYCONTINUE = MB_CANCELTRYCONTINUE then
begin
StrCopy(ButtonText, '自定义 Cancel 按钮文本');
SetWindowText(GetDlgItem(FindWindow('#32770', ATitle), IDCANCEL), ButtonText);
StrCopy(ButtonText, '自定义 Try Again 按钮文本');
SetWindowText(GetDlgItem(FindWindow('#32770', ATitle), IDTRYAGAIN), ButtonText);
StrCopy(ButtonText, '自定义 Continue 按钮文本');
SetWindowText(GetDlgItem(FindWindow('#32770', ATitle), IDCONTINUE), ButtonText);
end
else
StrCopy(ButtonText, '自定义其他按钮文本');
// 显示 MessageBox
Result := MessageBox(0, AMessage, ATitle, AButtonType or MB_ICONINFORMATION);
end;
```
在上面的示例代码中,我们使用了 FindWindow 函数来查找指定标题的窗口句柄,然后使用 GetDlgItem 函数获取指定控件的句柄,最后使用 SetWindowText 函数修改按钮的文本。