I want to create a warning dialog box which asks the users if the information typed during signup was correct, and asks him wether he want to continue or close that dialog and correct his information.
Asked
Active
Viewed 1.6k times
6
-
Even [`Task Dialog`](http://msdn.microsoft.com/en-us/library/windows/desktop/bb760441%28v=vs.85%29.aspx) in new Windows versions doesn't have the common buttons with this caption. Talking about task dialog you might use the custom buttons (see the screenshot from the link). In standard [`MessageBox`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx) there's IMHO no way how to change the button captions. So the easiest way is to create your own one, but maybe I'm wrong... Maybe [`this`](http://www.codeguru.com/cpp/w-p/win32/messagebox/article.php/c10873) way ? – TLama Dec 22 '11 at 12:29
-
1@TLama Task dialog lets you give the buttons any name you fancy – David Heffernan Dec 22 '11 at 12:31
-
@David, I was talking about `dwCommonButtons`, those you can't change or am I wrong ? – TLama Dec 22 '11 at 12:34
-
@tlama that's not really the point since one of the goals of task dialog is to allow buttons with any caption – David Heffernan Dec 22 '11 at 12:37
-
3Continue and Close mean pretty much the same thing. You need better names. Read the windows ux guidelines. – David Heffernan Dec 22 '11 at 13:35
4 Answers
11
var
td: TTaskDialog;
tb: TTaskDialogBaseButtonItem;
begin
td := TTaskDialog.Create(nil);
try
td.Caption := 'Warning';
td.Text := 'Continue or Close?';
td.MainIcon := tdiWarning;
td.CommonButtons := [];
tb := td.Buttons.Add;
tb.Caption := 'Continue';
tb.ModalResult := 100;
tb := td.Buttons.Add;
tb.Caption := 'Close';
tb.ModalResult := 101;
td.Execute;
if td.ModalResult = 100 then
ShowMessage('Continue')
else if td.ModalResult = 101 then
ShowMessage('Close');
finally
td.Free;
end;
end;

Community
- 1
- 1

Mikael Eriksson
- 136,425
- 22
- 210
- 281
-
2+1 for complete answer, (although `close` is a very bad caption for a button because of its general ambiguity and meaninglessness :-) – Johan Dec 22 '11 at 13:32
-
1.. and only when themes are enabled. I remember David has made a note on this somehere.. update - [here](http://stackoverflow.com/a/6344538/243614) – Sertac Akyuz Dec 22 '11 at 13:49
-
3Close generally means close the dialog and is used when there are no options. Continue and Cancel are most often paired. – Marcus Adams Dec 22 '11 at 14:56
-
@David - Thanks, it's very nice to see that it has been resolved in just about a few months! – Sertac Akyuz Dec 22 '11 at 20:18
8
if delphi then
if mrYes=MessageDlg('Continue?',mtwarning,[mbYes, mbNo],0) then
begin
//do somthing
end
else
exit; //go out

PresleyDias
- 3,657
- 6
- 36
- 62
-
what about writing ( Continue and Close ) instead of ( Yes and No ) ? – Rafik Bari Dec 22 '11 at 12:28
-
2you can only have this for the messageDlg mbYes, mbNo, mbOK,mbCancel,mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp – PresleyDias Dec 22 '11 at 12:31
-
IMO, it's better (easier, simpler, less code, etc.) to stick with the standard buttons. I suspect that the reason for the specific continue/close captions is based on specifications/requirements that were written without knowledge of the standard captions. If this is the case, the requirements should be changed. – Chris Thornton Dec 22 '11 at 13:20
-
1@chris the standard changed ages ago when Vista came out. Read about task dialog. – David Heffernan Dec 22 '11 at 13:28
-
1Ages ago.. yes.. Still not available to the majority of windows users, particularly enterprise users. I do like the task dialog, but it's overkill for such a simple confirmation prompt, unless those Continue/Close captions are necessary/justified, which I suspect they aren't. – Chris Thornton Dec 22 '11 at 14:21
-
That OS task dialogs aren't available doesn't mean that dialogs with more descriptive button captions aren't available, @Chris. And it's only a new standard on Windows; descriptive captions have been common on Macs for a decade or two. – Rob Kennedy Dec 22 '11 at 15:44
-
@chris dialogs with descriptive captions, as opposed to yes, no, cancel are just better – David Heffernan Dec 22 '11 at 18:11
8
var
AMsgDialog: TForm;
abutton: TButton;
bbutton: TButton;
begin
AMsgDialog := CreateMessageDialog('This is a test message.', mtWarning,[]);
abutton := TButton.Create(AMsgDialog);
bbutton := TButton.Create(AMsgDialog);
with AMsgDialog do
try
Caption := 'Dialog Title' ;
Height := 140;
AMsgDialog.Width := 260 ;
with abutton do
begin
Parent := AMsgDialog;
Caption := 'Continue';
Top := 67;
Left := 60;
// OnClick :tnotyfievent ;
end;
with bbutton do
begin
Parent := AMsgDialog;
Caption := 'Close';
Top := 67;
Left := 140;
//OnClick :tnotyfievent ;
end;
ShowModal ;
finally
abutton.Free;
bbutton.Free;
Free;
end;

Vibeeshan Mahadeva
- 7,147
- 8
- 52
- 102
2
Based on this:
procedure HookResourceString(rs: PResStringRec; newStr: PChar);
var
oldprotect: DWORD;
begin
VirtualProtect(rs, SizeOf(rs^), PAGE_EXECUTE_READWRITE, @oldProtect);
rs^.Identifier := Integer(newStr);
VirtualProtect(rs, SizeOf(rs^), oldProtect, @oldProtect);
end;
const
SContinue = 'Continue';
SClose = 'Close';
procedure TForm1.Button1Click(Sender: TObject);
begin
HookResourceString(@SMsgDlgOK, SContinue);
HookResourceString(@SMsgDlgCancel, SClose);
if MessageDlg('My Message', mtConfirmation, [mbOK, mbCancel], 0) = mrOK then
begin
// OK...
end;
end;
-
+1, you can also use the [`hook`](http://www.codeguru.com/cpp/w-p/win32/messagebox/article.php/c10873) to get the handle to the message box and then use [`GetDlgItem`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms645481%28v=vs.85%29.aspx) to get the handle of the button you want to change and set its text by using [`SetDlgItemText`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms645521%28v=vs.85%29.aspx); quite overkill, I know :) But the worst on this solution is that you have to use the DLL library for that hook. – TLama Dec 22 '11 at 13:05
-
2@TLama - No need for a dll, the dialog window is in the same thread. Can also hook the dialog without using SetWindowHookEx, in a message handler, such as WM_ENABLE, WM_ACTIVATE, or in ActiveFormChange etc.. – Sertac Akyuz Dec 22 '11 at 13:30
-
-
@SertacAkyuz, are you sure with that ? I tried to catch the `WM_ACTIVATE` in the main form's `WndProc` at message box showing but I didn't get the notification. Are you sure the `MessageBox`'s window doesn't have its own message loop ? – TLama Dec 22 '11 at 14:58
-
2The problem with this solution is that you're not restoring the original `Identifier` values afterwards, so every dialog displayed after this will show `Continue` instead of `OK` and `Close` instead of `Cancel`. There are other, better alternatives to this solution; they've even been posted here in this thread. (Not downvoting, just pointing out the problem.) – Ken White Dec 22 '11 at 15:02
-
1@TLama - Sorry for the confusion, it's my incorrect wording. I should possibly say 'hack' the dialog, instead of 'hook' the dialog. In a WM_ACTIVATE handler that's calling the dialog, you can loop forms when active is WA_INACTIVE, see if the activating form is a 'TMessageForm' (in case of a TaskDialog get the activating windows class name to compare...), etc.. – Sertac Akyuz Dec 22 '11 at 15:11