messageDlgについて

解決


理恵  2003-12-16 15:42:29  No: 6236  IP: 192.*.*.*

messageDlgを使って、Defultで[mbNo]が選択された状態にしたいのですが 、どうしても[mbYes]が選択された状態になってしまいます。ご教授お願いします。

編集 削除
Halbow  2003-12-16 16:37:25  No: 6237  IP: 192.*.*.*

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;

編集 削除
通りすがり  2003-12-16 16:47:06  No: 6238  IP: 192.*.*.*

以前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;

編集 削除
グリコのおまけや  2003-12-16 18:13:02  No: 6239  IP: 192.*.*.*

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;

編集 削除
えび  2003-12-16 18:54:47  No: 6240  IP: 192.*.*.*

MessageBoxじゃダメなんですか?パラメータの設定だけで出来ますけど。

編集 削除
通りすがり  2003-12-16 19:08:01  No: 6241  IP: 192.*.*.*

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;

編集 削除
理恵  2003-12-17 12:47:26  No: 6242  IP: 192.*.*.*

みなさまありがとうございます。
いろいろと試してみたのですが、
大変勉強になりました。

編集 削除