McBasic™Get McBasic™ ↗
Build 881
Hands-on tutorial · Data & services

Exercise exported desktop services

Check the complete dialog, clipboard, media and report sample before and after Windows or Linux export.

3 Form / control designs3 complete BASIC filesGuided sample project

This sample exercises system integration, so Check on Mac is only the first gate. Inspect every resource and handler below. On Windows, test native dialogs, codec-dependent audio/video and report printing. On Linux L1, audio/video and four CommonDialog operations are unavailable: their refusal is an expected boundary, not successful playback. Reports.Print opens a temporary PDF viewer instead of a native print dialog. Keep the app open while inspecting that temporary document. Do not run clipboard-changing actions until you have preserved anything important in the clipboard.

Step 1Prepare a safe practice project#

Extract the archive into a new writable folder, separate from your own application. Open WindowsServicesTest.mcbproj in McBasic™. Keep every declared source, layout, resource and migration file together.

To reconstruct it yourself, create a DesktopApp project and add the files declared below. In the complete project, follow these steps as a guided rebuild: replace each named source file once and Check after all its procedures are present.

Exact project configuration
project.mcproj
{
  "schemaVersion": 1,
  "projectId": "ab3e7724-fb71-4b4e-a5b1-5a9efe266bf3",
  "name": "WindowsServicesTest",
  "kind": "DesktopApp",
  "ai": {
    "storeChatsInProject": false
  },
  "language": {
    "dialect": "McBasic1",
    "requireExplicit": true,
    "compare": "Binary",
    "defaultArrayBase": 0
  },
  "application": {
    "bundleIdentifier": "com.mcbasic.samples.windowsservicestest",
    "version": "0.1.0",
    "buildNumber": "1",
    "appearance": "macOS",
    "startupFormId": "form-main",
    "shutdownMode": "OnStartupFormClosed"
  },
  "forms": [
    {
      "id": "form-main",
      "typeName": "frmMain",
      "layout": "Forms/frmMain.form.json",
      "code": "Forms/frmMain.bas"
    },
    {
      "id": "form-second",
      "typeName": "frmSecond",
      "layout": "Forms/frmSecond.form.json",
      "code": "Forms/frmSecond.bas"
    },
    {
      "id": "form-nobox",
      "typeName": "frmNoBox",
      "layout": "Forms/frmNoBox.form.json",
      "code": "Forms/frmNoBox.bas"
    }
  ],
  "modules": [],
  "classes": [],
  "tests": [],
  "references": [],
  "resources": [
    {
      "name": "Tone",
      "path": "Resources/tone.wav"
    },
    {
      "name": "HelloReport",
      "path": "Resources/Reports/Hello.report.json"
    },
    {
      "name": "DemoVideo",
      "path": "Resources/demo.mp4"
    }
  ],
  "targets": [
    "osx-arm64"
  ],
  "capabilities": []
}

Step 2Build the Form and set its properties#

frmMain

Select the Form first and set its properties. Add containers before their children. These are initial Designer values, not statements to paste into a procedure.

