I have the code below :
IF MessageDlg('Delete?',mtConfirmation,[mbYes,mbNo],0) = MrYes THEN
Begin
///Do Something;
End
Else
Begin
///Do Something;
End;
When the Style
is Windows
the MessageDlg
function play the sound , but if I change the Style
to Windows 10
for exemple, then the sound does not work.
Why the sound does not exist when I select a Style
?
How can I fix that ?
Note : I'm working on Delphi 10 Seattle.
Update:
I try MessageBeep(MB_ICONQUESTION);
as David Heffernan suggest in his Answer, but that also does not emit a sound.
When you use the Windows style, the message dialog is implemented by one of the Windows message dialog functions. These will emit standard system sounds that match the type of dialog.
When you use VCL styles, the VCL code is responsible for the dialog. And it chooses not to emit system sounds. This is just another one of the many details that is implemented imprecisely with VCL styles. If you want to replicate the standard behaviour when using VCL styles, you will need to add an appropriate call to MessageBeep
.
To complement the David answer, depending of your Windows version, the current active style and others checks the MessageDlg function is implemented using a Custom TForm or using the TTaskDialog class (this is a wrapper for the Windows Task Dialog). So as workaround you can use the TTaskDialog class directly and add the Vcl.Styles.Hooks unit to your project to style that kind of dialog.
uses
Vcl.Styles.Hooks;
procedure TForm56.Button1Click(Sender: TObject);
var
LTaskDialog : TTaskDialog;
begin
LTaskDialog := TTaskDialog.Create(Self);
try
LTaskDialog.Caption := 'Confirm';
LTaskDialog.Text := 'Delete ?';
LTaskDialog.CommonButtons := [tcbYes, tcbNo];
LTaskDialog.MainIcon := tdiInformation;
if LTaskDialog.Execute then
if LTaskDialog.ModalResult = mrYes then
begin
end;
finally
LTaskDialog.Free;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With