Mirror

How to have MessageDlg() play the corresponding sound (Views: 101)


Problem/Question/Abstract:

How to have MessageDlg() play the corresponding sound

Answer:

Application.MessageBox() and the Windows API function MessageBox() each play the system sound associated with the type of the message, but the VCL function MessageDlg does not. You have to call the API function MessageBeep() before you call MessageBox().

Replace your calls to MessageDlg() with MessageDlgSound() from the example below.

  
function MessageDlgSound(const Msg: string;
  DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons;
  HelpCtx: Longint): Word;
const
  Sounds: array[TMsgDlgType] of integer = (
    MB_ICONEXCLAMATION, MB_ICONHAND, MB_OK, MB_ICONQUESTION, MB_ICONASTERISK);
begin
  MessageBeep(Sounds[DlgType]);
  Result := MessageDlg(Msg, DlgType, Buttons, HelpCtx);
end;

<< Back to main page