Title: Making MessageDlg play the corresponding sound
Question: How can I make MessageDlg play the sound like MessageBox?
Answer:
The method MessageBox of the Application object plays the system
sound associated with the type of the message, but the function
MessageDlg doesn't. If you want sounds with MessageDlg then you
either have to call the API MessageBeep (declared in the Windows
unit) every time you call MessageDlg or use this wrapper for
MessageDlg:
interface
uses dialogs, windows;
function MessageDlgS(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons = [mbOk]; HelpCtx: Longint = 0): Word;
implementation
function MessageDlgS(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;