お世話になります。
C++ Builder 6.0についてのご質問です。
今回、諸事情により
メッセージボックスのキャンセルボタンのキャプション名を
独自の名前にできれば変更したいと考えています。
メッセージ表示部の実装方法は別記のとおりですが、この方法ですと
キャンセルボタン名はTMsgDlgButtons内の仕様により
"キャンセル"と表示されています。
このキャプション名"キャンセル"を例えば"強制停止"等、
自由に変更することは可能でしょうか。
(表示部コード)
MessageDlg("ボタン名を変更したいですか?"
,mtConfirmation,TMsgDlgButtons()<<mbOK<<mbCancel,0) == mrCancel)
{
(省略)
}
よろしくお願いいたします。
今回は諸事情により、Delphiで良ければ 餡の種類は二つ。
(つぶあん) リソースの文字列を直接書き換える。
キャンセルボタンのCaption文字列を定義しているソース(Consts.pas)を
プロジェクトのフォルダにコピーして、resourcestring中の該当する文字列を変更。
resourcestring
// SMsgDlgCancel = 'キャンセル';
SMsgDlgCancel = '強制停止';
(こしあん) プログラムで変更する。
private
procedure SpecialMsg(var Msg: TMessage); message WM_APP+100;
end;
implementation
procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(Handle, WM_APP+100, 0, Integer(PChar('強制停止')));
MessageDlg('ボタン名を変更したけど、いいかな?', mtConfirmation, [mbOk, mbCancel], 0);
end;
procedure TForm1.SpecialMsg(var Msg: TMessage);
var
hwP, hwC: HWND;
begin
hwP := FindWindow(nil, '確認');
hwC := FindWindowEx(hwP, 0, nil, 'キャンセル');
//SendMessage(hwC, WM_SETTEXT, 0, Integer(PChar('強制停止')));
SendMessage(hwC, WM_SETTEXT, 0, Msg.LParam);
end;
同じくでDelphiですが。
unit てきとうなユニット;
interface
uses
Dialogs;
function MessageDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
implementation
uses
Controls, Forms, StdCtrls;
function MessageDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
var
dlg: TForm;
i: Integer;
begin
dlg := CreateMessageDialog(Msg, DlgType, Buttons);
try
dlg.HelpContext := HelpCtx;
dlg.Position := poScreenCenter;
for i := 0 to dlg.ComponentCount -1 do begin
if dlg.Components[i] is TButton and
(TButton(dlg.Components[i]).ModalResult = mrCancel) then begin
TButton(dlg.Components[i]).Caption := '強制停止';
Break;
end;
end;
Result := dlg.ShowModal;
finally
dlg.Free;
end;
end;
end.
アンパンでいい?さん、ぽむぽむさんありがとうございました。
delphiとC++ Builderの実装スタイルは意外と違うのですね。
今回、頂いたアドバイスも含めて、
最終的には下記のように新規にダイアログを作成することで、
ボタン名を変更できるよう対応することにしました。
(アンパンでいい?さんからの文字列を定義しているソース(Consts.pas)は私のC++ Builder環境では見つけられませんでした)
TForm *dlg;
TButton *btn;
dlg = CreateMessageDialog("ボタン名を変更したいですか?""
,mtConfirmation
,TMsgDlgButtons() << mbOK << mbCancel);
btn = (TButton *)dlg->FindComponent("Cancel");
btn->Caption = "強制停止";
dlg->ShowModal();
if(dlg!=NULL) delete dlg;
どうもありがとうございました (_ _)
ツイート | ![]() |