messageDlgを使って、Defultで[mbNo]が選択された状態にしたいのですが 、どうしても[mbYes]が選択された状態になってしまいます。ご教授お願いします。
Halbow です。
下記のように試したらうまくいきました。
{ Private 宣言 }
public
procedure WMApp(var Msg:TMessage);message WM_APP;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(Handle,WM_APP,0,0);
MessageDlg('Test',mtConfirmation,[mbYes,mbCancel,mbNo],0);
end;
procedure TForm1.WMApp(var Msg: TMessage);
begin
keybd_event(VK_TAB,0,0,0);
keybd_event(VK_TAB,0,KEYEVENTF_KEYUP,0);
end;
以前D2で作ったような気がしたので、探してD6用に直してみました。
function MsgDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; DefBtn: TMsgDlgBtn): Integer;
const
ButtonNames:
array[TMsgDlgBtn] of string = ('Yes','No','OK','Cancel',
'Abort','Retry','Ignore','All','NoToAll','YesToAll','Help');
begin
with CreateMessageDialog(Msg,DlgType,Buttons) do begin
try
HelpContext := 0;
if DefBtn in Buttons then
ActiveControl :=
FindComponent(ButtonNames[DefBtn]) as TWinControl;
Result := ShowModal;
finally
Free;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if MsgDlg('ほんとにいいの?',mtConfirmation,
[mbYes,mbCancel,mbNo],mbCancel)=mrYes then
MsgDlg('ほんとに?',mtConfirmation,
[mbYes,mbCancel,mbNo],mbNo);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with CreateMessageDialog('これでエエんかいな?', mtConfirmation, [mbYes, mbNo]) do begin
OnShow := MyDlgShow;
if ShowModal = mrNo then begin
// NOならナンもせんがな
end;
Release;
end;
end;
procedure TForm1.MyDlgShow(Sender: TObject);
begin
SendMessage(FindWindowEx(TForm(Sender).Handle, 0, 'TButton', 'いいえ(&N)'), WM_SETFOCUS, 0, 0);
end;
MessageBoxじゃダメなんですか?パラメータの設定だけで出来ますけど。
procedure TForm1.Button1Click(Sender: TObject);
begin
if MessageBox(Handle,'こんな','で',
MB_ICONINFORMATION or MB_YESNOCANCEL or MB_DEFBUTTON3)=mrYes then
MessageBox(Handle,'こんな','かな?',
MB_ICONINFORMATION or MB_YESNOCANCEL or MB_DEFBUTTON2);
end;
みなさまありがとうございます。
いろいろと試してみたのですが、
大変勉強になりました。
ツイート | ![]() |