Normal MessageBoxes (and PB's MsgBoxes) generate sounds according to the sound scheme that the user currently has set up.
(The type of sound changes with the icon displayed in the message box).
By using MessageBoxIndirect() we can circumvent Window's sound schemes and present a 'Muted' MessageBox...
(The type of sound changes with the icon displayed in the message box).
By using MessageBoxIndirect() we can circumvent Window's sound schemes and present a 'Muted' MessageBox...

Code:
#INCLUDE "WIN32API.INC" '------------------/ ' Call like: MMBox "Message", "Title", Flags or Res = MMBOX("Choose","eg Yes or No", %MB_YESNO) Function MMBox (ByVal sMsg As String, Opt ByVal sTitle As String, Opt ByVal dwFlags As Dword) As Long Local hOwner, Res As Long Local MbParams As MSGBOXPARAMS If Len(sTitle) = 0 Then sTitle = "MMBox" ' $AppName ? Select Case dwFlags AND &H000000f0 ' Choose appropriate icon Case &H00000010 ' %MB_ICONHAND, %MB_ICONERROR, %MB_ICONSTOP MbParams.lpszIcon = %IDI_HAND Case &H00000020 ' %MB_ICONQUESTION MbParams.lpszIcon = %IDI_QUESTION Case &H00000030 ' %MB_ICONEXCLAMATION, %MB_ICONWARNING MbParams.lpszIcon = %IDI_EXCLAMATION Case &H00000040 ' %MB_ICONASTERISK, %MB_ICONINFORMATION MbParams.lpszIcon = %IDI_ASTERISK Case Else ' %MB_USERICON MbParams.lpszIcon = %IDI_APPLICATION ' Or Icon from resource file..? End Select dwFlags = (dwFlags AND &Hffffff0f) OR &H00000080 ' Force %MB_USERICON Style hOwner = GetForegroundWindow() ' 0 for desktop or function could ' take 'hOwner' as a parameter MbParams.cbSize = SizeOf(MbParams) MbParams.hwndOwner = hOwner MbParams.hInstance = 0 MbParams.lpszCaption = StrPtr(sTitle) MbParams.lpszText = StrPtr(sMsg) MbParams.dwStyle = dwFlags ' if .dwStyle includes %MB_USERICON, .lpszIcon is valid ' MbParams.lpszIcon = ' and Windows doesn't automatically asign a sound ! MbParams.dwContextHelpId = 0 MbParams.lpfnMsgBoxCallback = 0 MbParams.dwLanguageId = 0 ' 3081 ? Res = MESSAGEBOXINDIRECT(MbParams) Function = Res End Function '------------------/MMBox Function PbMain() Local MbParams As MSGBOXPARAMS Local Res As Long MMBox "Whatever" MMBox "IDI_HAND, IDI_ERROR", "MB_ICONHAND, ERROR, STOP", %MB_ICONHAND Res = MMBox ("IDI_QUESTION", "MB_ICONQUESTION, YESNO", %MB_ICONQUESTION OR %MB_YESNO OR %MB_DEFBUTTON2) MMBox "IDI_EXCLAMATION, IDI_WARNING", "MB_ICONEXCLAMATION, WARNING", %MB_ICONEXCLAMATION MMBox "IDI_ASTERISK, IDI_INFORMATION", "MB_ICONASTERISK, INFORMATION", %MB_ICONASTERISK MMBox "IDI_APPLICATION", "%MB_USERICON", %MB_USERICON ' Standard API MessageBox (or PB MsgBox) - applies sound as per Control panel setup / Sound Scheme MessageBox GetForegroundWindow(), "~!#$%^&*'"+$CRLF+"MessageBox..!", "Now hear this!", %MB_ICONEXCLAMATION End Function '------------------/PBMain
Comment