' Multi-step wizard with Next/Back/Cancel buttons via Win32 DECLARE
#COMPILE EXE
#DIM ALL

DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" (BYVAL hWnd AS LONG, BYVAL lpText AS ASCIIZ, BYVAL lpCaption AS ASCIIZ, BYVAL uType AS LONG) AS LONG
DECLARE FUNCTION SetWindowText LIB "USER32.DLL" ALIAS "SetWindowTextA" (BYVAL hWnd AS LONG, BYVAL lpString AS ASCIIZ) AS LONG
DECLARE FUNCTION GetDlgItem LIB "USER32.DLL" (BYVAL hDlg AS LONG, BYVAL nIDDlgItem AS LONG) AS LONG
DECLARE FUNCTION EnableWindow LIB "USER32.DLL" (BYVAL hWnd AS LONG, BYVAL bEnable AS LONG) AS LONG

%MAX_STEPS = 5
%ID_NEXT   = 1000
%ID_BACK   = 1001
%ID_CANCEL = 1002
%ID_FINISH = 1003

TYPE WizardData
    step AS LONG
    name AS STRING
    email AS STRING
    projectType AS LONG
    features AS LONG
    outputDir AS STRING
    confirmed AS LONG
END TYPE

SUB InitWizard(BYREF w AS WizardData)
    w.step = 1
    w.name = ""
    w.email = ""
    w.projectType = 0
    w.features = 0
    w.outputDir = "C:\Projects"
    w.confirmed = 0
END SUB

FUNCTION CanGoNext(BYREF w AS WizardData) AS LONG
    IF w.step = 1 AND LEN(w.name) = 0 THEN
        FUNCTION = 0
    END IF
    IF w.step = 2 AND LEN(w.email) = 0 THEN
        FUNCTION = 0
    END IF
    FUNCTION = 1
END FUNCTION

SUB ShowStep(BYREF w AS WizardData)
    PRINT ""
    PRINT "=== Step "; w.step; " of "; %MAX_STEPS; " ==="
    IF w.step = 1 THEN
        PRINT "Welcome to the Project Wizard!"
        PRINT "This wizard helps you create a new project."
        PRINT "Name: "; IIF(LEN(w.name) > 0, w.name, "(not set)")
    ELSEIF w.step = 2 THEN
        PRINT "Contact Information"
        PRINT "Email: "; IIF(LEN(w.email) > 0, w.email, "(not set)")
    ELSEIF w.step = 3 THEN
        PRINT "Project Type"
        PRINT "Type: "
        IF w.projectType = 0 THEN PRINT "Console Application"
        IF w.projectType = 1 THEN PRINT "GUI Application"
        IF w.projectType = 2 THEN PRINT "Library"
        IF w.projectType = 3 THEN PRINT "Web Service"
    ELSEIF w.step = 4 THEN
        PRINT "Features"
        PRINT "Include:"
        PRINT "  [x] Unit Tests"
        IF w.features AND 1 THEN PRINT "  [x] Documentation"
        IF w.features AND 2 THEN PRINT "  [x] Samples"
        IF w.features AND 4 THEN PRINT "  [x] CI Pipeline"
        PRINT "  Output: "; w.outputDir
    ELSEIF w.step = 5 THEN
        PRINT "Confirmation"
        PRINT "Name: "; w.name
        PRINT "Email: "; w.email
        PRINT "Project type: "; w.projectType
        PRINT "Output: "; w.outputDir
        PRINT ""
        PRINT "Press Finish to create the project."
    END IF
    PRINT "Buttons: ["
    IF w.step > 1 THEN PRINT "< Back ";
    IF w.step < %MAX_STEPS THEN PRINT "Next >";
    IF w.step = %MAX_STEPS THEN PRINT "Finish";
    PRINT " ] [Cancel]"
END SUB

SUB NextStep(BYREF w AS WizardData)
    IF w.step < %MAX_STEPS THEN
        w.step = w.step + 1
        PRINT " -> Moving to step "; w.step
    END IF
END SUB

SUB PrevStep(BYREF w AS WizardData)
    IF w.step > 1 THEN
        w.step = w.step - 1
        PRINT " -> Moving to step "; w.step
    END IF
END SUB

SUB SetField(BYREF w AS WizardData, BYVAL field AS LONG, BYVAL value AS STRING)
    IF field = 1 THEN w.name = value
    IF field = 2 THEN w.email = value
    IF field = 3 THEN w.projectType = VAL(value)
    IF field = 4 THEN w.features = VAL(value)
    IF field = 5 THEN w.outputDir = value
END SUB

SUB RunWizard()
    LOCAL w AS WizardData
    InitWizard(w)
    SetField(w, 1, "MyProject")
    SetField(w, 2, "user@example.com")
    SetField(w, 3, "1")
    SetField(w, 4, "3")
    w.confirmed = 1
    LOCAL i AS LONG
    FOR i = 1 TO %MAX_STEPS
        w.step = i
        ShowStep(w)
        IF i < %MAX_STEPS THEN
            NextStep(w)
        END IF
    NEXT i
    PRINT ""
    PRINT "Wizard completed!"
    PRINT "Project '"; w.name; "' created successfully."
END SUB

SUB TestNavigation()
    PRINT "Navigation test:"
    LOCAL w AS WizardData
    InitWizard(w)
    ShowStep(w)
    PrevStep(w)
    NextStep(w)
    SetField(w, 1, "Test")
    NextStep(w)
    ShowStep(w)
    PrevStep(w)
    ShowStep(w)
END SUB

SUB ValidationScenarios()
    PRINT "Validation scenarios:"
    LOCAL w AS WizardData
    InitWizard(w)
    PRINT "  Step 1, name empty: CanGoNext="; CanGoNext(w)
    SetField(w, 1, "ProjectX")
    PRINT "  Step 1, name set: CanGoNext="; CanGoNext(w)
    PRINT "  Step 2, email empty: CanGoNext="; CanGoNext(w)
    SetField(w, 2, "a@b.com")
    PRINT "  Step 2, email set: CanGoNext="; CanGoNext(w)
END SUB

FUNCTION PBMAIN() AS LONG
    PRINT "=== Wizard Dialog Demo ==="
    PRINT "Win32: Dialog with Next/Back/Cancel buttons"
    PRINT ""
    TestNavigation()
    PRINT ""
    ValidationScenarios()
    PRINT ""
    RunWizard()
    PRINT ""
    PRINT "=== End Wizard Demo ==="
    FUNCTION = 0
END FUNCTION
