MessageDlg does not make sound
Asked Answered
Z

2

5

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.

Zanezaneski answered 9/12, 2016 at 14:25 Comment(0)
N
3

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;
Neoptolemus answered 9/12, 2016 at 16:19 Comment(0)
D
4

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.

Dachshund answered 9/12, 2016 at 14:30 Comment(4)
MessageBeep(MB_ICONQUESTION); Does not emit Standard system soundZanezaneski
I'm using Windows 7 and that not working for me , MessageBeep(MB_ICONWARNING); emit the sound , but MessageBeep(MB_ICONQUESTION); NoZanezaneski
Erm, not sure now which value you should pass. I think you should play with your sounds and set them up so that you can distinguish between then. The see what sound is emitted when VCL styles are off, then pass the value which replicates that sound. Anyway, I'm sure you can take it from here.Dachshund
@Sami The most probable reason why using MessageBeep(MB_ICONQUESTION); does not generate any sound is because your windows does not have any sound assigned as the Windows Question sound (this is by default). Check your windows sound settings to see or edit which notifications have sounds assigned to them.Exact
N
3

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;
Neoptolemus answered 9/12, 2016 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.