MessageDlg does not make sound

I have the code below:

IF MessageDlg('Delete?',mtConfirmation,[mbYes,mbNo],0) = MrYes THEN Begin ///Do Something; End Else Begin ///Do Something; End; 

When Style is Windows , the MessageDlg function plays sound, but if I replace Style with Windows 10 , for example, the sound does not work.

  • Why does the sound not exist when I choose Style ?

  • How can i fix this?

Note. I am working on a Delphi 10 Seattle .

Update:

I am trying to use MessageBeep(MB_ICONQUESTION); like David Heffernan in his answer, but that also does not emit a sound.

+5
source share
2 answers

In addition to David's answer, depending on your version of Windows, the current active style and other checks of the MessageDlg function are implemented using Custom TForm or using the TTaskDialog class (this is the shell for the Windows Task Dialog ). That way you can use the TTaskDialog class directly and add Vcl.Styles.Hooks to your project to create such a 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; 
+3
source

When using the Windows style, the message dialog is implemented using one of the functions of the Windows message dialog box. They will produce standard system sounds appropriate to the type of dialogue.

When you use VCL styles, the VCL code is responsible for the dialog. And he chooses not to emit system sounds. This is just one of many details that are inaccurately implemented using VCL styles. If you want to reproduce the standard behavior when using VCL styles, you will need to add the corresponding MessageBeep call.

+4
source

Source: https://habr.com/ru/post/1261052/


All Articles