Attribute VB_Name = "MessageBoxDemoModule" Option Explicit '------------------------------------------------------------------------------ 'MessageBox Demo 'This demo show all the posible flags that can be used 'when showing a messagebox by calling the method ShowMessageBox 'from the WStForm class '------------------------------------------------------------------------------- Public wsFactory As New WStFactory Public wsForm As New WStForm Public wsWidget As New WStWidget Public Sub Main() Dim bResult As Boolean Dim sObjectName As String Dim sEventValue As String Dim bEnd As Boolean Dim iOptions As Integer Dim iDefaultAs As Integer Dim iIcon As Integer Dim iMsgBoxResult As Integer Dim sMsgBoxTest As String Dim sMsgBoxCaption As String Dim x As Integer Dim y As Integer Dim cx As Integer Dim cy As Integer x = 0 y = 0 cx = 0 cy = 0 bEnd = False wsFactory.CreateFormByName "myForm" wsForm.SetCoordTypeByName "myForm", WS_FORM_CT_BYPERCENTAGE wsFactory.CreateWidget WS_LABEL, 0, "FormTittle", 30, 0, 40, 5, "MsgBox Demo" 'Buttons wsFactory.CreateWidget WS_BUTTON, 0, "resetBtn", 55, 68, 35, 12, "Reset" wsFactory.CreateWidget WS_BUTTON, 0, "ExitButton", 55, 80, 35, 12, "Exit" wsFactory.CreateWidget WS_BUTTON, 0, "showMessageBoxBtn", 5, 10, 40, 13, "Show MsgBox" 'MessageBox result wsFactory.CreateWidget WS_LABEL, 0, "msgBoxResultLabel", 5, 25, 30, 5, "" 'MessageBox Options x = 5 y = 33 cx = 40 cy = 5 wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "okMsgBoxRadioBtn", x, y, cx, cy, "OK " wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "okCancelMsgBoxRadioBtn", x, y + 5, cx, cy, "OkCancel " wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "ariMsgBoxRadioBtn", x, y + 10, cx, cy, "AbortRetryIgnore" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "RetryCancelMsgBoxRadioBtn", x, y + 15, cx, cy, "RetryCancel" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "YesNoMsgBoxRadioBtn", x, y + 20, cx, cy, "YesNo" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "YesNoCancelMsgBoxRadioBtn", x, y + 25, cx, cy, "YesNoCancel" 'MessageBox Default button x = 55 y = 15 cx = 40 cy = 5 wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "defaultBtn1", x, y, cx, cy, "DefaultBtn1" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "defaultBtn2", x, y + 5, cx, cy, "DefaultBtn2" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "defaultBtn3", x, y + 10, cx, cy, "DefaultBtn3" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "defaultBtn4", x, y + 15, cx, cy, "DefaultBtn4" 'MessageBox Icon x = 55 y = 40 cx = 40 cy = 5 wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "exclamationIcon", x, y, cx, cy, "Exclamation" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "informationIcon", x, y + 5, cx, cy, "Information" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "questionIcon", x, y + 10, cx, cy, "Question" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "errorIcon", x, y + 15, cx, cy, "Error" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "noIcon", x, y + 20, cx, cy, "NoIcon" 'Caption and text x = 5 y = 65 cx = 40 cy = 7 wsFactory.CreateWidget WS_LABEL, 0, "msgBoxTextLabel", x, y, cx, cy, "MsgBox Text" wsFactory.CreateWidget WS_FIELD, 0, "msgBoxText", x, y + cy, cx, cy, "Test" wsFactory.CreateWidget WS_LABEL, 0, "msgBoxCaptionLabel", x, y + cy * 2, cx, cy, "MsgBox Caption" wsFactory.CreateWidget WS_FIELD, 0, "msgBoxCaption", x, y + cy * 3, cx, cy, "Caption Test" wsWidget.ModifyInputDevicesByName "msgBoxText", 0, WS_FIELD_ID_DISABLE_SCAN wsWidget.ModifyInputDevicesByName "msgBoxCaption", 0, WS_FIELD_ID_DISABLE_SCAN 'Options group wsWidget.SetGroupIdByName "okMsgBoxRadioBtn", 1 wsWidget.SetGroupIdByName "okCancelMsgBoxRadioBtn", 1 wsWidget.SetGroupIdByName "ariMsgBoxRadioBtn", 1 wsWidget.SetGroupIdByName "RetryCancelMsgBoxRadioBtn", 1 wsWidget.SetGroupIdByName "YesNoMsgBoxRadioBtn", 1 wsWidget.SetGroupIdByName "YesNoCancelMsgBoxRadioBtn", 1 'Default Button group wsWidget.SetGroupIdByName "defaultBtn1", 2 wsWidget.SetGroupIdByName "defaultBtn2", 2 wsWidget.SetGroupIdByName "defaultBtn3", 2 wsWidget.SetGroupIdByName "defaultBtn4", 2 'Icon group wsWidget.SetGroupIdByName "exclamationIcon", 3 wsWidget.SetGroupIdByName "informationIcon", 3 wsWidget.SetGroupIdByName "questionIcon", 3 wsWidget.SetGroupIdByName "errorIcon", 3 wsWidget.SetGroupIdByName "noIcon", 3 wsFactory.CreateCustomFont 1, 14, True, False, False, "Times New Roman", WS_CENTER wsFactory.CreateCustomFont 2, 13, False, False, False, "Arial", WS_LEFT wsFactory.LoadExternalIcon 3, WS_EXIT, "iconlib.dll" wsFactory.LoadExternalIcon 4, WS_RELOAD, "iconlib.dll" wsFactory.LoadExternalIcon 5, WS_SEARCH, "iconlib.dll" wsWidget.SetIconByName "ExitButton", 3 wsWidget.SetIconByName "resetBtn", 4 wsWidget.SetIconByName "showMessageBoxBtn", 5 wsForm.AddObjectByName "myForm", "FormTittle" wsForm.AddObjectByName "myForm", "ExitButton" wsForm.AddObjectByName "myForm", "showMessageBoxBtn" wsForm.AddObjectByName "myForm", "okMsgBoxRadioBtn" wsForm.AddObjectByName "myForm", "okCancelMsgBoxRadioBtn" wsForm.AddObjectByName "myForm", "ariMsgBoxRadioBtn" wsForm.AddObjectByName "myForm", "RetryCancelMsgBoxRadioBtn" wsForm.AddObjectByName "myForm", "YesNoMsgBoxRadioBtn" wsForm.AddObjectByName "myForm", "YesNoCancelMsgBoxRadioBtn" wsForm.AddObjectByName "myForm", "defaultBtn1" wsForm.AddObjectByName "myForm", "defaultBtn2" wsForm.AddObjectByName "myForm", "defaultBtn3" wsForm.AddObjectByName "myForm", "defaultBtn4" wsForm.AddObjectByName "myForm", "exclamationIcon" wsForm.AddObjectByName "myForm", "informationIcon" wsForm.AddObjectByName "myForm", "questionIcon" wsForm.AddObjectByName "myForm", "errorIcon" wsForm.AddObjectByName "myForm", "noIcon" wsForm.AddObjectByName "myForm", "msgBoxText" wsForm.AddObjectByName "myForm", "msgBoxCaption" wsForm.AddObjectByName "myForm", "msgBoxTextLabel" wsForm.AddObjectByName "myForm", "msgBoxCaptionLabel" wsForm.AddObjectByName "myForm", "msgBoxResultLabel" wsForm.AddObjectByName "myForm", "resetBtn" 'Enables the submit mode on the main button, the texts of the ' msgBoxText and msgBoxCaption fields will be sent before ' the click event on the showMessageBoxBtn is processed wsWidget.EnableSubmitModeByName "showMessageBoxBtn", True 'Font customization wsWidget.SetFontByName "okMsgBoxRadioBtn", 2 wsWidget.SetFontByName "okCancelMsgBoxRadioBtn", 2 wsWidget.SetFontByName "ariMsgBoxRadioBtn", 2 wsWidget.SetFontByName "RetryCancelMsgBoxRadioBtn", 2 wsWidget.SetFontByName "YesNoMsgBoxRadioBtn", 2 wsWidget.SetFontByName "YesNoCancelMsgBoxRadioBtn", 2 wsWidget.SetFontByName "defaultBtn1", 2 wsWidget.SetFontByName "defaultBtn2", 2 wsWidget.SetFontByName "defaultBtn3", 2 wsWidget.SetFontByName "defaultBtn4", 2 wsWidget.SetFontByName "exclamationIcon", 2 wsWidget.SetFontByName "informationIcon", 2 wsWidget.SetFontByName "questionIcon", 2 wsWidget.SetFontByName "errorIcon", 2 wsWidget.SetFontByName "noIcon", 2 wsWidget.SetFontByName "msgBoxResultLabel", 2 wsWidget.SetStateByName "okMsgBoxRadioBtn", WS_STATE_CHECKED wsWidget.SetStateByName "defaultBtn1", WS_STATE_CHECKED wsWidget.SetStateByName "exclamationIcon", WS_STATE_CHECKED iIcon = WS_MSG_BOX_ICON_EXCLAMATION wsWidget.SetFontByName "FormTittle", 1 wsWidget.SetFontByName "ExitButton", 1 wsForm.ShowByName "myForm", True, True bResult = True While (bEnd = False And bResult) bResult = wsForm.GetEvent() sObjectName = wsForm.GetLastEventSourceName() If sObjectName = "showMessageBoxBtn" Then sMsgBoxTest = wsWidget.GetTextByName("msgBoxText") sMsgBoxCaption = wsWidget.GetTextByName("msgBoxCaption") iMsgBoxResult = wsForm.ShowMessageBox(sMsgBoxTest, sMsgBoxCaption, iOptions, iDefaultAs, iIcon) wsWidget.SetTextByName "msgBoxResultLabel", "Result: " + MapResultValueToString(iMsgBoxResult) End If If sObjectName = "resetBtn" Then bResult = wsForm.RestoreInitialState() End If 'Checks the current options If wsWidget.GetStateByName("okMsgBoxRadioBtn") = WS_STATE_CHECKED Then iOptions = WS_MSG_BOX_OP_OK ElseIf wsWidget.GetStateByName("okCancelMsgBoxRadioBtn") = WS_STATE_CHECKED Then iOptions = WS_MSG_BOX_OP_OKCANCEL ElseIf wsWidget.GetStateByName("ariMsgBoxRadioBtn") = WS_STATE_CHECKED Then iOptions = WS_MSG_BOX_OP_ABORTRETRYIGNORE ElseIf wsWidget.GetStateByName("RetryCancelMsgBoxRadioBtn") = WS_STATE_CHECKED Then iOptions = WS_MSG_BOX_OP_RETRYCANCEL ElseIf wsWidget.GetStateByName("YesNoMsgBoxRadioBtn") = WS_STATE_CHECKED Then iOptions = WS_MSG_BOX_OP_YESNO ElseIf wsWidget.GetStateByName("YesNoCancelMsgBoxRadioBtn") = WS_STATE_CHECKED Then iOptions = WS_MSG_BOX_OP_YESNOCANCEL Else iOptions = WS_MSG_BOX_OP_OK End If 'Checks the default button If wsWidget.GetStateByName("defaultBtn1") = WS_STATE_CHECKED Then iDefaultAs = WS_MSG_BOX_DEFBUTTON1 ElseIf wsWidget.GetStateByName("defaultBtn2") = WS_STATE_CHECKED Then iDefaultAs = WS_MSG_BOX_DEFBUTTON2 ElseIf wsWidget.GetStateByName("defaultBtn3") = WS_STATE_CHECKED Then iDefaultAs = WS_MSG_BOX_DEFBUTTON3 ElseIf wsWidget.GetStateByName("defaultBtn4") = WS_STATE_CHECKED Then iDefaultAs = WS_MSG_BOX_DEFBUTTON4 End If If wsWidget.GetStateByName("exclamationIcon") = WS_STATE_CHECKED Then iIcon = WS_MSG_BOX_ICON_EXCLAMATION ElseIf wsWidget.GetStateByName("informationIcon") = WS_STATE_CHECKED Then iIcon = WS_MSG_BOX_ICON_INFORMATION ElseIf wsWidget.GetStateByName("questionIcon") = WS_STATE_CHECKED Then iIcon = WS_MSG_BOX_ICON_QUESTION ElseIf wsWidget.GetStateByName("errorIcon") = WS_STATE_CHECKED Then iIcon = WS_MSG_BOX_ICON_ERROR ElseIf wsWidget.GetStateByName("noIcon") = WS_STATE_CHECKED Then iIcon = 0 End If If sObjectName = "ExitButton" Or wsForm.GetLastEventIntValue() = WS_ESC Then bEnd = True End If Wend EndProgram: End Sub Public Function MapResultValueToString(iMsgBoxResult As Integer) As String Select Case iMsgBoxResult Case WS_MSG_BOX_RET_VAL_ABORT MapResultValueToString = "Abort" Case WS_MSG_BOX_RET_VAL_CANCEL MapResultValueToString = "Cancel" Case WS_MSG_BOX_RET_VAL_IGNORE MapResultValueToString = "Ignore" Case WS_MSG_BOX_RET_VAL_NO MapResultValueToString = "No" Case WS_MSG_BOX_RET_VAL_OK MapResultValueToString = "Ok" Case WS_MSG_BOX_RET_VAL_RETRY MapResultValueToString = "Retry" Case WS_MSG_BOX_RET_VAL_YES MapResultValueToString = "Yes" Case Else MapResultValueToString = "Function has failed" End Select End Function