Form propertyValue
Caption"Windows Services Test"
Width1110
Height560
MinWidth600
MinHeight480
TypeNameParent
LabellblStatusForm
CommandButtoncmdMsgOkForm
CommandButtoncmdMsgYncForm
CommandButtoncmdMsgCritForm
CommandButtoncmdMsgExclForm
CommandButtoncmdMsgInfoForm
CommandButtoncmdInputForm
CommandButtoncmdOpenForm
CommandButtoncmdSaveForm
CommandButtoncmdFolderForm
CommandButtoncmdColorForm
CommandButtoncmdFontForm
CommandButtoncmdPrinterForm
CommandButtoncmdPageSetupForm
CommandButtoncmdClipForm
CommandButtoncmdUrlForm
CommandButtoncmdPlayForm
CommandButtoncmdPauseForm
CommandButtoncmdStopForm
CommandButtoncmdSeekForm
CommandButtoncmdVolForm
CommandButtoncmdSecondForm
CommandButtoncmdErrorForm
CommandButtoncmdNoBoxForm
CommandButtoncmdReportForm
PanelpnlColorForm
LabellblFontSampleForm
AudioPlayeraudToneForm
LabellblNotesForm
VideoPlayervidDemoForm
CommandButtoncmdVidPlayForm
CommandButtoncmdVidPauseForm
CommandButtoncmdVidStopForm
CommandButtoncmdVidPosForm
CommandButtoncmdVidVolForm
CommandButtoncmdVidLoopForm
CommandButtoncmdVidStretchForm
LabellblVideoNotesForm
CommonDialogdlgCommonComponent tray
MenuItemmnuFileComponent tray
MenuItemmnuFileOpenComponent tray
MenuItemmnuFileSaveComponent tray
MenuItemmnuFileSep1Component tray
MenuItemmnuFileExitComponent tray
MenuItemmnuEditComponent tray
MenuItemmnuEditCopyComponent tray
MenuItemmnuEditPasteComponent tray
lblStatus · exact Inspector values
PropertyValue
Left20
Top14
Width680
Height44
Caption"Choose a service. The result appears here."
ForeColor"#263238"
Anchor edgesLeft, Top, Right
cmdMsgOk · exact Inspector values
PropertyValue
Left20
Top70
Width164
Height36
Caption"MsgBox OK only"
TabIndex0
Anchor edgesLeft, Top
cmdMsgYnc · exact Inspector values
PropertyValue
Left192
Top70
Width164
Height36
Caption"MsgBox Yes/No/Cancel"
TabIndex1
Anchor edgesLeft, Top
cmdMsgCrit · exact Inspector values
PropertyValue
Left364
Top70
Width164
Height36
Caption"MsgBox Critical"
TabIndex2
Anchor edgesLeft, Top
cmdMsgExcl · exact Inspector values
PropertyValue
Left536
Top70
Width164
Height36
Caption"MsgBox Exclamation"
TabIndex3
Anchor edgesLeft, Top
cmdMsgInfo · exact Inspector values
PropertyValue
Left20
Top114
Width164
Height36
Caption"MsgBox Information"
TabIndex4
Anchor edgesLeft, Top
cmdInput · exact Inspector values
PropertyValue
Left192
Top114
Width164
Height36
Caption"InputBox"
TabIndex5
Anchor edgesLeft, Top
cmdOpen · exact Inspector values
PropertyValue
Left364
Top114
Width164
Height36
Caption"ShowOpen"
TabIndex6
Anchor edgesLeft, Top
cmdSave · exact Inspector values
PropertyValue
Left536
Top114
Width164
Height36
Caption"ShowSave"
TabIndex7
Anchor edgesLeft, Top
cmdFolder · exact Inspector values
PropertyValue
Left20
Top158
Width164
Height36
Caption"ShowFolder"
TabIndex8
Anchor edgesLeft, Top
cmdColor · exact Inspector values
PropertyValue
Left192
Top158
Width164
Height36
Caption"ShowColor"
TabIndex9
Anchor edgesLeft, Top
cmdFont · exact Inspector values
PropertyValue
Left364
Top158
Width164
Height36
Caption"ShowFont"
TabIndex10
Anchor edgesLeft, Top
cmdPrinter · exact Inspector values
PropertyValue
Left536
Top158
Width164
Height36
Caption"ShowPrinter"
TabIndex11
Anchor edgesLeft, Top
cmdPageSetup · exact Inspector values
PropertyValue
Left20
Top202
Width164
Height36
Caption"ShowPageSetup"
TabIndex12
Anchor edgesLeft, Top
cmdClip · exact Inspector values
PropertyValue
Left192
Top202
Width164
Height36
Caption"Clipboard round trip"
TabIndex13
Anchor edgesLeft, Top
cmdUrl · exact Inspector values
PropertyValue
Left364
Top202
Width164
Height36
Caption"Open mcbasic.com"
TabIndex14
Anchor edgesLeft, Top
cmdPlay · exact Inspector values
PropertyValue
Left536
Top202
Width164
Height36
Caption"Play"
TabIndex15
Anchor edgesLeft, Top
cmdPause · exact Inspector values
PropertyValue
Left20
Top246
Width164
Height36
Caption"Pause"
TabIndex16
Anchor edgesLeft, Top
cmdStop · exact Inspector values
PropertyValue
Left192
Top246
Width164
Height36
Caption"Stop"
TabIndex17
Anchor edgesLeft, Top
cmdSeek · exact Inspector values
PropertyValue
Left364
Top246
Width164
Height36
Caption"Position 0.5 + Play"
TabIndex18
Anchor edgesLeft, Top
cmdVol · exact Inspector values
PropertyValue
Left536
Top246
Width164
Height36
Caption"Volume 0.5"
TabIndex19
Anchor edgesLeft, Top
cmdSecond · exact Inspector values
PropertyValue
Left20
Top290
Width164
Height36
Caption"Open second form"
TabIndex20
Anchor edgesLeft, Top
cmdError · exact Inspector values
PropertyValue
Left192
Top290
Width164
Height36
Caption"Raise error 5"
TabIndex21
Anchor edgesLeft, Top
cmdNoBox · exact Inspector values
PropertyValue
Left364
Top290
Width164
Height36
Caption"Open form without box"
TabIndex22
Anchor edgesLeft, Top
cmdReport · exact Inspector values
PropertyValue
Left536
Top290
Width164
Height36
Caption"Print report"
TabIndex23
Anchor edgesLeft, Top
pnlColor · exact Inspector values
PropertyValue
Left20
Top344
Width120
Height44
BackColor"#EEEEEE"
Anchor edgesLeft, Top
lblFontSample · exact Inspector values
PropertyValue
Left152
Top344
Width548
Height44
Caption"Sample text for ShowFont"
Anchor edgesLeft, Top
audTone · exact Inspector values
PropertyValue
Left20
Top400
Width680
Height60
Source"Tone"
AutoPlayFalse
LoopFalse
Volume0.8
Anchor edgesLeft, Top, Right
lblNotes · exact Inspector values
PropertyValue
Left20
Top468
Width680
Height76
Caption"Also check: Alt+F opens File and Alt+E opens Edit (underlined letters); Help > About WindowsServicesTest; the second form has About in its system menu (Alt+Space) and a disabled Minimize button; the form without box has a Help > About menu bar. MDI keys: publish the MdiForms sample."
ForeColor"#455A64"
Anchor edgesLeft, Top, Right
vidDemo · exact Inspector values
PropertyValue
Left720
Top70
Width370
Height250
Source"DemoVideo"
AutoPlayFalse
LoopFalse
Volume0.8
ControlsVisibleTrue
Stretch"Uniform"
Anchor edgesLeft, Top
cmdVidPlay · exact Inspector values
PropertyValue
Left720
Top334
Width180
Height36
Caption"Video Play"
TabIndex24
Anchor edgesLeft, Top
cmdVidPause · exact Inspector values
PropertyValue
Left910
Top334
Width180
Height36
Caption"Video Pause"
TabIndex25
Anchor edgesLeft, Top
cmdVidStop · exact Inspector values
PropertyValue
Left720
Top378
Width180
Height36
Caption"Video Stop"
TabIndex26
Anchor edgesLeft, Top
cmdVidPos · exact Inspector values
PropertyValue
Left910
Top378
Width180
Height36
Caption"Video Position 0.5"
TabIndex27
Anchor edgesLeft, Top
cmdVidVol · exact Inspector values
PropertyValue
Left720
Top422
Width180
Height36
Caption"Video Volume 0.3"
TabIndex28
Anchor edgesLeft, Top
cmdVidLoop · exact Inspector values
PropertyValue
Left910
Top422
Width180
Height36
Caption"Video Loop on/off"
TabIndex29
Anchor edgesLeft, Top
cmdVidStretch · exact Inspector values
PropertyValue
Left720
Top466
Width180
Height36
Caption"Video Stretch next"
TabIndex30
Anchor edgesLeft, Top
lblVideoNotes · exact Inspector values
PropertyValue
Left910
Top466
Width180
Height80
Caption"Video check: the clip shows in the black area with the Play bar below it; Stretch cycles Uniform, Fill, UniformToFill; Loop repeats it. The clip has no sound track."
ForeColor"#455A64"
Anchor edgesLeft, Top
dlgCommon · exact Inspector values
PropertyValue
Title"Windows Services Test"
Filter"Text files|*.txt;*.md"
FileName"notes.txt"
Color"#1565C0"
Font"System|13|Regular|Normal"
PrinterName""
PaperName""
PageOrientation"Portrait"
PageWidth612
PageHeight792
mnuFile · exact Inspector values
PropertyValue
Caption"&File"
Parent""
Order0
mnuFileOpen · exact Inspector values
PropertyValue
Caption"&Open…"
Parent"mnu-file"
Order0
Shortcut"Ctrl+O"
mnuFileSave · exact Inspector values
PropertyValue
Caption"&Save…"
Parent"mnu-file"
Order1
Shortcut"Ctrl+S"
mnuFileSep1 · exact Inspector values
PropertyValue
Caption"-"
Parent"mnu-file"
Order2
mnuFileExit · exact Inspector values
PropertyValue
Caption"E&xit"
Parent"mnu-file"
Order3
mnuEdit · exact Inspector values
PropertyValue
Caption"&Edit"
Parent""
Order1
mnuEditCopy · exact Inspector values
PropertyValue
Caption"&Copy"
Parent"mnu-edit"
Order0
Shortcut"Ctrl+C"
mnuEditPaste · exact Inspector values
PropertyValue
Caption"&Paste"
Parent"mnu-edit"
Order1
Shortcut"Ctrl+V"

