Date: 02-16-2022
Return to Index
created by gbSnippets
'The MsgBox$ function returns a value corresponding to the button (or escape key)
'a user chooses. Use that value in an If/Then or Select Case statement to respond
'to the user's choice. Options include 1-3 buttons on the MsgBox$ window.
'Primary Code:
'Syntax: MsgBox txt$ [, [style%], title$]
'Yes-No, QuestionMark Icon
If MsgBox ("Are you sure?", %MB_YesNo Or %MB_IconQuestion, "Take Action") = %IdNo Then
'... respond to NO
Else
'... respond to YES
End If
'Ok-Cancel, Information Icon
If MsgBox ("Are you sure?", %MB_OkCancel Or %MB_IconInformation, "Take Action") = %IdOK Then
'... respond to OK
Else
'... respond to CANCEL
End If
'Yes-No-Cancel, ExclamationPoint Icon
Select Case MsgBox ("Are you sure?", %MB_YesNoCancel Or %MB_IconExclamation, "Take Action")
Case %IDYes
Case %IDNo
Case %IDCancel
End Select
'Buttons and Icon Options
'To indicate the buttons displayed in the message box, specify one of the following values.
'Buttons
MB_ABORTRETRYIGNORE 'aborty, retry, ignore
MB_CANCELTRYCONTINUE 'cancel, try again, continue
MB_HELP 'adds a Help button
MB_OK 'one button, OK
MB_OKCANCEL 'two buttons, OK and Cancel
MB_RETRYCANCEL 'two buttons, Retry and Cancel
MB_YESNO 'two buttons, Yes and No
MB_YESNOCANCEL 'three buttons, Yes, No, and Cancel
'Icons
MB_ICONEXCLAMATION 'exclamation point
MB_ICONWARNING 'exclamation point
MB_ICONINFORMATION 'lowercase letter i in a circle
MB_ICONASTERISK 'lowercase letter i in a circle
MB_ICONQUESTION 'question mark (not recommended)
MB_ICONSTOP 'stop sign
MB_ICONERROR 'stop sign
MB_ICONHAND 'stop sign
'To indicate the default button, specify one of the following values.
MB_DEFBUTTON1 '1st button is default (default)
MB_DEFBUTTON2 '2nd button is default
MB_DEFBUTTON3 '3rd button is default
MB_DEFBUTTON4 '4th button is default
'Compilable Example: (Jose Includes)
'run and compile, then press Alt-F4 or X-button to close
'uses MsgBox to ask user to confirm saving settings before closure
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg as DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_SYSCOMMAND
Local Style&
If (CB.wParam AND &HFFF0) = %SC_Close Then 'trap Alt-F4, X-button, WindowMenu/Close
Style& = %MB_YesNoCancel Or %MB_IconQuestion Or %MB_TaskModal
Select Case MsgBox("Save Setting Before Closing?", Style&, "Save Settings")
Case %IdYes
' ... take action before closing the application
Function = 0 'False - go ahead with closing the application
Case %IdNo
Function = 0 'False - go ahead with closing the application
Case %IdCancel
Function = 1 'True - abort the close - no further processing needed
End Select
End If
Case %WM_Close
MsgBox "Close" 'included as a reminder the WM_Close is sent before WM_Destroy
Case %WM_Destroy
MsgBox "Destroy" 'put your closing code here (save settings, etc.)
End Select
End Function
'gbs_00049
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm