Mega Code Archive

 
Categories / Delphi / Examples
 

How to have messagedlg[] play the corresponding sound

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;