frmSecond

Select the Form first and set its properties. Add containers before their children. These are initial Designer values, not statements to paste into a procedure.

Form propertyValue
Caption"Second form"
Width360
Height200
MinButtonFalse
TypeNameParent
LabellblInfoForm
CommandButtoncmdCloseForm
lblInfo · exact Inspector values
PropertyValue
Left20
Top20
Width320
Height80
Caption"Opened modelessly. Minimize is disabled (MinButton = False). Alt+Space, or the icon at the left of the title bar, opens the system menu with About WindowsServicesTest."
cmdClose · exact Inspector values
PropertyValue
Left20
Top120
Width120
Height36
Caption"Close"

frmNoBox

Select the Form first and set its properties. Add containers before their children. These are initial Designer values, not statements to paste into a procedure.

Form propertyValue
Caption"Form without control box"
Width380
Height200
ControlBoxFalse
TypeNameParent
LabellblInfoForm
CommandButtoncmdCloseForm
lblInfo · exact Inspector values
PropertyValue
Left20
Top20
Width340
Height80
Caption"ControlBox = False: no system menu and no Close button. On Windows the form shows a menu bar with only Help > About WindowsServicesTest, so the About stays reachable."
cmdClose · exact Inspector values
PropertyValue
Left20
Top120
Width120
Height36
Caption"Close"

Step 3Connect the events explicitly#

frmMain

ObjectEventProcedureParameters
cmdMsgOkClickcmdMsgOk_ClickClick()
cmdMsgYncClickcmdMsgYnc_ClickClick()
cmdMsgCritClickcmdMsgCrit_ClickClick()
cmdMsgExclClickcmdMsgExcl_ClickClick()
cmdMsgInfoClickcmdMsgInfo_ClickClick()
cmdInputClickcmdInput_ClickClick()
cmdOpenClickcmdOpen_ClickClick()
cmdSaveClickcmdSave_ClickClick()
cmdFolderClickcmdFolder_ClickClick()
cmdColorClickcmdColor_ClickClick()
cmdFontClickcmdFont_ClickClick()
cmdPrinterClickcmdPrinter_ClickClick()
cmdPageSetupClickcmdPageSetup_ClickClick()
cmdClipClickcmdClip_ClickClick()
cmdUrlClickcmdUrl_ClickClick()
cmdPlayClickcmdPlay_ClickClick()
cmdPauseClickcmdPause_ClickClick()
cmdStopClickcmdStop_ClickClick()
cmdSeekClickcmdSeek_ClickClick()
cmdVolClickcmdVol_ClickClick()
cmdSecondClickcmdSecond_ClickClick()
cmdErrorClickcmdError_ClickClick()
cmdNoBoxClickcmdNoBox_ClickClick()
cmdReportClickcmdReport_ClickClick()
audToneFailedaudTone_FailedFailed()
audToneCompletedaudTone_CompletedCompleted()
vidDemoLoadedvidDemo_LoadedLoaded()
vidDemoCompletedvidDemo_CompletedCompleted()
vidDemoFailedvidDemo_FailedFailed()
vidDemoStateChangedvidDemo_StateChangedStateChanged()
cmdVidPlayClickcmdVidPlay_ClickClick()
cmdVidPauseClickcmdVidPause_ClickClick()
cmdVidStopClickcmdVidStop_ClickClick()
cmdVidPosClickcmdVidPos_ClickClick()
cmdVidVolClickcmdVidVol_ClickClick()
cmdVidLoopClickcmdVidLoop_ClickClick()
cmdVidStretchClickcmdVidStretch_ClickClick()
mnuFileOpenClickmnuFileOpen_ClickClick()
mnuFileSaveClickmnuFileSave_ClickClick()
mnuFileExitClickmnuFileExit_ClickClick()
mnuEditCopyClickmnuEditCopy_ClickClick()
mnuEditPasteClickmnuEditPaste_ClickClick()
FormLoadForm_Load()

frmSecond

ObjectEventProcedureParameters
cmdCloseClickcmdClose_ClickClick()

frmNoBox

ObjectEventProcedureParameters
cmdCloseClickcmdClose_ClickClick()

Step 4Enter the complete behavior#

Open the named source file. Enter declarations first, then every procedure. Expand a procedure for its full body, or copy the complete file. Helpers are required: do not stop after entering the first Click handler.

Forms/frmMain.bas

Enter these declarations at file scope, before the procedures.

Forms/frmMain.bas · declarations
Option Explicit

' frmMain: tries every platform service on one form (dialogs, clipboard, URL, audio, video, menus, a second form, a run-time error).
' Each action writes its result to lblStatus, so no MsgBox is needed to read it (the MsgBox buttons show the value they return).

' Shows a short ready message when the form loads.
Private Sub Form_Load()

Initialize state before enabling dependent actions. Keep the shared declarations and startup dependencies with this procedure.

Forms/frmMain.bas · Form_Load
Private Sub Form_Load()
    lblStatus.Caption = "Ready. Audio state: " + audTone.State
End Sub
Private Sub ShowMsgResult(ByVal Style As String, ByVal Result As Long)

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · ShowMsgResult
Private Sub ShowMsgResult(ByVal Style As String, ByVal Result As Long)
    lblStatus.Caption = Style + " returned " + CStr(Result)
End Sub
Private Sub ShowDialogResult(ByVal Value As String)

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · ShowDialogResult
Private Sub ShowDialogResult(ByVal Value As String)
    If dlgCommon.Cancelled Then
        lblStatus.Caption = dlgCommon.LastAction + " cancelled"
    Else
        lblStatus.Caption = dlgCommon.LastAction + ": " + Value
    End If
End Sub
Private Sub cmdMsgOk_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdMsgOk_Click
Private Sub cmdMsgOk_Click()
    ShowMsgResult "OK only", MsgBox("This is a message with an OK button.", vbOKOnly, "Windows Services Test")
End Sub
Private Sub cmdMsgYnc_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdMsgYnc_Click
Private Sub cmdMsgYnc_Click()
    ShowMsgResult "Yes/No/Cancel", MsgBox("Do you want to continue?", vbYesNoCancel + vbQuestion + vbDefaultButton2, "Question")
End Sub
Private Sub cmdMsgCrit_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdMsgCrit_Click
Private Sub cmdMsgCrit_Click()
    ShowMsgResult "Critical", MsgBox("Something went wrong.", vbOKOnly + vbCritical, "Critical")
End Sub
Private Sub cmdMsgExcl_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdMsgExcl_Click
Private Sub cmdMsgExcl_Click()
    ShowMsgResult "Exclamation", MsgBox("Take care.", vbOKOnly + vbExclamation, "Exclamation")
End Sub
Private Sub cmdMsgInfo_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdMsgInfo_Click
Private Sub cmdMsgInfo_Click()
    ShowMsgResult "Information", MsgBox("For your information.", vbOKOnly + vbInformation, "Information")
End Sub
Private Sub cmdInput_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdInput_Click
Private Sub cmdInput_Click()
    Dim Answer As String
    Answer = InputBox("What is your name?", "InputBox", "Ada")
    lblStatus.Caption = "InputBox returned [" + Answer + "]"
End Sub
Private Sub cmdOpen_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdOpen_Click
Private Sub cmdOpen_Click()
    dlgCommon.ShowOpen
    ShowDialogResult dlgCommon.FileName
End Sub
Private Sub cmdSave_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdSave_Click
Private Sub cmdSave_Click()
    dlgCommon.ShowSave
    ShowDialogResult dlgCommon.FileName
End Sub
Private Sub cmdFolder_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdFolder_Click
Private Sub cmdFolder_Click()
    dlgCommon.ShowFolder
    ShowDialogResult dlgCommon.FileName
End Sub
Private Sub cmdColor_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdColor_Click
Private Sub cmdColor_Click()
    dlgCommon.ShowColor
    If Not dlgCommon.Cancelled Then pnlColor.BackColor = dlgCommon.Color
    ShowDialogResult dlgCommon.Color
End Sub
Private Sub cmdFont_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdFont_Click
Private Sub cmdFont_Click()
    dlgCommon.ShowFont
    If Not dlgCommon.Cancelled Then lblFontSample.Font = dlgCommon.Font
    ShowDialogResult dlgCommon.Font
End Sub
Private Sub cmdPrinter_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdPrinter_Click
Private Sub cmdPrinter_Click()
    dlgCommon.ShowPrinter
    ShowDialogResult dlgCommon.PrinterName + " / " + dlgCommon.PaperName
End Sub
Private Sub cmdPageSetup_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdPageSetup_Click
Private Sub cmdPageSetup_Click()
    dlgCommon.ShowPageSetup
    ShowDialogResult dlgCommon.PageOrientation + " " + CStr(dlgCommon.PageWidth) + " x " + CStr(dlgCommon.PageHeight)
End Sub
Private Sub cmdClip_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdClip_Click
Private Sub cmdClip_Click()
    Dim Back As String
    Clipboard.SetText "McBasic clipboard test"
    Back = Clipboard.GetText()
    lblStatus.Caption = "Clipboard has text: " + CStr(Clipboard.HasText()) + ", read back [" + Back + "]"
    Clipboard.Clear
    lblStatus.Caption = lblStatus.Caption + "; after Clear has text: " + CStr(Clipboard.HasText())
End Sub
Private Sub cmdUrl_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdUrl_Click
Private Sub cmdUrl_Click()
    Platform.OpenUrl "https://www.mcbasic.com"
    lblStatus.Caption = "Asked the system to open https://www.mcbasic.com"
End Sub
Private Sub cmdPlay_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdPlay_Click
Private Sub cmdPlay_Click()
    audTone.Play
    lblStatus.Caption = "Audio state: " + audTone.State
End Sub
Private Sub cmdPause_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdPause_Click
Private Sub cmdPause_Click()
    audTone.Pause
    lblStatus.Caption = "Audio state: " + audTone.State
End Sub
Private Sub cmdStop_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdStop_Click
Private Sub cmdStop_Click()
    audTone.Stop
    lblStatus.Caption = "Audio state: " + audTone.State
End Sub
Private Sub cmdSeek_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdSeek_Click
Private Sub cmdSeek_Click()
    audTone.Position = 0.5
    audTone.Play
    lblStatus.Caption = "Position set to 0.5 before Play; state: " + audTone.State
End Sub
Private Sub cmdVol_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdVol_Click
Private Sub cmdVol_Click()
    audTone.Volume = 0.5
    lblStatus.Caption = "Volume is " + CStr(audTone.Volume)
End Sub
Private Sub audTone_Failed()

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · audTone_Failed
Private Sub audTone_Failed()
    lblStatus.Caption = "Audio failed: " + audTone.Error
End Sub
Private Sub audTone_Completed()

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · audTone_Completed
Private Sub audTone_Completed()
    lblStatus.Caption = "Audio completed"
End Sub
Private Sub ShowVideo(ByVal Action As String)

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · ShowVideo
Private Sub ShowVideo(ByVal Action As String)
    lblStatus.Caption = Action + "; video state: " + vidDemo.State + ", position " + CStr(vidDemo.Position) + " of " + CStr(vidDemo.Duration) + " s"
End Sub
Private Sub cmdVidPlay_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdVidPlay_Click
Private Sub cmdVidPlay_Click()
    vidDemo.Play
    ShowVideo "Video Play"
End Sub
Private Sub cmdVidPause_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdVidPause_Click
Private Sub cmdVidPause_Click()
    vidDemo.Pause
    ShowVideo "Video Pause"
End Sub
Private Sub cmdVidStop_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdVidStop_Click
Private Sub cmdVidStop_Click()
    vidDemo.Stop
    ShowVideo "Video Stop"
End Sub
Private Sub cmdVidPos_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdVidPos_Click
Private Sub cmdVidPos_Click()
    vidDemo.Position = 0.5
    vidDemo.Play
    ShowVideo "Video Position 0.5 + Play"
End Sub
Private Sub cmdVidVol_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdVidVol_Click
Private Sub cmdVidVol_Click()
    vidDemo.Volume = 0.3
    lblStatus.Caption = "Video volume is " + CStr(vidDemo.Volume)
End Sub
Private Sub cmdVidLoop_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdVidLoop_Click
Private Sub cmdVidLoop_Click()
    vidDemo.Loop = Not vidDemo.Loop
    lblStatus.Caption = "Video Loop is " + CStr(vidDemo.Loop)
End Sub
Private Sub cmdVidStretch_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdVidStretch_Click
Private Sub cmdVidStretch_Click()
    If vidDemo.Stretch = "Uniform" Then
        vidDemo.Stretch = "Fill"
    ElseIf vidDemo.Stretch = "Fill" Then
        vidDemo.Stretch = "UniformToFill"
    Else
        vidDemo.Stretch = "Uniform"
    End If
    lblStatus.Caption = "Video Stretch is " + vidDemo.Stretch
End Sub
Private Sub vidDemo_Loaded()

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · vidDemo_Loaded
Private Sub vidDemo_Loaded()
    lblStatus.Caption = "Video loaded (" + CStr(vidDemo.Duration) + " s)"
End Sub
Private Sub vidDemo_Completed()

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · vidDemo_Completed
Private Sub vidDemo_Completed()
    lblStatus.Caption = "Video completed"
End Sub
Private Sub vidDemo_Failed()

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · vidDemo_Failed
Private Sub vidDemo_Failed()
    lblStatus.Caption = "Video failed: " + vidDemo.Error
End Sub
Private Sub vidDemo_StateChanged()

Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.

Forms/frmMain.bas · vidDemo_StateChanged
Private Sub vidDemo_StateChanged()
    lblStatus.Caption = "Video state: " + vidDemo.State
End Sub
Private Sub cmdSecond_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdSecond_Click
Private Sub cmdSecond_Click()
    Dim f As frmSecond
    Set f = New frmSecond
    f.Show
    lblStatus.Caption = "Second form opened (modeless)"
End Sub
Private Sub cmdNoBox_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdNoBox_Click
Private Sub cmdNoBox_Click()
    Dim f As frmNoBox
    Set f = New frmNoBox
    f.Show
    lblStatus.Caption = "Form without control box opened"
End Sub
Private Sub cmdReport_Click()

Follow the success, failure and cleanup paths together. Do not omit a guard or Finally block when entering this procedure.

Forms/frmMain.bas · cmdReport_Click
Private Sub cmdReport_Click()
    Try
        If Reports.Print(App.ResourcePath & "/Resources/Reports/Hello.report.json") Then
            lblStatus.Caption = "Report sent to the printer"
        Else
            lblStatus.Caption = "Report printing cancelled"
        End If
    Catch failure As McException
        lblStatus.Caption = "Report failed " & CStr(failure.Number) & ": " & failure.Message
    End Try
End Sub
Private Sub cmdError_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdError_Click
Private Sub cmdError_Click()
    Err.Raise 5, "WindowsServicesTest", "This error was raised on purpose."
End Sub
Private Sub mnuFileOpen_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · mnuFileOpen_Click
Private Sub mnuFileOpen_Click()
    lblStatus.Caption = "Menu: File > Open"
End Sub
Private Sub mnuFileSave_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · mnuFileSave_Click
Private Sub mnuFileSave_Click()
    lblStatus.Caption = "Menu: File > Save"
End Sub
Private Sub mnuFileExit_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · mnuFileExit_Click
Private Sub mnuFileExit_Click()
    lblStatus.Caption = "Menu: File > Exit"
    Unload Me
End Sub
Private Sub mnuEditCopy_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · mnuEditCopy_Click
Private Sub mnuEditCopy_Click()
    lblStatus.Caption = "Menu: Edit > Copy"
End Sub
Private Sub mnuEditPaste_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · mnuEditPaste_Click
Private Sub mnuEditPaste_Click()
    lblStatus.Caption = "Menu: Edit > Paste"
End Sub
Copy the complete Forms/frmMain.bas file

Replace the file once; do not append duplicate procedures.

Forms/frmMain.bas
Option Explicit

' frmMain: tries every platform service on one form (dialogs, clipboard, URL, audio, video, menus, a second form, a run-time error).
' Each action writes its result to lblStatus, so no MsgBox is needed to read it (the MsgBox buttons show the value they return).

' Shows a short ready message when the form loads.
Private Sub Form_Load()
    lblStatus.Caption = "Ready. Audio state: " + audTone.State
End Sub

' Reports the value a MsgBox returned (1 OK, 2 Cancel, 6 Yes, 7 No).
Private Sub ShowMsgResult(ByVal Style As String, ByVal Result As Long)
    lblStatus.Caption = Style + " returned " + CStr(Result)
End Sub

' Reports a CommonDialog result, or that the person cancelled.
Private Sub ShowDialogResult(ByVal Value As String)
    If dlgCommon.Cancelled Then
        lblStatus.Caption = dlgCommon.LastAction + " cancelled"
    Else
        lblStatus.Caption = dlgCommon.LastAction + ": " + Value
    End If
End Sub

' MsgBox with the OK button only.
Private Sub cmdMsgOk_Click()
    ShowMsgResult "OK only", MsgBox("This is a message with an OK button.", vbOKOnly, "Windows Services Test")
End Sub

' MsgBox with Yes, No and Cancel, a question icon and the second button (No) as default.
Private Sub cmdMsgYnc_Click()
    ShowMsgResult "Yes/No/Cancel", MsgBox("Do you want to continue?", vbYesNoCancel + vbQuestion + vbDefaultButton2, "Question")
End Sub

' MsgBox with the critical (error) icon.
Private Sub cmdMsgCrit_Click()
    ShowMsgResult "Critical", MsgBox("Something went wrong.", vbOKOnly + vbCritical, "Critical")
End Sub

' MsgBox with the exclamation (warning) icon.
Private Sub cmdMsgExcl_Click()
    ShowMsgResult "Exclamation", MsgBox("Take care.", vbOKOnly + vbExclamation, "Exclamation")
End Sub

' MsgBox with the information icon.
Private Sub cmdMsgInfo_Click()
    ShowMsgResult "Information", MsgBox("For your information.", vbOKOnly + vbInformation, "Information")
End Sub

' InputBox with a default value; Cancel returns an empty string.
Private Sub cmdInput_Click()
    Dim Answer As String
    Answer = InputBox("What is your name?", "InputBox", "Ada")
    lblStatus.Caption = "InputBox returned [" + Answer + "]"
End Sub

' Open dialog limited by the filter set on the component.
Private Sub cmdOpen_Click()
    dlgCommon.ShowOpen
    ShowDialogResult dlgCommon.FileName
End Sub

' Save dialog.
Private Sub cmdSave_Click()
    dlgCommon.ShowSave
    ShowDialogResult dlgCommon.FileName
End Sub

' Folder dialog.
Private Sub cmdFolder_Click()
    dlgCommon.ShowFolder
    ShowDialogResult dlgCommon.FileName
End Sub

' Color dialog; paints the sample panel with the chosen color.
Private Sub cmdColor_Click()
    dlgCommon.ShowColor
    If Not dlgCommon.Cancelled Then pnlColor.BackColor = dlgCommon.Color
    ShowDialogResult dlgCommon.Color
End Sub

' Font dialog; applies the chosen font to the sample label.
Private Sub cmdFont_Click()
    dlgCommon.ShowFont
    If Not dlgCommon.Cancelled Then lblFontSample.Font = dlgCommon.Font
    ShowDialogResult dlgCommon.Font
End Sub

' Print dialog; shows the printer and paper it returned.
Private Sub cmdPrinter_Click()
    dlgCommon.ShowPrinter
    ShowDialogResult dlgCommon.PrinterName + " / " + dlgCommon.PaperName
End Sub

' Page setup dialog; shows orientation and page size.
Private Sub cmdPageSetup_Click()
    dlgCommon.ShowPageSetup
    ShowDialogResult dlgCommon.PageOrientation + " " + CStr(dlgCommon.PageWidth) + " x " + CStr(dlgCommon.PageHeight)
