Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes you'd like to customize the MsgBox, putting in a sound of your own or
'an icon of your own. All that is required is to use the %MB_UserIcon equate.
'Once the sound is muted, you can use sndPlaySound to play a custom/system sound
'of your choice (see snippets http://gbl_00328 and http://gbl_00350 )
'Primary Code:
'A simple way to get rid of the MsgBox sound is to include both the %MB_UserIcon
'and another icon constant. If you use only the %MB_UserIcon, then Windows leaves a
'space for an icon, making the text in the MsgBox mis-aligned.
MsgBox "hello", %MB_UserIcon + %MB_IconExclamation
'To specify an icon of your own, however, a bit more effort is needed. Fill in a
'MsgBoxParams structure and send to the MessageBoxIndirect API.
Local D As MsgBoxParams, T As Asciiz*50, C As Asciiz*50, I As Asciiz*50
T = "Custom Message"
C = "Customize"
D.cbSize = SizeOf (D)
D.hWndOwner = hDlg 'can be %NUL
D.hInstance = %Null 'handle to the module containing the icon resource
D.lpszText = VarPTR(T)
D.lpszCaption = VarPTR(C)
D.dwStyle = %MB_UserIcon
D.lpszIcon = %IDI_Question
D.dwContextHelpID = 0
D.lpfnMsgBoxCallback = 0
D.dwLanguageID = 0
MessageBoxIndirect D
'Compilable Example: (Jose Includes)
'This snippets shows how to get no icon. It also shows how to display an icon from a
'resource file or a system icon (built into Windows):
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
Global hDlg as DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"System Icon", 30,10,140,20
Control Add Button, hDlg, 200,"Resource Icon", 30,40,140,20
Control Add Button, hDlg, 300,"No icon and no sound!", 30,70,140,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local D As MsgBoxParams, T As Asciiz*50, C As Asciiz*50, I As Asciiz*50
If CB.Msg = %WM_Command AND CB.Ctl = 300 AND CB.Ctlmsg = %BN_Clicked Then
MsgBox "No icon here!", %MB_UserIcon + %MB_IconExclamation
End If
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
T = "Custom Message"
C = "Customize"
D.cbSize = SizeOf (D)
D.hWndOwner = hDlg 'can be %NUL
D.hInstance = %Null 'handle to the module containing the icon resource
D.lpszText = VarPTR(T)
D.lpszCaption = VarPTR(C)
D.dwStyle = %MB_UserIcon
D.lpszIcon = %IDI_Question
D.dwContextHelpID = 0
D.lpfnMsgBoxCallback = 0
D.dwLanguageID = 0
MessageBoxIndirect D
End If
If CB.Msg = %WM_Command AND CB.Ctl = 200 AND CB.Ctlmsg = %BN_Clicked Then
T = "Custom Message"
C = "Customize"
I = "logo"
D.cbSize = SizeOf (D)
D.hWndOwner = hDlg 'can be %NUL
D.hInstance = 0 'handle to the module containing the icon resource
D.lpszText = VarPTR(T)
D.lpszCaption = VarPTR(C)
D.dwStyle = %MB_UserIcon
D.lpszIcon = 100
D.dwContextHelpID = 0
D.lpfnMsgBoxCallback = 0
D.dwLanguageID = 0
MessageBoxIndirect D
End If
End Function
'gbs_00332
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm