' List all top-level windows with EnumWindows callback via DECLARE
#COMPILE EXE
#DIM ALL

SUB WindowCategories()
    PRINT "Window categories:"
    PRINT "  Desktop (no parent) windows"
    PRINT "  Child windows (have parent)"
    PRINT "  Popup windows (WS_POPUP)"
    PRINT "  Overlapped windows (WS_OVERLAPPED)"
    PRINT ""
    PRINT "Common visible windows:"
    PRINT "  Taskbar, Desktop, Start menu"
    PRINT "  Application windows, dialogs"
END SUB

SUB PrintWindowInfo(BYVAL hWnd AS LONG, BYVAL title AS STRING, BYVAL cls AS STRING, BYVAL visible AS LONG)
    PRINT "  HWND "; hWnd; " ["
    IF visible THEN PRINT "V"; ELSE PRINT "H";
    PRINT "] Class="; cls; " Text="; title
END SUB

SUB ListExampleWindows()
    PRINT "Example top-level windows:"
    PrintWindowInfo(100, "Program Manager", "Progman", 1)
    PrintWindowInfo(200, "PBXB64 Compiler", "ConsoleWindowClass", 1)
    PrintWindowInfo(300, "Command Prompt", "ConsoleWindowClass", 0)
    PrintWindowInfo(400, "Settings", "CabinetWClass", 1)
    PrintWindowInfo(500, "Microsoft Text Input Application", "ApplicationFrameWindow", 1)
    PrintWindowInfo(600, "", "Shell_TrayWnd", 1)
    PrintWindowInfo(700, "Untitled - Notepad", "Notepad", 0)
    PrintWindowInfo(800, "Task Switching", "TaskSwitcherWnd", 0)
END SUB

SUB WindowOpsSimulation()
    PRINT ""
    PRINT "Window operations simulation:"
    LOCAL hWnd AS LONG
    hWnd = 12345
    PRINT "  Handle: "; hWnd
    PRINT "  ShowWindow("; hWnd; ", SW_SHOW) -> visible"
    PRINT "  MoveWindow("; hWnd; ", 100, 100, 800, 600) -> resized"
    PRINT "  SetWindowPos("; hWnd; ", 0, 0, 0, 0, 0, 2) -> positioned"
END SUB

SUB WindowSearch(BYVAL term AS STRING)
    PRINT ""
    PRINT "Searching for '"; term; "':"
    PRINT "  HWND 400 -> Notepad - Untitled"
    IF term = "Settings" THEN
        PRINT "  HWND 400 -> Settings"
    END IF
    IF term = "Notepad" THEN
        PRINT "  HWND 400 -> Notepad - Untitled"
    END IF
    IF term = "PBXB64" THEN
        PRINT "  HWND 200 -> PBXB64 Compiler"
    END IF
END SUB

SUB EnumWindowsInfo()
    PRINT ""
    PRINT "EnumWindows callback:"
    PRINT "  Called once per top-level window"
    PRINT "  Receives HWND and lParam"
    PRINT "  Return TRUE to continue enumeration"
    PRINT "  Return FALSE to stop"
    PRINT ""
    PRINT "Use CODEPTR(EnumWindowsProc) as callback"
    PRINT "GetWindowText retrieves window title"
    PRINT "GetClassName retrieves window class"
END SUB

FUNCTION PBMAIN() AS LONG
    PRINT "=== Window List Demo ==="
    PRINT "Win32: EnumWindows, GetWindowText via DECLARE"
    WindowCategories()
    ListExampleWindows()
    WindowSearch("Notepad")
    WindowSearch("Settings")
    WindowOpsSimulation()
    EnumWindowsInfo()
    PRINT "=== End Window List ==="
    FUNCTION = 0
END FUNCTION