End Sub

' Clipboard round trip: set, test, read, clear, test again.
Private Sub cmdClip_Click()
    Dim Back As String
    Clipboard.SetText "McBasic clipboard test"
    Back = Clipboard.GetText()
    lblStatus.Caption = "Clipboard has text: " + CStr(Clipboard.HasText()) + ", read back [" + Back + "]"
    Clipboard.Clear
    lblStatus.Caption = lblStatus.Caption + "; after Clear has text: " + CStr(Clipboard.HasText())
End Sub

' Opens the McBasic web site in the default browser.
Private Sub cmdUrl_Click()
    Platform.OpenUrl "https://www.mcbasic.com"
    lblStatus.Caption = "Asked the system to open https://www.mcbasic.com"
End Sub

' Starts the audio from the beginning.
Private Sub cmdPlay_Click()
    audTone.Play
    lblStatus.Caption = "Audio state: " + audTone.State
End Sub

' Pauses the audio.
Private Sub cmdPause_Click()
    audTone.Pause
    lblStatus.Caption = "Audio state: " + audTone.State
End Sub

' Stops the audio.
Private Sub cmdStop_Click()
    audTone.Stop
    lblStatus.Caption = "Audio state: " + audTone.State
End Sub

' Sets Position to 0.5 seconds before Play (must not fail), then plays.
Private Sub cmdSeek_Click()
    audTone.Position = 0.5
    audTone.Play
    lblStatus.Caption = "Position set to 0.5 before Play; state: " + audTone.State
End Sub

' Sets the player volume to half.
Private Sub cmdVol_Click()
    audTone.Volume = 0.5
    lblStatus.Caption = "Volume is " + CStr(audTone.Volume)
End Sub

' Reports an audio error text.
Private Sub audTone_Failed()
    lblStatus.Caption = "Audio failed: " + audTone.Error
End Sub

' Reports that playback reached the end.
Private Sub audTone_Completed()
    lblStatus.Caption = "Audio completed"
End Sub

' Shows the video state, with the position while it plays.
Private Sub ShowVideo(ByVal Action As String)
    lblStatus.Caption = Action + "; video state: " + vidDemo.State + ", position " + CStr(vidDemo.Position) + " of " + CStr(vidDemo.Duration) + " s"
End Sub

' Plays the one-second demo clip (a resumed pause continues where it stopped).
Private Sub cmdVidPlay_Click()
    vidDemo.Play
    ShowVideo "Video Play"
End Sub

' Pauses the clip.
Private Sub cmdVidPause_Click()
    vidDemo.Pause
    ShowVideo "Video Pause"
End Sub

' Stops the clip and rewinds it.
Private Sub cmdVidStop_Click()
    vidDemo.Stop
    ShowVideo "Video Stop"
End Sub

' Moves to half a second (the clip is one second long), then plays from there.
Private Sub cmdVidPos_Click()
    vidDemo.Position = 0.5
    vidDemo.Play
    ShowVideo "Video Position 0.5 + Play"
End Sub

' Sets the video volume to 0.3 (the demo clip has no sound track, so this only proves the call works).
Private Sub cmdVidVol_Click()
    vidDemo.Volume = 0.3
    lblStatus.Caption = "Video volume is " + CStr(vidDemo.Volume)
End Sub

' Turns Loop on or off; with Loop on the clip restarts at the end until Pause or Stop.
Private Sub cmdVidLoop_Click()
    vidDemo.Loop = Not vidDemo.Loop
    lblStatus.Caption = "Video Loop is " + CStr(vidDemo.Loop)
End Sub

' Cycles Stretch: Uniform, Fill, UniformToFill, then Uniform again.
Private Sub cmdVidStretch_Click()
    If vidDemo.Stretch = "Uniform" Then
        vidDemo.Stretch = "Fill"
    ElseIf vidDemo.Stretch = "Fill" Then
        vidDemo.Stretch = "UniformToFill"
    Else
        vidDemo.Stretch = "Uniform"
    End If
    lblStatus.Caption = "Video Stretch is " + vidDemo.Stretch
End Sub

' Reports that the clip is ready, with its length.
Private Sub vidDemo_Loaded()
    lblStatus.Caption = "Video loaded (" + CStr(vidDemo.Duration) + " s)"
End Sub

' Reports that the clip reached the end (never with Loop on).
Private Sub vidDemo_Completed()
    lblStatus.Caption = "Video completed"
End Sub

' Reports why the clip cannot play.
Private Sub vidDemo_Failed()
    lblStatus.Caption = "Video failed: " + vidDemo.Error
End Sub

' Shows each state change (Loaded, Playing, Paused, Stopped, Completed).
Private Sub vidDemo_StateChanged()
    lblStatus.Caption = "Video state: " + vidDemo.State
End Sub

' Opens the second form modelessly, so this form stays usable.
Private Sub cmdSecond_Click()
    Dim f As frmSecond
    Set f = New frmSecond
    f.Show
    lblStatus.Caption = "Second form opened (modeless)"
End Sub

' Opens a form with ControlBox = False and no menus: on Windows it gets a Help > About menu bar.
Private Sub cmdNoBox_Click()
    Dim f As frmNoBox
    Set f = New frmNoBox
    f.Show
    lblStatus.Caption = "Form without control box opened"
End Sub

' Prints a one-page report through the system print dialog (the Windows Print dialog on Windows).
' Cancel returns False; a printer error stops the call with error 5 and the reason, shown in the label.
Private Sub cmdReport_Click()
    Try
        If Reports.Print(App.ResourcePath & "/Resources/Reports/Hello.report.json") Then
            lblStatus.Caption = "Report sent to the printer"
        Else
            lblStatus.Caption = "Report printing cancelled"
        End If
    Catch failure As McException
        lblStatus.Caption = "Report failed " & CStr(failure.Number) & ": " & failure.Message
    End Try
