Author: Tomas Rutkauskas
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.
1 2 function MessageDlgSound(const Msg: string;
3 DlgType: TMsgDlgType;
4 Buttons: TMsgDlgButtons;
5 HelpCtx: Longint): Word;
6 const7 Sounds: array[TMsgDlgType] of integer = (
8 MB_ICONEXCLAMATION, MB_ICONHAND, MB_OK, MB_ICONQUESTION, MB_ICONASTERISK);
9 begin10 MessageBeep(Sounds[DlgType]);
11 Result := MessageDlg(Msg, DlgType, Buttons, HelpCtx);
12 end;