End Sub

' Raises run-time error 5 on purpose to show the error dialog.
Private Sub cmdError_Click()
    Err.Raise 5, "WindowsServicesTest", "This error was raised on purpose."
End Sub

' File > Open (Ctrl+O).
Private Sub mnuFileOpen_Click()
    lblStatus.Caption = "Menu: File > Open"
End Sub

' File > Save (Ctrl+S).
Private Sub mnuFileSave_Click()
    lblStatus.Caption = "Menu: File > Save"
End Sub

' File > Exit closes the window.
Private Sub mnuFileExit_Click()
    lblStatus.Caption = "Menu: File > Exit"
    Unload Me
End Sub

' Edit > Copy (Ctrl+C).
Private Sub mnuEditCopy_Click()
    lblStatus.Caption = "Menu: Edit > Copy"
End Sub

' Edit > Paste (Ctrl+V).
Private Sub mnuEditPaste_Click()
    lblStatus.Caption = "Menu: Edit > Paste"
End Sub

Forms/frmSecond.bas

Enter these declarations at file scope, before the procedures.

Forms/frmSecond.bas · declarations
Option Explicit

' frmSecond: a small form that frmMain opens modelessly.

' Closes this form; the main form stays open.
Private Sub cmdClose_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmSecond.bas · cmdClose_Click
Private Sub cmdClose_Click()
    Unload Me
End Sub
Copy the complete Forms/frmSecond.bas file

Replace the file once; do not append duplicate procedures.

Forms/frmSecond.bas
Option Explicit

' frmSecond: a small form that frmMain opens modelessly.

' Closes this form; the main form stays open.
Private Sub cmdClose_Click()
    Unload Me
End Sub

Forms/frmNoBox.bas

Enter these declarations at file scope, before the procedures.

Forms/frmNoBox.bas · declarations
Option Explicit

' frmNoBox: a form with ControlBox = False and no menus. Windows gives it no system menu, so McBasic adds a menu bar
' with only Help > About; this form proves the About stays reachable.

' Closes this form (it has no Close button of its own); the main form stays open.
Private Sub cmdClose_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmNoBox.bas · cmdClose_Click
Private Sub cmdClose_Click()
    Unload Me
End Sub
Copy the complete Forms/frmNoBox.bas file

Replace the file once; do not append duplicate procedures.

Forms/frmNoBox.bas
Option Explicit

' frmNoBox: a form with ControlBox = False and no menus. Windows gives it no system menu, so McBasic adds a menu bar
' with only Help > About; this form proves the About stays reachable.

' Closes this form (it has no Close button of its own); the main form stays open.
Private Sub cmdClose_Click()
    Unload Me
End Sub

Step 5Keep resources and storage reproducible#

Keep the following files at their declared relative paths. Apply migrations before the first query. Media and report resources must travel with the build.

FilePurpose
Resources/tone.wavBundled asset / license
Resources/Reports/Hello.report.jsonStructured resource
Resources/demo.mp4Bundled asset / license
Resources/Reports/Hello.report.json
Resources/Reports/Hello.report.json
{
  "schemaVersion": 1,
  "title": "WindowsServicesTest report",
  "page": {
    "size": "A4",
    "orientation": "Portrait",
    "margin": 42
  },
  "paragraphs": [
    "A one-page report for the Windows test: Reports.Print shows the Windows Print dialog and prints this page on the chosen printer."
  ],
  "columns": [
    {
      "header": "Service",
      "weight": 2,
      "alignment": "Left"
    },
    {
      "header": "Result",
      "weight": 1,
      "alignment": "Right"
    }
  ],
  "rows": [
    ["MsgBox", "1"],
    ["Clipboard", "2"],
    ["Audio", "3"]
  ],
  "totalColumn": 1
}

Step 6Check, run and test the result#

Save all files and run Check. Resolve diagnostics before Run. Developer CLI users can work from the extracted folder:

Developer CLI
mcbasic check WindowsServicesTest.mcbproj
mcbasic run WindowsServicesTest.mcbproj

Acceptance checklist

  • Save and Check, then run the sample on the Mac as a baseline.
  • Publish for the destination architecture and transfer the artifact to a machine you control.
  • Try file and folder dialogs, including Cancel; confirm cancellation does not report a saved file.
  • Set and read a disposable clipboard value. Open only the sample URL you intend to visit.
  • Windows: test supplied media, stop/pause and close; try a report and Cancel printing.
  • Linux: confirm unavailable operations are handled, normal controls remain usable, and report handoff opens the default viewer.
  • Record OS/architecture and each observed result. A successful export alone is not an acceptance pass.

Step 7Make one change and repeat the tests#

Use Platform.IsLinux to hide unsupported actions, while retaining runtime error handling for failures on every platform.

Save a working Git checkpoint first. Change one behavior, Check again and repeat the acceptance checklist. Compare with the downloaded solution if a regression appears.

Source baseline 20f4bfed6b · Build manifest
Sources & maintenance

Original web explanation, reviewed against these repository sources. API tables and example files follow the implementation.

  • docs/manual/33-publishing-for-windows.md
  • docs/manual/34-publishing-for-linux.md
  • src/McBasic.Build/PublishTargets.cs
  • src/McBasic.Build/PlatformAvailabilityCheck.cs
  • src/McBasic.Runtime/McPlatformAvailability.cs
  • samples/WindowsServicesTest.mcbproj/Forms/frmMain.bas
  • samples/WindowsServicesTest.mcbproj/Forms/frmMain.form.json