Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 136
» Latest member: Rob Wooding
» Forum threads: 146
» Forum posts: 1,132

Full Statistics

Latest Threads
WorldWeather.bas
Forum: Source Code Library
Last Post: Stanley Durham
1 hour ago
» Replies: 1
» Views: 13
RSA2048 encryption
Forum: Programming
Last Post: Mannish Bhandari
8 hours ago
» Replies: 4
» Views: 102
logout
Forum: Suggestions and discussion about PUMP
Last Post: Albert Richheimer
Yesterday, 10:21
» Replies: 1
» Views: 61
WinTick 1.1
Forum: Source Code Library
Last Post: Borje Hagsten
Yesterday, 00:33
» Replies: 0
» Views: 50
RSA-2048 in PowerBasic (n...
Forum: Source Code Library
Last Post: Steven Pringels
12.11.2026, 20:28
» Replies: 0
» Views: 59
Insert image in post
Forum: Suggestions and discussion about PUMP
Last Post: Dale Yarker
05.11.2026, 14:47
» Replies: 3
» Views: 258
GDI+ Gauges custom contro...
Forum: Programming
Last Post: Jules Marchildon
04.11.2026, 13:12
» Replies: 7
» Views: 762
Next Gen Visual Designer ...
Forum: Programming
Last Post: Jules Marchildon
27.10.2026, 04:38
» Replies: 14
» Views: 1,781
Program that won't close
Forum: PowerBASIC for Windows
Last Post: Mike Doty
26.10.2026, 15:54
» Replies: 6
» Views: 576
EnableVisualStyles.bas
Forum: Source Code Library
Last Post: Stanley Durham
25.10.2026, 01:12
» Replies: 5
» Views: 533

 
  Doubly Linked String/WString List (Parser?)
Posted by: Stanley Durham - 05.10.2025, 10:15 - Forum: Source Code Library - Replies (2)

Compiler? Do you write a compiler or parse code for an existing compiler?
Two versions, String or WString. No dependencies. Fast, get 1,0000,000 values in less than 1/10 of a second.

This is something I did thinking it might be useful for parsing code. It’s a list, queue, stack and deque.  You can push, peek pop from front or back.
But it also has a cursor that can be moved forward and backwards. The cursor position also acts as a queue, stack and deque. You can push, peek, pop and delete before and after cursor position. The cursor can save its position one time; you can move around and then return.
Supports Split/Join.
It can load a text file and be saved as a text file (code file). WString version uses UTF8.
It can be stored/restored to/from file, binary format.
It can get a list of files, folders, sub-folders and all files in sub-folders matching a mask.
 
There are probably a lot better tools out there, but simplicity appeals to me. It seems like each different tool is a whole new programming language to learn. And different versions of the same type of compiler have different tools.
 
The idea is that you have an input and output list containing lines of code. One or more temporary list can be used to split a line of code apart. Push the output to the output list.
 
It’s an allocated container, must call …New() before use. Call PtrFree(p) to free handle or pointer. Errors are logged if %LogOnError is defined. Message on error if %MessageOnError is defined. You can use the ExitIf() macro to log parsing errors.
 
It might be useful, might not.


Code:
'StrList.inc

'Public domain, use at own risk. SDurham

'Function StrListNew() As Long
    'allocate new instance : return container pointer : call PtrFree(p) to free pointer

'Sub StrListClear(ByVal p As StrListT Ptr)
    'empty container

'Function StrListCount(ByVal p As StrListT Ptr) As Long
    'get item count

'Sub StrListAdd(ByVal p As StrListT Ptr, ByRef value As String)
    'append value

'Function StrListCursor(ByVal p As StrListT Ptr) As Long
    'true/false if cursor valid

'Function StrListFirst(ByVal p As StrListT Ptr) As Long
    'move cursor to first node : true/false success

'Function StrListNext(ByVal p As StrListT Ptr) As Long
    'move cursor to next node : true/false success

'Function StrListLast(ByVal p As StrListT Ptr) As Long
    'move cursor to last node : true/false success

'Function StrListPervious(ByVal p As StrListT Ptr) As Long
    'move cursor to previous node : true/false success

'Function StrListRember(ByVal p As StrListT Ptr) As Long
    'remember cursor position : fail if cursor null : true/false success

'Function StrListReturn(ByVal p As StrListT Ptr) As Long
    'return to remembered position : fail if node deleted : true/false success

'Function StrListGet(ByVal p As StrListT Ptr) As String
    'get value at cursor position : null if cursor null

'Function StrListSet(ByVal p As StrListT Ptr, ByRef value As String) As Long
    'set value at cursor position : fail if cursor null : true/false success

'Function StrListDeleteForward(ByVal p As StrListT Ptr) As Long
    'move to next node and delete node at cursor position : fail if cursor null : true/false success
    'cursor will be null if no next node

'Function StrListDeleteBackward(ByVal p As StrListT Ptr) As Long
    'move to previous node and delete node at cursor position : fail if cursor null : true/false success
    'cursor will be null if no previous node

'Function StrListIsBefore(ByVal p As StrListT Ptr) As Long
    'true/false if there is a node before cursor position

'Function StrListIsAfter(ByVal p As StrListT Ptr) As Long
    'true/false if there is a node after cursor position

'Function StrListDeleteBefore(ByVal p As StrListT Ptr) As Long
    'delete node before cursor position : fail if cursor null or no previous node : true/false success

'Function StrListDeleteAfter(ByVal p As StrListT Ptr) As Long
    'delete node after cursor position : fail if cursor null or no next node : true/false success

'Function StrListPushBefore(ByVal p As StrListT Ptr, ByRef value As String) As Long
    'add value before cursor position : fail if cursor null : true/false success

'Function StrListPushAfter(ByVal p As StrListT Ptr, ByRef value As String) As Long
    'add value after cursor position : fail if cursor null : true/false success
    'add value before cursor position : fail if cursor null : true/false success

'Function StrListPeekBefore(ByVal p As StrListT Ptr) As String
    'get value before cursor position : null if cursor invalid or no previous node

'Function StrListPeekAfter(ByVal p As StrListT Ptr) As String
    'get value after cursor position : null if cursor invalid or no next node

'Function StrListPopBefore(ByVal p As StrListT Ptr) As String
    'get and remove value before cursor position : null if cursor invalid or no previous node

'Function StrListPopAfter(ByVal p As StrListT Ptr) As String
    'get and remove value after cursor position : null if cursor invalid or no next node

'Sub StrListPushFirst(ByVal p As StrListT Ptr, ByRef value As String)
    'insert at front

'Sub StrListPushLast(ByVal p As StrListT Ptr, ByRef value As String)
    'append to end

'Function StrListPeekFirst(ByVal p As StrListT Ptr) As String
    'get fist value : null if list empty

'Function StrListPeekLast(ByVal p As StrListT Ptr) As String
    'get last value : null list empty

'Function StrListPopFirst(ByVal p As StrListT Ptr) As String
    'get and remove fist value : null if list empty

'Function StrListPopLast(ByVal p As StrListT Ptr) As String
    'get and remove last value : null if list empty

'Sub StrListImport(ByVal p As StrListT Ptr, a() As String)
    'import PB array

'Sub StrListExport(ByVal p As StrListT Ptr, a() As String)
    'export to PB array

'Sub StrListSplit(ByVal p As StrListT Ptr, ByVal delimited As String, ByVal delimiter As String)
    'split array on delimited string

'Function StrListJoin(ByVal p As StrListT Ptr, ByVal delimiter As String) As String
    'join array on delimiter

'Sub StrListToText(ByVal p As StrListT Ptr, ByVal file As WString)
    'store list as text file

'Sub StrListFromText(ByVal p As StrListT Ptr, ByVal file As WString)
    'load text file

'Sub StrListFolders(ByVal p As StrListT Ptr, ByVal rootFolder As String)
    'get all folders in root folder

'Sub StrListFiles(ByVal p As StrListT Ptr, ByVal folder As String, ByVal mask As String)
    'get all files in folder matching mask

'Sub StrListAllFolders(ByVal p As StrListT Ptr, ByVal rootFolder As String)
    'get all folders in root folder and sub-folders, including root folder

'Sub StrListAllFiles(ByVal p As StrListT Ptr, ByVal rootFolder As String, ByVal mask As String)
    'get all files in root folder, and sub-folders, matching mask

'Function StrListStore(ByVal p As StrListT Ptr) As String
    'store container to String

'Sub StrListRestore(ByVal p As StrListT Ptr, ByRef stored As String)
    'restore container from String

'Sub StrListFileStore(ByVal p As StrListT Ptr, ByVal file As WString)
    'store container to File

'Sub StrListFileRestore(ByVal p As StrListT Ptr, ByVal file As WString)
    'restore container from File

#If Not %Def(%ExitIf240526)
    %ExitIf240526 = 1
    '----------------------------------------------------------------------
    'Error Exit Macro
    'Exit procedure with error message
    'if %LogOnError defined then errors logged to app folder
    'if %MessageOnError defined then message on error
    'if %HaltOnError defined then app halt with message on error
    'Public domain, use at own risk. SDurham
    '----------------------------------------------------------------------
    %ExitIfErr = 151
    '----------------------------------------------------------------------
    Macro ExitIf(test, message, exitWhat)
        If test Then
            ExitLog FuncName$ + "() " + message
            Error %ExitIfErr
            Exit exitWhat
        End If
    End Macro
    Macro ExitF(test, message) = ExitIf(test, message, Function)
    Macro ExitS(test, message) = ExitIf(test, message, Sub)
    Macro ExitM(test, message) = ExitIf(test, message, Method)
    Macro ExitP(test, message) = ExitIf(test, message, Property)
    Macro ExitMC(test, message) = ExitIf(test, message, Macro)
    'GoTo with error message
    Macro GoToIf(test, message, goWhere)
        If test Then
            ExitLog FuncName$ +": "+ message
            Error %ExitIfErr
            GoTo goWhere
        End If
    End Macro
    '----------------------------------------------------------------------
    Sub ExitLog(ByVal message As String) Private
        Local h As Long
        h = FreeFile
        #If %Def(%LogOnError) Or %Def(%MessageOnError) Or %Def(%HaltOnError)
            Open Exe.Path$+"Error.log" For Append As h
            If Lof(h) < 16000 Then
                Print# h, Date$ +", "+ Time$ +", "+ Exe.Full$ +", "+ message
            End If
            Close h
        #EndIf
        #If %Def(%MessageOnError) Or %Def(%HaltOnError)
            ? message,,"Error!"
        #EndIf
        #If %Def(%HaltOnError)
            End
        #EndIf
    End Sub
    '----------------------------------------------------------------------
#EndIf '%ExitIf240526

#If Not %Def(%Memory230925)
    %Memory230925 = 1
    '----------------------------------------------------------------------
    'Memory Allocation
    'Public domain, use at own risk. SDurham
    '----------------------------------------------------------------------
    Declare Function GlobalAlloc Lib "Kernel32.dll" Alias "GlobalAlloc" (ByVal uFlags As Dword, ByVal dwBytes As Dword) As Dword
    Declare Function GlobalReAlloc Lib "Kernel32.dll" Alias "GlobalReAlloc" (ByVal hMem As Dword, ByVal dwBytes As Dword, ByVal uFlags As Dword) As Dword
    Declare Function GlobalFree Lib "Kernel32.dll" Alias "GlobalFree" (ByVal hMem As Dword) As Dword
    %MEMFIXED = &H0000 : %MEMMOVEABLE = &H0002 : %MEMZEROINIT = &H0040 : %MEMGPTR = (%MEMZEROINIT Or %MEMFIXED)
    '----------------------------------------------------------------------
    Function MemAlloc(ByVal bytes As Long) As Long
        'allocate memory
        If bytes Then Function = GlobalAlloc(ByVal %MEMGPTR, ByVal bytes)
    End Function
    '----------------------------------------------------------------------
    Function MemReAlloc(ByVal hMem As Long, ByVal bytes As Long) As Long
        'reallocate new size
        If hMem And bytes Then
            Function = GlobalReAlloc(ByVal hMem, ByVal bytes, ByVal %MEMMOVEABLE Or %MEMZEROINIT)
        ElseIf bytes Then
            Function = GlobalAlloc(ByVal %MEMGPTR, ByVal bytes)
        ElseIf hMem Then
            Function = GlobalFree(ByVal hMem)
        End If
    End Function
    '----------------------------------------------------------------------
    Function MemFree(ByVal hMem As Long) As Long
        'free memory
        If hMem Then GlobalFree(ByVal hMem)
    End Function
    '----------------------------------------------------------------------
#EndIf '%Memory230925

#If Not %Def(%Ptr250717)
    %Ptr250717 = 1
    '----------------------------------------------------------------------
    'Allocate UDT Pointer
    'PtrT must be first item in UDT
    'call PtrNew() to allocate pointer
    'call PtrFree() to free pointer
    'if PtrNewCallback() supplied then called after memory allocated
    'if PtrFinalCallback() supplied then called before memory freed
    'instance count supported but shouldn't be used unless needed
    'should be made clear who is responsible for freeing pointer
    '----------------------------------------------------------------------
    Declare Sub PtrNewCallback(ByVal p As Long)
        'if supplied then called after ponter allocated
    Declare Sub PtrFinalCallback(ByVal p As Long)
        'if supplied then called before ponter freed
    Declare Function PtrStoreCallback(ByVal p As Long) As String
        'return String holding pointer's associated data
    Declare Function PtrRestorCallback(ByRef stored As String) As Long
        'return new instance with data restored
    '----------------------------------------------------------------------
    %PtrTag = 648910727
    Type PtrT
        tag As Long
        instances As Long
        finalCB As Long
    End Type
    '----------------------------------------------------------------------
    Function PtrNew(ByVal SizeOfUdt As Long, ByVal newCB As Long, ByVal finalCB As Long) As Long
        'allocate new pointer instance : return pointer
        'if new callback supplied then called after memory allocated
        'if final callback supplied then called before memory freed
        Local p As PtrT Ptr
        ExitF(SizeOfUdt < SizeOf(PtrT), "invalid size")
            p = MemAlloc(SizeOfUdt)
            If p Then
                @p.tag = %PtrTag
                @p.instances = 1
                @p.finalCB = finalCB
                If newCB Then Call Dword newCB Using PtrNewCallback(p)
                Function = p
            End If
    End Function
    '----------------------------------------------------------------------
    Function PtrFree(ByVal p As PtrT Ptr) As Long
        'free pointer allocated by PtrNew() : return null
        'if final callback was supplied then called before memory freed
        If p Then
            ExitF(@p.tag <> %PtrTag, "invalid ptr")
            ExitF(@p.instances < 1, "invalid instance count")
            Decr @p.instances
            If @p.instances = 0 Then
                If @p.finalCB Then Call Dword @p.finalCB Using PtrFinalCallback(p)
                MemFree(p)
            End If
        End If
    End Function
    '----------------------------------------------------------------------
    Sub PtrIncr(ByVal p As PtrT Ptr)
        'increment instance count
        ExitS(p = 0 Or @p.tag <> %PtrTag, "invalid ptr")
        Incr @p.instances
    End Sub
    '----------------------------------------------------------------------
#EndIf '%Ptr250717

#If Not %Def(%StrBuild250811)
    %StrBuild250811 = 1
    '----------------------------------------------------------------------
    'String Builder
    'Public domain, use at own risk. SDurham
    '----------------------------------------------------------------------
    %BytSize = 1
    %StrBuildBufferMax = 5000000
    '----------------------------------------------------------------------
    Type StrBuildT
        mem As Long
        count As Long
        max As Long
    End Type
    '----------------------------------------------------------------------
    Sub StrBuildPush(t As StrBuildT, ByVal value As String)
        'append value
        Local strlen, currentcount, buffer, newmax As Long
        strlen = Len(value)
        If strlen Then
            If strlen > t.max - t.count Then
                currentcount = t.count : t.count = 0 : t.max = 0
                buffer = Max&(1, 2 * currentcount)
                buffer = Min&(buffer, %StrBuildBufferMax)
                newmax = currentcount + buffer + strlen
                t.mem = MemReAlloc(t.mem, newmax * %BytSize)
                If t.mem = 0 Then Exit Sub
                t.count = currentcount : t.max = newmax
            End If
            Memory Copy StrPtr(value), t.mem + (t.count * %BytSize), strlen * %BytSize
            t.count += strlen
        End If
    End Sub
    '----------------------------------------------------------------------
    Function StrBuildPop(t As StrBuildT) As String
        'get whole string : free memory
        If t.mem And t.count Then Function = Peek$(t.mem, t.count)
        t.mem = MemFree(t.mem)
        t.count = 0
        t.max = 0
    End Function
    '----------------------------------------------------------------------
#EndIf '%StrBuild250811

#If Not %Def(%FileStore250717)
    %FileStore250717 = 1
    Sub FilePut(ByVal file As WString, ByRef value As WString)
        'store value to File
        Local f As Long
        If Len(file) = 0 Then Exit Sub
        f = FreeFile
        Open file For Binary As f
        SetEof f
        Put$ f, value
        Close f
    End Sub
    Function FileGet(ByRef file As WString) As WString
        'restore value from File
        Local f As Long, value As WString
        If IsFalse IsFile(file) Then Exit Function
        f = FreeFile
        Open file For Binary As f
        Get$ f, Lof(f), value
        Close f
        Function = value
    End Function
#EndIf '%FileStore250717

#If Not %Def(%PtrList250812)
    %PtrList250812 = 1
    '----------------------------------------------------------------------
    'Pointer Doubly Linked List : Stack : Queue : Deque
    'pointers to allocated UDTs
    'PtrT must be first item in UDT
    'pointer must have been allocated with PtrNew()
    'stored pointers can't be null
    'Public domain, use at own risk. SDurham
    '----------------------------------------------------------------------
    Declare Function PtrStoreCallback(ByVal p As Long) As String
        'return String holding pointer's associated data
    Declare Function PtrRestorCallback(ByRef stored As String) As Long
        'return new instance with data restored
    '----------------------------------------------------------------------
    %LngSize = 4
    %PtrListTag = -699621965
    Type PtrListNodeT
        allocator As PtrT
        next As PtrListNodeT Ptr
        prev As PtrListNodeT Ptr
        value As Long
    End Type
    Type PtrListT
        allocator As PtrT
        tag As Long
        count As Long
        first As PtrListNodeT Ptr
        last As PtrListNodeT Ptr
        cursor As PtrListNodeT Ptr
        remember As PtrListNodeT Ptr
    End Type
    '----------------------------------------------------------------------
    Function PtrListNew() As Long
        'allocate new instance : return container pointer : call PtrFree(p) to free pointer
        Function = PtrNew(SizeOf(PtrListT), CodePtr(PtrListNewCB), CodePtr(PtrListClear))
    End Function
    '----------------------------------------------------------------------
    Sub PtrListClear(ByVal p As PtrListT Ptr)
        'empty container
        Local node As PtrListNodeT Ptr
        ExitS(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        While @p.first
            node = @p.first
            @p.first = @node.next
            PtrFree(node)
        Wend
        @p.last = 0
        @p.count = 0
        @p.cursor = 0
        @p.remember = 0
    End Sub
    '----------------------------------------------------------------------
    Function PtrListCount(ByVal p As PtrListT Ptr) As Long
        'get item count
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        Function = @p.count
    End Function
    '----------------------------------------------------------------------
    Sub PtrListAdd(ByVal p As PtrListT Ptr, ByVal pItem As Long)
        'append value
        PtrListPushLast p, pItem
    End Sub
    '----------------------------------------------------------------------
    Function PtrListCursor(ByVal p As PtrListT Ptr) As Long
        'true/false if cursor valid
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor Then Function = 1
    End Function
    '----------------------------------------------------------------------
    Function PtrListFirst(ByVal p As PtrListT Ptr) As Long
        'move cursor to first node : true/false success
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        @p.cursor = @p.first
        If @p.cursor Then Function = 1
    End Function
    '----------------------------------------------------------------------
    Function PtrListNext(ByVal p As PtrListT Ptr) As Long
        'move cursor to next node : true/false success
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor Then @p.cursor = @p.@cursor.next
        If @p.cursor Then Function = 1
    End Function
    '----------------------------------------------------------------------
    Function PtrListLast(ByVal p As PtrListT Ptr) As Long
        'move cursor to last node : true/false success
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        @p.cursor = @p.last
        If @p.cursor Then Function = 1
    End Function
    '----------------------------------------------------------------------
    Function PtrListPervious(ByVal p As PtrListT Ptr) As Long
        'move cursor to previous node : true/false success
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor Then @p.cursor = @p.@cursor.prev
        If @p.cursor Then Function = 1
    End Function
    '----------------------------------------------------------------------
    Function PtrListRember(ByVal p As PtrListT Ptr) As Long
        'remember cursor position : fail if cursor null : true/false success
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        @p.remember = @p.cursor
        If @p.remember Then Function = 1
    End Function
    '----------------------------------------------------------------------
    Function PtrListReturn(ByVal p As PtrListT Ptr) As Long
        'return to remembered position : fail if node deleted : true/false success
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        @p.cursor = @p.remember
        If @p.cursor Then Function = 1
    End Function
    '----------------------------------------------------------------------
    Function PtrListGet(ByVal p As PtrListT Ptr) As Long
        'get value at cursor position : null if cursor null
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor Then Function = @p.@cursor.value
    End Function
    '----------------------------------------------------------------------
    Function PtrListDeleteForward(ByVal p As PtrListT Ptr) As Long
        'move to next node and delete node at cursor position : fail if cursor null : true/false success
        'cursor will be null if no next node
        Local n As PtrListNodeT Ptr
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor Then
            Function = 1
            n = @p.cursor
            @p.cursor = @p.@cursor.next
            PtrListNodeDelete(p, n)
        End If
    End Function
    '----------------------------------------------------------------------
    Function PtrListDeleteBackward(ByVal p As PtrListT Ptr) As Long
        'move to previous node and delete node at cursor position : fail if cursor null : true/false success
        'cursor will be null if no previous node
        Local n As PtrListNodeT Ptr
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor Then
            Function = 1
            n = @p.cursor
            @p.cursor = @p.@cursor.prev
            PtrListNodeDelete(p, n)
        End If
    End Function
    '----------------------------------------------------------------------
    Function PtrListIsBefore(ByVal p As PtrListT Ptr) As Long
        'true/false if there is a node before cursor position
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor And @p.@cursor.prev Then Function = 1
    End Function
    '----------------------------------------------------------------------
    Function PtrListIsAfter(ByVal p As PtrListT Ptr) As Long
        'true/false if there is a node after cursor position
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor And @p.@cursor.next Then Function = 1
    End Function
    '----------------------------------------------------------------------
    Function PtrListDeleteBefore(ByVal p As PtrListT Ptr) As Long
        'delete node before cursor position : fail if cursor null or no previous node : true/false success
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor And @p.@cursor.prev Then
            PtrListNodeDelete p, @p.@cursor.prev
            Function = 1
        End If
    End Function
    '----------------------------------------------------------------------
    Function PtrListDeleteAfter(ByVal p As PtrListT Ptr) As Long
        'delete node after cursor position : fail if cursor null or no next node : true/false success
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor And @p.@cursor.next Then
            PtrListNodeDelete p, @p.@cursor.next
            Function = 1
        End If
    End Function
    '----------------------------------------------------------------------
    Function PtrListPushBefore(ByVal p As PtrListT Ptr, ByVal pItem As Long) As Long
        'add value before cursor position : fail if cursor null : true/false success
        Local node As PtrListNodeT Ptr
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        ExitF(pItem = 0 Or Peek(Long, pItem) <> %PtrTag, "invalid item")
        If @p.cursor Then
            Function = 1
            If @p.cursor = @p.first Then
                PtrListPushFirst p, pItem
            Else
                ExitF(@p.@cursor.prev = 0, "previous node null")
                node = PtrNew(SizeOf(PtrListNodeT), 0, CodePtr(PtrListNodeFinalCB))
                ExitF(node = 0, "PtrNew fail")
                @node.value = pItem
                @node.next = @p.cursor
                @node.prev = @p.@cursor.prev
                @p.@cursor.@prev.next = node
                @p.@cursor.prev = node
            End If
        End If
    End Function
    '----------------------------------------------------------------------
    Function PtrListPushAfter(ByVal p As PtrListT Ptr, ByVal pItem As Long) As Long
        'add value after cursor position : fail if cursor null : true/false success
        Local node As PtrListNodeT Ptr
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        ExitF(pItem = 0 Or Peek(Long, pItem) <> %PtrTag, "invalid item")
        If @p.cursor Then
            Function = 1
            If @p.cursor = @p.last Then
                PtrListPushLast p, pItem
            Else
                ExitF(@p.@cursor.next = 0, "next node null")
                node = PtrNew(SizeOf(PtrListNodeT), 0, CodePtr(PtrListNodeFinalCB))
                ExitF(node = 0, "PtrNew fail")
                @node.value = pItem
                @node.prev = @p.cursor
                @node.next = @p.@cursor.next
                @p.@cursor.@next.prev = node
                @p.@cursor.next = node
            End If
        End If
    End Function
    '----------------------------------------------------------------------
    Function PtrListPeekBefore(ByVal p As PtrListT Ptr) As Long
        'get value before cursor position : null if cursor invalid or no previous node
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor And @p.@cursor.prev Then Function = @p.@cursor.@prev.value
    End Function
    '----------------------------------------------------------------------
    Function PtrListPeekAfter(ByVal p As PtrListT Ptr) As Long
        'get value after cursor position : null if cursor invalid or no next node
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.cursor And @p.@cursor.next Then Function = @p.@cursor.@next.value
    End Function
    '----------------------------------------------------------------------
    Function PtrListPopBefore(ByVal p As PtrListT Ptr) As Long
        'get and remove value before cursor position : null if cursor invalid or no previous node
        'user responsible for freeing popped pointers
        Local h As Long
        h = PtrListPeekBefore(p)
        If h Then
            PtrIncr(h)
            Function = h
            PtrListDeleteBefore(p)
        End If
    End Function
    '----------------------------------------------------------------------
    Function PtrListPopAfter(ByVal p As PtrListT Ptr) As Long
        'get and remove value after cursor position : null if cursor invalid or no next node
        'user responsible for freeing popped pointers
        Local h As Long
        h = PtrListPeekAfter(p)
        If h Then
            PtrIncr(h)
            Function = h
            PtrListDeleteAfter(p)
        End If
    End Function
    '----------------------------------------------------------------------
    Sub PtrListPushFirst(ByVal p As PtrListT Ptr, ByVal pItem As Long)
        'insert at front
        Local node As PtrListNodeT Ptr
        ExitS(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        ExitS(pItem = 0 Or Peek(Long, pItem) <> %PtrTag, "invalid item")
        node = PtrNew(SizeOf(PtrListNodeT), 0, CodePtr(PtrListNodeFinalCB))
        ExitS(node = 0, "PtrNew fail")
        @node.value = pItem
        If @p.count Then
            ExitS(@p.first = 0, "first node null")
            @p.@first.prev = node
            @node.next = @p.first
            @p.first = node
            Incr @p.count
        Else
            @p.first = node
            @p.last = node
            @p.count = 1
        End If
    End Sub
    '----------------------------------------------------------------------
    Sub PtrListPushLast(ByVal p As PtrListT Ptr, ByVal pItem As Long)
        'append to end
        Local node As PtrListNodeT Ptr
        ExitS(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        ExitS(pItem = 0 Or Peek(Long, pItem) <> %PtrTag, "invalid item")
        node = PtrNew(SizeOf(PtrListNodeT), 0, CodePtr(PtrListNodeFinalCB))
        ExitS(node = 0, "PtrNew fail")
        @node.value = pItem
        If @p.count Then
            ExitS(@p.last = 0, "last node null")
            @p.@last.next = node
            @node.prev = @p.last
            @p.last = node
            Incr @p.count
        Else
            @p.first = node
            @p.last = node
            @p.count = 1
        End If
    End Sub
    '----------------------------------------------------------------------
    Function PtrListPeekFirst(ByVal p As PtrListT Ptr) As Long
        'get fist value : null if list empty
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.first Then Function = @p.@first.value
    End Function
    '----------------------------------------------------------------------
    Function PtrListPeekLast(ByVal p As PtrListT Ptr) As Long
        'get last value : null list empty
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.last Then Function = @p.@last.value
    End Function
    '----------------------------------------------------------------------
    Function PtrListPopFirst(ByVal p As PtrListT Ptr) As Long
        'get and remove fist value : null if list empty
        'user responsible for freeing popped pointers
        Local h As Long
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.first Then
            h = @p.@first.value
            PtrIncr(h)
            Function = h
            PtrListNodeDelete(p, @p.first)
        End If
    End Function
    '----------------------------------------------------------------------
    Function PtrListPopLast(ByVal p As PtrListT Ptr) As Long
        'get and remove last value : null if list empty
        'user responsible for freeing popped pointers
        Local h As Long
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        If @p.last Then
            h = @p.@last.value
            PtrIncr(h)
            Function = h
            PtrListNodeDelete(p, @p.last)
        End If
    End Function
    '----------------------------------------------------------------------
    Function PtrListStore(ByVal p As PtrListT Ptr, ByVal storeCB As Long) As String
        'store container to String
        'Declare Function PtrStoreCallback(ByVal p As Long) As String
        Local more, h As Long
        Local sb As StrBuildT
        Local s As String
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        ExitF(storeCB = 0, "null callback")
        If @p.count Then
            StrBuildPush sb, Mkl$(@p.count)
            more = PtrListFirst(p)
            While more
                h = PtrListGet(p)
                ExitF(h = 0, "unexpected null")
                Call Dword storeCB Using PtrStoreCallback(h) To s
                StrBuildPush sb, Mkl$(Len(s))
                StrBuildPush sb, s
                more = PtrListNext(p)
            Wend
        End If
        Function = StrBuildPop(sb)
    End Function
    '----------------------------------------------------------------------
    Sub PtrListRestore(ByVal p As PtrListT Ptr, ByRef stored As String, ByVal restoreCB As Long)
        'restore container from String
        'Declare Function PtrRestorCallback(ByRef stored As String) As Long
        Register i As Long
        Local items, bytes, h As Long
        Local s As String
        Local pl As Long Ptr
        ExitS(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        ExitS(restoreCB = 0, "null callback")
        PtrListClear p
        If Len(stored) Then
            pl = StrPtr(stored)
            items = @pl : Incr pl
            For i = 1 To items
                bytes = @pl : Incr pl
                s = Peek$(pl, bytes) : pl += bytes
                Call Dword restoreCB Using PtrRestorCallback(s) To h
                ExitS(h = 0,"null callback return")
                PtrListAdd p, h
            Next i
        End If
    End Sub
    '----------------------------------------------------------------------
    Sub PtrListFileStore(ByVal p As PtrListT Ptr, ByVal file As WString, ByVal storeCB As Long)
        'store container to File
        'Declare Function PtrStoreCallback(ByVal p As Long) As String
        ExitS(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        ExitS(storeCB = 0, "null callback")
        ExitS(Len(file) = 0, "invalid file")
        FilePut file, PtrListStore(p, storeCB)
    End Sub
    '----------------------------------------------------------------------
    Sub PtrListFileRestore(ByVal p As PtrListT Ptr, ByVal file As WString, ByVal restoreCB As Long)
        'restore container from File
        'Declare Function PtrRestorCallback(ByRef stored As String) As Long
        ExitS(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %PtrListTag, "invalid ptr")
        ExitS(IsFalse IsFile(file), "invalid file" + file)
        PtrListRestore p, FileGet(file), restoreCB
    End Sub
    '----------------------------------------------------------------------
    'PRIVATE:
    '----------------------------------------------------------------------
    Sub PtrListNewCB(ByVal p As PtrListT Ptr) Private
        'PRIVATE: list new callback
        If p Then @p.tag = %PtrListTag
    End Sub
    '----------------------------------------------------------------------
    Sub PtrListNodeFinalCB(ByVal node As PtrListNodeT Ptr)
        If node Then
            PtrFree(@node.value)
        End If
    End Sub
    '----------------------------------------------------------------------
    Sub PtrListNodeDelete(ByVal p As PtrListT Ptr, ByVal node As PtrListNodeT Ptr) Private
        'PRIVATE: remove node from list
        If node Then
            If @p.cursor = node Then @p.cursor = 0
            If @p.remember = node Then @p.remember = 0
            If @p.first = node Then @p.first = @node.next
            If @p.last = node Then @p.last = @node.prev
            If @node.prev Then @node.@prev.next = @node.next
            If @node.next Then @node.@next.prev = @node.prev
            ExitS(@p.count = 0, "invalid count")
            Decr @p.count
            PtrFree(node)
        End If
    End Sub
    '----------------------------------------------------------------------
#EndIf '%PtrList250812

#If Not %Def(%Str250724)
    %Str250724 = 1
    '----------------------------------------------------------------------
    'Dynamic String Container
    '----------------------------------------------------------------------
    Declare Function StrCompareCallback(ByVal a As Long, ByVal b As Long) As Long
        'a < b : return < 0    a = b : return = 0    a > b : return > 0
    '----------------------------------------------------------------------
    %BytSize = 1
    %StrTag = 653170298
    Type StrT
        allocator As PtrT
        tag As Long
        mem As Byte Ptr
        count As Long
    End Type
    '----------------------------------------------------------------------
    Function StrNew() As Long
        'allocate new instance : return container pointer : call PtrFree(p) to free pointer
        Function = PtrNew(SizeOf(StrT), CodePtr(StrNewCB), CodePtr(StrClear))
    End Function
    '----------------------------------------------------------------------
    Sub StrClear(ByVal p As StrT Ptr)
        'empty container
        ExitS(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %StrTag, "invalid ptr")
        @p.mem = MemFree(@p.mem)
        @p.count = 0
    End Sub
    '----------------------------------------------------------------------
    Function StrGet(ByVal p As StrT Ptr) As String
        'get value
        ExitF(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %StrTag, "invalid ptr")
        Function = Peek$(@p.mem, @p.count)
    End Function
    '----------------------------------------------------------------------
    Sub StrSet(ByVal p As StrT Ptr, ByRef value As String)
        Local strlen As Long : strlen = Len(value)
        Local bytes As Long : bytes = strlen * %BytSize
        ExitS(p = 0 Or @p.allocator.tag <> %PtrTag Or @p.tag <> %StrTag, "invalid ptr")
        @p.mem = MemFree(@p.mem) : @p.count = 0
        If strlen Then
            @p.mem = MemAlloc(bytes)
            If @p.mem Then
                @p.count = strlen
                Memory Copy StrPtr(value), @p.mem, bytes
            End If
        End If
    End Sub
    '----------------------------------------------------------------------
    Function StrNewValue(ByRef value As String) As Long
        'allocate new instance : store value : return pointer
        Local h As Long
        h = StrNew()
        StrSet h, value
        Function = h
    End Function
    '----------------------------------------------------------------------
    Function StrHashIndex(ByVal p As StrT Ptr, ByVal capacity As Long) As Long
        'get key's one-based hash index position
        Register i As Long : Local total, temp As Long
        Function = 1
        If p Then
            For i = 0 To @p.count - 1
                temp += @p.@mem[i] + total
                Shift Left total, 8
                total += temp
            Next i
            Function = Abs(total Mod capacity) + 1
        End If
    End Function
    '----------------------------------------------------------------------
    Function StrEqual(ByVal a As StrT Ptr, ByVal b As StrT Ptr) As Long
        'true/false if two strings equal
        Register i As Long
        If a And b And @a.count = @b.count Then
            For i = 0 To @a.count - 1
                If @a.@mem[i] <> @b.@mem[i] Then Exit Function
            Next i
            Function = 1
        End If
    End Function
    '----------------------------------------------------------------------
    Function StrCompare(ByVal a As StrT Ptr, ByVal b As StrT Ptr) As Long
        'compare callback : case sensitive
        Register i As Long : Register compare As Long
        If a And b Then
            For i = 0 To Min&(@a.count, @b.count) - 1
                compare = @a.@mem[i] - @b.@mem[i]
                If compare Then
                    Function = compare : Exit Function
                End If
            Next i
            Function = @a.count - @b.count
        End If
    End Function
    '----------------------------------------------------------------------
    Function StrCompareIgnore(ByVal a As StrT Ptr, ByVal b As StrT Ptr) As Long
        'compare callback : case sensitive
        Register i As Long : Register compare As Long : Local la, lb As Long
        If a And b Then
            For i = 0 To Min&(@a.count, @b.count) - 1
                la = @a.@mem[i] : lb = @b.@mem[i]
                If la > 64 And la < 91 Then la += 32
                If lb > 64 And lb < 91 Then lb += 32
                compare = la - lb
                If compare Then
                    Function = compare : Exit Function
                End If
            Next i
            Function = @a.count - @b.count
        End If
    End Function
    '----------------------------------------------------------------------
    Function StrStoreCB(ByVal p As StrT Ptr) As String
        'store callback
        Function = ChrToUtf8$(StrGet(p))
    End Function
    '----------------------------------------------------------------------
    Function StrRestoreCB(ByRef value As String) As Long
        'restore callback
        Function = StrNewValue(Utf8ToChr$(value))
    End Function
    '----------------------------------------------------------------------
    'PRIVATE:
    '----------------------------------------------------------------------
    Sub StrNewCB(ByVal p As StrT Ptr) Private
        'PRIVATE: new callback
        If p Then @p.tag = %StrTag
    End Sub
    '----------------------------------------------------------------------
#EndIf '%Str250724

#If Not %Def(%StrList250812)
    %StrList250812 = 1
    '----------------------------------------------------------------------
    'String Doubly Linked List : Stack : Queue : Deque
    '----------------------------------------------------------------------
    Macro StrListT = PtrListT
    '----------------------------------------------------------------------
    Function StrListNew() As Long
        'allocate new instance : return container pointer : call PtrFree(p) to free pointer
        Function = PtrListNew()
    End Function
    '----------------------------------------------------------------------
    Sub StrListClear(ByVal p As StrListT Ptr)
        'empty container
        PtrListClear p
    End Sub
    '----------------------------------------------------------------------
    Function StrListCount(ByVal p As StrListT Ptr) As Long
        'get item count
        Function = PtrListCount(p)
    End Function
    '----------------------------------------------------------------------
    Sub StrListAdd(ByVal p As StrListT Ptr, ByRef value As String)
        'append value
        PtrListAdd p, StrNewValue(value)
    End Sub
    '----------------------------------------------------------------------
    Function StrListCursor(ByVal p As StrListT Ptr) As Long
        'true/false if cursor valid
        Function = PtrListCursor(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListFirst(ByVal p As StrListT Ptr) As Long
        'move cursor to first node : true/false success
        Function = PtrListFirst(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListNext(ByVal p As StrListT Ptr) As Long
        'move cursor to next node : true/false success
        Function = PtrListNext(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListLast(ByVal p As StrListT Ptr) As Long
        'move cursor to last node : true/false success
        Function = PtrListLast(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListPervious(ByVal p As StrListT Ptr) As Long
        'move cursor to previous node : true/false success
        Function = PtrListPervious(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListRember(ByVal p As StrListT Ptr) As Long
        'remember cursor position : fail if cursor null : true/false success
        Function = PtrListRember(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListReturn(ByVal p As StrListT Ptr) As Long
        'return to remembered position : fail if node deleted : true/false success
        Function = PtrListReturn(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListGet(ByVal p As StrListT Ptr) As String
        'get value at cursor position : null if cursor null
        Local h As Long
        h = PtrListGet(p)
        If h Then Function = StrGet(h)
    End Function
    '----------------------------------------------------------------------
    Function StrListSet(ByVal p As StrListT Ptr, ByRef value As String) As Long
        'set value at cursor position : fail if cursor null : true/false success
        Local h As Long
        h = PtrListGet(p)
        If h Then
            StrSet h, value
            Function = 1
        End If
    End Function
    '----------------------------------------------------------------------
    Function StrListDeleteForward(ByVal p As StrListT Ptr) As Long
        'move to next node and delete node at cursor position : fail if cursor null : true/false success
        'cursor will be null if no next node
        Function = PtrListDeleteForward(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListDeleteBackward(ByVal p As StrListT Ptr) As Long
        'move to previous node and delete node at cursor position : fail if cursor null : true/false success
        'cursor will be null if no previous node
        Function = PtrListDeleteBackward(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListIsBefore(ByVal p As StrListT Ptr) As Long
        'true/false if there is a node before cursor position
        Function = PtrListIsBefore(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListIsAfter(ByVal p As StrListT Ptr) As Long
        'true/false if there is a node after cursor position
        Function = PtrListIsAfter(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListDeleteBefore(ByVal p As StrListT Ptr) As Long
        'delete node before cursor position : fail if cursor null or no previous node : true/false success
        Function = PtrListDeleteBefore(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListDeleteAfter(ByVal p As StrListT Ptr) As Long
        'delete node after cursor position : fail if cursor null or no next node : true/false success
        Function = PtrListDeleteAfter(p)
    End Function
    '----------------------------------------------------------------------
    Function StrListPushBefore(ByVal p As StrListT Ptr, ByRef value As String) As Long
        'add value before cursor position : fail if cursor null : true/false success
        Local h As Long : h = StrNewValue(value)
        If IsFalse PtrListPushBefore(p, h) Then PtrFree(h)
    End Function
    '----------------------------------------------------------------------
    Function StrListPushAfter(ByVal p As StrListT Ptr, ByRef value As String) As Long
        'add value after cursor position : fail if cursor null : true/false success
        'add value before cursor position : fail if cursor null : true/false success
        Local h As Long : h = StrNewValue(value)
        If IsFalse PtrListPushAfter(p, h) Then PtrFree(h)
    End Function
    '----------------------------------------------------------------------
    Function StrListPeekBefore(ByVal p As StrListT Ptr) As String
        'get value before cursor position : null if cursor invalid or no previous node
        Local h As Long : h = PtrListPeekBefore(p)
        If h Then Function = StrGet(h)
    End Function
    '----------------------------------------------------------------------
    Function StrListPeekAfter(ByVal p As StrListT Ptr) As String
        'get value after cursor position : null if cursor invalid or no next node
        Local h As Long : h = PtrListPeekAfter(p)
        If h Then Function = StrGet(h)
    End Function
    '----------------------------------------------------------------------
    Function StrListPopBefore(ByVal p As StrListT Ptr) As String
        'get and remove value before cursor position : null if cursor invalid or no previous node
        Local h As Long : h = PtrListPopBefore(p)
        If h Then
            Function = StrGet(h)
            PtrFree(h)
        End If
    End Function
    '----------------------------------------------------------------------
    Function StrListPopAfter(ByVal p As StrListT Ptr) As String
        'get and remove value after cursor position : null if cursor invalid or no next node
        Local h As Long : h = PtrListPopAfter(p)
        If h Then
            Function = StrGet(h)
            PtrFree(h)
        End If
    End Function
    '----------------------------------------------------------------------
    Sub StrListPushFirst(ByVal p As StrListT Ptr, ByRef value As String)
        'insert at front
        PtrListPushFirst p, StrNewValue(value)
    End Sub
    '----------------------------------------------------------------------
    Sub StrListPushLast(ByVal p As StrListT Ptr, ByRef value As String)
        'append to end
        PtrListPushLast p, StrNewValue(value)
    End Sub
    '----------------------------------------------------------------------
    Function StrListPeekFirst(ByVal p As StrListT Ptr) As String
        'get fist value : null if list empty
        Local h As Long : h = PtrListPeekFirst(p)
        If h Then Function = StrGet(h)
    End Function
    '----------------------------------------------------------------------
    Function StrListPeekLast(ByVal p As StrListT Ptr) As String
        'get last value : null list empty
        Local h As Long : h = PtrListPeekLast(p)
        If h Then Function = StrGet(h)
    End Function
    '----------------------------------------------------------------------
    Function StrListPopFirst(ByVal p As StrListT Ptr) As String
        'get and remove fist value : null if list empty
        Local h As Long : h = PtrListPopFirst(p)
        If h Then
            Function = StrGet(h)
            PtrFree(h)
        End If
    End Function
    '----------------------------------------------------------------------
    Function StrListPopLast(ByVal p As StrListT Ptr) As String
        'get and remove last value : null if list empty
        Local h As Long : h = PtrListPopLast(p)
        If h Then
            Function = StrGet(h)
            PtrFree(h)
        End If
    End Function
    '----------------------------------------------------------------------
    Sub StrListImport(ByVal p As StrListT Ptr, a() As String)
        'import PB array
        Register i As Long
        StrListClear p
        For i = LBound(a) To UBound(a)
            StrListAdd p, a(i)
        Next i
    End Sub
    '----------------------------------------------------------------------
    Sub StrListExport(ByVal p As StrListT Ptr, a() As String)
        'export to PB array
        Register i As Long
        Local more As Long
        Erase a()
        If StrListCount(p) Then
            ReDim a(1 To StrListCount(p))
            more = StrListFirst(p)
            While more
                Incr i
                a(i) = StrListGet(p)
                more = StrListNext(p)
            Wend
        End If
    End Sub
    '----------------------------------------------------------------------
    Sub StrListSplit(ByVal p As StrListT Ptr, ByVal delimited As String, ByVal delimiter As String)
        'split array on delimited string
        Local items As Long
        Local a() As String
        StrListClear p
        If Len(delimited) Then
            items = ParseCount(delimited, delimiter)
            If items Then
                Dim a(1 To items)
                Parse delimited, a(), delimiter
                StrListImport p, a()
            End If
        End If
    End Sub
    '----------------------------------------------------------------------
    Function StrListJoin(ByVal p As StrListT Ptr, ByVal delimiter As String) As String
        'join array on delimiter
        Local a() As String
        StrListExport p, a()
        Function = Join$(a(), delimiter)
    End Function
    '----------------------------------------------------------------------
    Sub StrListToText(ByVal p As StrListT Ptr, ByVal file As WString)
        'store list as text file
        If StrListCount(p) Then
            FilePut file, RTrim$(StrListJoin(p, $CrLf))  + $CrLf
        End If
    End Sub
    '----------------------------------------------------------------------
    Sub StrListFromText(ByVal p As StrListT Ptr, ByVal file As WString)
        'load text file
        Local contents As String
        StrListClear p
        contents = FileGet(file)
        contents = Trim$(contents, $CrLf)
        If Len(contents) Then
            StrListSplit p, contents, $CrLf
        End If
    End Sub
    '----------------------------------------------------------------------
    Sub StrListFolders(ByVal p As StrListT Ptr, ByVal rootFolder As String)
        'get all folders in root folder
        Local folder, folderMask, rootPath As String
        Local DrD As DirData
        StrListClear p
        ExitS(IsFalse IsFolder(rootFolder), "invalid folder")
        rootPath = RTrim$(rootFolder, "\") + "\"
        folderMask = rootPath
        folder = Dir$(folderMask, Only %SubDir To DrD)
        While Len(folder)
            StrListAdd p, rootPath + folder
            folder = Dir$
        Wend
    End Sub
    '----------------------------------------------------------------------
    Sub StrListFiles(ByVal p As StrListT Ptr, ByVal folder As String, ByVal mask As String)
        'get all files in folder matching mask
        Local file, fileMask As String
        StrListClear p
        ExitS(IsFalse IsFolder(folder), "invalid folder")
        folder = RTrim$(folder, "\") + "\"
        fileMask = folder + mask
        file = Dir$(fileMask)
        While Len(file)
            StrListAdd p, folder + file
            file = Dir$
        Wend
    End Sub
    '----------------------------------------------------------------------
    Sub StrListAllFolders(ByVal p As StrListT Ptr, ByVal rootFolder As String)
        'get all folders in root folder and sub-folders, including root folder
        Local folderStack As Long : folderStack = StrListNew()
        Local subFolderStack As Long : subFolderStack = StrListNew()
        Local currentFolder As String
        StrListClear p
        ExitS(IsFalse IsFolder(rootFolder), "invalid folder")
        StrListPushLast folderStack, rootFolder
        While StrListCount(folderStack)
            currentFolder = StrListPopLast(folderStack)
            StrListAdd p, currentFolder
            StrListFolders subFolderStack, currentFolder
            While StrListCount(subFolderStack)
                StrListPushLast folderStack, StrListPopLast(subFolderStack)
            Wend
        Wend
        folderStack = PtrFree(folderStack)
        subFolderStack = PtrFree(subFolderStack)
    End Sub
    '----------------------------------------------------------------------
    Sub StrListAllFiles(ByVal p As StrListT Ptr, ByVal rootFolder As String, ByVal mask As String)
        'get all files in root folder, and sub-folders, matching mask
        Local allFolderStack As Long : allFolderStack = StrListNew()
        Local folderFileStack As Long : folderFileStack = StrListNew()
        StrListClear p
        ExitS(IsFalse IsFolder(rootFolder), "invalid folder")
        StrListAllFolders allFolderStack, rootFolder
        While StrListCount(allFolderStack)
            StrListFiles folderFileStack, StrListPopLast(allFolderStack), mask
            While StrListCount(folderFileStack)
                StrListAdd p, StrListPopLast(folderFileStack)
            Wend
        Wend
        allFolderStack = PtrFree(allFolderStack)
        folderFileStack = PtrFree(folderFileStack)
    End Sub
    '----------------------------------------------------------------------
    Function StrListStore(ByVal p As StrListT Ptr) As String
        'store container to String
        Function = PtrListStore(p, CodePtr(StrStoreCB))
    End Function
    '----------------------------------------------------------------------
    Sub StrListRestore(ByVal p As StrListT Ptr, ByRef stored As String)
        'restore container from String
        PtrListRestore p, stored, CodePtr(StrRestoreCB)
    End Sub
    '----------------------------------------------------------------------
    Sub StrListFileStore(ByVal p As StrListT Ptr, ByVal file As WString)
        'store container to File
        PtrListFileStore p, file, CodePtr(StrStoreCB)
    End Sub
    '----------------------------------------------------------------------
    Sub StrListFileRestore(ByVal p As StrListT Ptr, ByVal file As WString)
        'restore container from File
        PtrListFileRestore p, file, CodePtr(StrRestoreCB)
    End Sub
    '----------------------------------------------------------------------
#EndIf '%StrList250812

Print this item

  & Character problem
Posted by: Robert Alvarez - 30.09.2025, 20:08 - Forum: PowerBASIC for Windows - Replies (13)

using the & character is a problem when typing in text box and displaying it, is thee a fix

type A&B
screen show AB
xprint show A&B

type A&&B
screen show A&B
xprint show A&&B

Print this item

  Very Simple Round Gauge Discussion Thread
Posted by: Jules Marchildon - 24.09.2025, 23:33 - Forum: Programming - Replies (5)

Posted  in source code forum.

Nice one Kevin,  yours looks better.   I didn't know I had a friendly stalker!  Big Grin

Patrice, I gave it a try,  while I've run out of socks from trying all your other demo's out, I did feel the whoosh and then  goosebumps!  Impressive!  Seems much much faster!   Did you use the native LZNT1 in the last release?

Since I know diddly about obj files I downloaded a free one of the curiosity Rover...
https://free3d.com/3d-model/curiosity-rover-46907.html
...but it's missing the MTL file, so I made one up, unfortunately the conversion still failed.   

Code:
# dummy MTL for Curiosity Rover
newmtl default
Ka 0.200000 0.200000 0.200000
Kd 0.666667 0.666667 0.666667
Ks 0.000000 0.000000 0.000000
Ns 1.000000
illum 2
Pl
P

Print this item

  Very Simple Round Gauge 0-100%
Posted by: Jules Marchildon - 24.09.2025, 18:01 - Forum: Source Code Library - Replies (6)

I needed a very simple round gauge for one of our in-house measuring dashboards.  I didn't use any double buffer or GDI+ as it is only intended to be a static needle most of the time.  

This one demo's percentage, but you can modify it to whatever; volts, amps, watts, temp, cats, dogs.   Big Grin
   

Code:
'
' Very simple round gauge, 0-100%
' Jules Marchildon, Sept. 24, 2025
'

#COMPILE EXE
#DIM ALL

#INCLUDE "WIN32API.INC"

GLOBAL gValue AS LONG
GLOBAL ghDlg AS DWORD

'--------------------------------------------------------------------------------------------------
'
'--------------------------------------------------------------------------------------------------
FUNCTION PBMAIN()
    DIALOG NEW 0, "Round Gauge: 0-100%",,, 200, 200, %WS_SYSMENU TO ghDlg
    DIALOG SHOW MODAL ghDlg CALL DlgProc
END FUNCTION

'--------------------------------------------------------------------------------------------------
'
'--------------------------------------------------------------------------------------------------
CALLBACK FUNCTION DlgProc()

    LOCAL ps AS PAINTSTRUCT
    LOCAL hDC, hMemDC, hBitmap, hOldBitmap AS DWORD
    LOCAL hGauge AS DWORD
    LOCAL rc AS RECT
    LOCAL cx AS LONG, cy AS LONG, radius AS LONG

    SELECT CASE CB.MSG

        CASE %WM_INITDIALOG
            '-simulate gauge updates with a timer
            SetTimer CB.HNDL, 1, 300, BYVAL %NULL

        CASE %WM_TIMER
            gValue = (gValue + 1) MOD 101
            InvalidateRect CB.HNDL, BYVAL %NULL, %TRUE

        CASE %WM_PAINT
            hDC = BeginPaint(CB.HNDL, ps)
                GetClientRect(CB.HNDL, rc)
                hMemDC = CreateCompatibleDC(hDC)
                hBitmap = CreateCompatibleBitmap(hDC, rc.nRight, rc.nBottom)
                hOldBitmap = SelectObject(hMemDC, hBitmap)
                FillRect hMemDC, rc, GetSysColorBrush(%COLOR_BTNFACE)
                '-calc center and radius
                cx = (rc.nRight - rc.nLeft) \ 2
                cy = (rc.nBottom - rc.nTop) \ 2
                radius = MIN(cx, cy) - 10
                DrawGauge(hMemDC, cx, cy, radius, gValue)
                BitBlt hDC, 0, 0, rc.nRight, rc.nBottom, hMemDC, 0, 0, %SRCCOPY
                SelectObject hMemDC, hOldBitmap
                DeleteObject hBitmap
                DeleteDC hMemDC
            EndPaint(CB.HNDL, ps)

        CASE %WM_DESTROY
            KillTimer CB.HNDL, 1
            PostQuitMessage 0

    END SELECT
END FUNCTION

'--------------------------------------------------------------------------------------------------
'
'--------------------------------------------------------------------------------------------------
SUB DrawGauge(hDC AS DWORD, cx AS LONG, cy AS LONG, radius AS LONG, value AS LONG)

    LOCAL angle, rad, offsetRad, aDeg, percent, needleWidth AS SINGLE
    LOCAL hPen, hOldPen, hFont, hOldFont, hBrush, hOldBrush AS DWORD
    LOCAL i, x1, y1, x2, y2, xTip, yTip, r, g, b AS LONG
    LOCAL xBase1, yBase1, xBase2, yBase2 AS LONG
    LOCAL sVal AS STRING, lsize AS SIZE, cherryPi AS EXT

    cherryPi = 4*ATN(1)

    '=== Arc background with green-yellow-red segments ===
    FOR aDeg = 225 TO -45 STEP -1
        rad = aDeg * cherryPi / 180
        x1 = cx + radius * 0.85 * COS(rad)
        y1 = cy - radius * 0.85 * SIN(rad)
        x2 = cx + radius * 0.95 * COS(rad)
        y2 = cy - radius * 0.95 * SIN(rad)
        '-calc perc% across arc 0 to 1
        percent = (225 - aDeg) / 270
        '-interpolate color
        IF percent <= 0.25 THEN
            '-green to Yellow
            r = percent / 0.25 * 255
            g = 255
            b = 0
        ELSEIF percent <= 0.75 THEN
            '-yellow to Red
            r = 255
            g = 255 - ((percent - 0.25) / 0.5 * 255)
            b = 0
        ELSE
            '-solid Red
            r = 255
            g = 0
            b = 0
        END IF
        hPen = CreatePen(%PS_SOLID, 1, RGB(r, g, b))
        hOldPen = SelectObject(hDC, hPen)
        MoveToEx hDC, x1, y1, BYVAL %NULL
        LineTo hDC, x2, y2
        SelectObject hDC, hOldPen
        DeleteObject hPen
    NEXT


    #IF 1 '=== Optional chintzy bezel ring ===
        hPen = CreatePen(%PS_SOLID, 4, RGB(190, 190, 190))
        hOldPen = SelectObject(hDC, hPen)
        LOCAL ltweak AS LONG
        ltweak = 1 '-tweak gap to your own taste
        ARC hDC, cx - radius - ltweak, cy - radius - ltweak, cx + radius + ltweak, cy + radius + ltweak, 0, 0, 0, 0
        SelectObject hDC, hOldPen
        DeleteObject hPen
    #ENDIF

    '=== tick marks and labels every 5 units ===
    FOR i = 0 TO 100 STEP 5
        angle = (225 - (i * 2.7!)) * cherryPi / 180
        '-major tick length for labels every 10 units, short for 5 units
        IF (i MOD 10) = 0 THEN
            x1 = cx + radius * 0.80 * COS(angle)
            y1 = cy - radius * 0.80 * SIN(angle)
        ELSE
            x1 = cx + radius * 0.84 * COS(angle)
            y1 = cy - radius * 0.84 * SIN(angle)
        END IF
        x2 = cx + radius * 0.92 * COS(angle)
        y2 = cy - radius * 0.92 * SIN(angle)
        MoveToEx hDC, x1, y1, BYVAL %NULL
        LineTo hDC, x2, y2
        '-label every 10 units only
        IF (i MOD 10) = 0 THEN
            LOCAL sText AS STRING
            sText = FORMAT$(i)
            SetBkMode hDC, %TRANSPARENT
            SetTextColor hDC, RGB(40, 140, 240)
            LOCAL tx AS LONG, ty AS LONG
            tx = cx + radius * 0.65 * COS(angle) - 10
            ty = cy - radius * 0.65 * SIN(angle) - 8
            TextOut hDC, tx, ty, BYVAL STRPTR(sText), LEN(sText)
        END IF
    NEXT

    '=== draw polygon needle ===
    angle = (225 - (gValue * 2.7!))  '<-map gValue (0-100) to 225 to -45
    rad = angle * cherryPi / 180
    '-tip of the needle
    xTip = cx + radius * 0.75 * COS(rad)
    yTip = cy - radius * 0.75 * SIN(rad)
    '-base width and angle offset for polygon
    needleWidth = 6.0  '<-adjust width here
    offsetRad = 90 * cherryPi / 180  '-perpendicular
    '-two base corners *perpendicular to needle angle
    xBase1 = cx + needleWidth * COS(rad + offsetRad)
    yBase1 = cy - needleWidth * SIN(rad + offsetRad)
    xBase2 = cx + needleWidth * COS(rad - offsetRad)
    yBase2 = cy - needleWidth * SIN(rad - offsetRad)
    '-define needle polygon points
    DIM pts(0 TO 2) AS POINTAPI
    pts(0).x = xTip : pts(0).y = yTip
    pts(1).x = xBase1 : pts(1).y = yBase1
    pts(2).x = xBase2 : pts(2).y = yBase2
    '-draw needle
    hBrush = CreateSolidBrush(RGB(255, 0, 0))    '-fill color
    hOldBrush = SelectObject(hDC, hBrush)
    hPen = CreatePen(%PS_SOLID, 1, RGB(0, 0, 0)) '-outline
    hOldPen = SelectObject(hDC, hPen)
    POLYGON hDC, pts(0), 3
    SelectObject hDC, hOldBrush
    DeleteObject hBrush
    SelectObject hDC, hOldPen
    DeleteObject hPen
    '-center cap
    ELLIPSE hDC, cx - 8, cy - 8, cx + 8, cy + 8
    '=== digital value display in the center ===
    sVal = FORMAT$(value) + "%"
    hFont = CreateFont(28, 0, 0, 0, %FW_BOLD, 0, 0, 0, _
                %ANSI_CHARSET, %OUT_DEFAULT_PRECIS, %CLIP_DEFAULT_PRECIS, _
                %DEFAULT_QUALITY, %DEFAULT_PITCH OR %FF_DONTCARE, "Segoe UI")
    hOldFont = SelectObject(hDC, hFont)
    SetBkMode hDC, %TRANSPARENT
    SetTextColor hDC, RGB(0, 102, 204)
    '-measure text size to center it
    GetTextExtentPoint32 hDC, BYVAL STRPTR(sVal), LEN(sVal), lsize
    TextOut hDC, cx - lsize.cx \ 2, cy - lsize.cy \ 2 +60, BYVAL STRPTR(sVal), LEN(sVal)
    SelectObject hDC, hOldFont
    DeleteObject hFont

END SUB
                                         

Print this item

  WAITKEY$ not in FreeBASIC
Posted by: Dale Yarker - 23.09.2025, 14:03 - Forum: Programming - Replies (3)

not posted in FreeBASIC forum because a PB user will know what I'm talking about.

I'm having bad success compiling and running (from tiko).

(before someone bitches - isn't helping coders only used to PB a good subject for PUMP?

One problem is the FreeBASIC "appears" not to run because console never shows. They do run from Command Prompt because console does not close at end of code. I can not find an equivalent to WAITKEY$ in FreeBASIC. The problem presents with samples from FreeBASIC and tiko too. FreeBASIC INKEY in a loop should work. Is that the answer?

GUI sample problems later.

(repeat from elsewhere- I'm not really transitioning from PB to FreeBASIC. It is a 64 bit alternative even though what I do does not need that much horsepower)

Cheers,

Print this item

  gbScroller - Scroll Image
Posted by: Gary Beene - 23.09.2025, 06:04 - Forum: Source Code Library - Replies (1)

gbScroller is the companion app to gbClientCapture.  Both are intended to support viewing of sheet music in a horizontal format.

gbClientCapture captures multiple images from a music sheet and merges them into a single horizontal image.

gbScroller displays the merged image, scrolling it to the left.

Both are discussed in the same thread. http://pump.richheimer.de/showthread.php...562#pid562

Features:
1. Zoom the merged image
2. Scroll the merged image, with speed control 
3. Display a vertical line between individual images

[Image: gbscroller.jpg]

Files for both gbClientCapture and gbScroller are in the zip https://garybeene.com/files/gbclientcapture.zip

Code:
'Compilable Example: Jose Includes

#Compile Exe  "gbscroller.exe"
#Dim All

#Debug Error On
#Debug Display On

%Unicode = 1

#Include "WIN32API.INC"
#Include "cgdiplus.inc" '<-replace with Jose or you own GDI+ include file.

Enum Equates Singular
   IDC_Toolbar   = 500
   IDC_Graphic
   IDT_Exit
   IDT_Faster
   IDT_Slower
   IDT_View
   IDT_ShowLine
   IDT_Scroll
   IDC_StatusBar
   IDT_ResetZoom
   IDT_ResetScroll
   IDC_Up
   IDC_Down
   IDT_StopScroll
   IDT_Plus
   IDT_Minus
   ID_Timer
End Enum

#Resource Manifest, 1,      "icons\xptheme_dpiaware.xml"

#Resource Icon logo, "icons\scroll2.ico"
#Resource Icon zexit, "icons\power.ico"
#Resource Icon zview, "icons\view.ico"
#Resource Icon zleft, "icons\scrollleft.ico"
#Resource Icon zright, "icons\scrollright.ico"
#Resource Icon zstop, "icons\stop.ico"
#Resource Icon zplus, "icons\plus.ico"
#Resource Icon zminus, "icons\minus.ico"
#Resource Icon zreset, "icons\reset.ico"

$Ver = "1.1"

Global hDlg, hToolbar, hList, hFont As Dword
Global Scroll, ShowLine, TimerInterval, ImageWidth, ImageHeight,XDelta As Long
Global SBW, SBH, TBW, TBH As Long, Zoom As Single

Function PBMain() As Long
   Dialog New Pixels, 0, "gbScroller v" + $Ver,,,100,100, %WS_OverlappedWindow To hDlg
   Dialog Set Icon hDlg, "logo"
   Font New "Tahoma",10, 0 To hFont
   CreateImageList
   CreateToolbar
   CreateStatusBar
   Dialog Show Modal hDlg, Call DlgMain
End Function

CallBack Function DlgMain()
   Local iReturn As Long
   Select Case As Long Cb.Msg
      Case %WM_InitDialog
         BuildAcceleratorTable
         settings_ini "get"
         GetImageSize
         CreateGraphic
         Statusbar Set Text hDlg, %IDC_StatusBar, 1, 0, "gbScroller v" + $Ver + "       Zoom = " + Str$(Zoom) + "       Timer Interval = " + Str$(TimerInterval)

      Case %WM_Size : ResizeDialog

      Case %WM_Timer : ScrollImage : SetStatusBar

      Case %WM_Help

      Case %WM_Command
         Select Case Cb.Ctl
            Case %IdCancel        : sBeep : Dialog End hDlg
            Case %IDT_Exit        : sBeep : Dialog End hDlg
            Case %IDT_Scroll      : sBeep : ManageScroll : CreateToolbar
            Case %IDT_StopScroll  : sBeep : ManageScroll : CreateToolbar
            Case %IDT_Faster      : sBeep : ChangeSpeed(-1) : CreateToolbar
            Case %IDT_Slower      : sBeep : ChangeSpeed(+1) : CreateToolbar
            Case %IDT_Plus        : sBeep : Magnify(+1)
            Case %IDT_Minus       : sBeep : Magnify(-1)
            Case %IDT_ResetZoom   : sBeep : Magnify(0)
            Case %IDT_ResetScroll : sBeep : ResetScroll
            Case %IDT_ShowLine    : sBeep : ShowLine Xor=1 : DrawLines(IIf(ShowLine,%Red,-2)) : Graphic ReDraw
            Case %IDT_View        : sBeep : iReturn = ShellExecute(hDlg, "Open", "merge.bmp", $Nul, $Nul, %SW_ShowNormal)

         End Select

      Case %WM_Destroy
         settings_ini "save"
   End Select
End Function

Sub CreateStatusBar
   Control Add Statusbar, hDlg, %IDC_StatusBar, "Welcome to gbScroller v" + $Ver, 0,0,0,0, %CCS_Bottom Or %SBars_SizeGrip
   Control Get Size hDlg, %IDC_StatusBar To SBW, SBH
   Control Set Font hDlg, %IDC_StatusBar, hFont
End Sub

Sub CreateGraphic
   Local w,h As Long
   Dialog Get Client hDlg To w,h
   Control Add Graphic, hDlg, %IDC_Graphic, "", 10, TBH, w-20,h, %WS_Border
   Graphic Attach hDlg, %IDC_Graphic, ReDraw
   Graphic Set Virtual ImageWidth, ImageHeight
   Graphic Color %Black, %White
   Graphic Clear
End Sub

Sub CreateImageList
   ImageList New Icon 48,48,32,20 To hList
   ImageList Add Icon hList, "zexit"   '1
   ImageList Add Icon hList, "zleft"   '2
   ImageList Add Icon hList, "zright"  '3
   ImageList Add Icon hList, "zstop"  '4
   ImageList Add Icon hList, "zplus"  '5
   ImageList Add Icon hList, "zminus"  '6
   ImageList Add Icon hList, "zreset"  '7
   ImageList Add Icon hList, "zview"  '8
End Sub

Sub CreateToolbar
   Control Kill hDlg, %IDC_Toolbar
   Control Add Toolbar, hDlg, %IDC_Toolbar, "", 0,0,0,0 , %TbStyle_Flat Or %CCS_NoDivider
   Control Handle hDlg, %IDC_Toolbar To hToolbar
   Toolbar Set ImageList hDlg, %IDC_Toolbar, hList, 0

   Toolbar Add Button hDlg, %IDC_Toolbar, 1, %IDT_Exit, %TbStyle_Button, " Exit "

   Toolbar Add Separator hDlg, %IDC_Toolbar, 50

   Toolbar Add Button hDlg, %IDC_Toolbar, 5, %IDT_Plus, %TbStyle_Button, " ZoomIn "
   Toolbar Add Button hDlg, %IDC_Toolbar, 6, %IDT_Minus, %TbStyle_Button, " ZoomOut "
   Toolbar Add Button hDlg, %IDC_Toolbar, 7, %IDT_ResetZoom, %TbStyle_Button, " Reset "

   Toolbar Add Separator hDlg, %IDC_Toolbar, 50

   If Scroll = 0 Then Toolbar Add Button hDlg, %IDC_Toolbar, 8, %IDT_Scroll, %TbStyle_Button, " Scroll "
   If Scroll = 1 Then Toolbar Add Button hDlg, %IDC_Toolbar, 4, %IDT_StopScroll, %TbStyle_Button, " Stop "
   Toolbar Add Button hDlg, %IDC_Toolbar, 2, %IDT_Slower, %TbStyle_Button, " Slower "
   Toolbar Add Button hDlg, %IDC_Toolbar, 3, %IDT_Faster, %TbStyle_Button, " Faster "
   Toolbar Add Button hDlg, %IDC_Toolbar, 7, %IDT_ResetScroll, %TbStyle_Button, " Reset "

   Control Set Font hDlg, %IDC_StatusBar, hToolbar
   Control Get Size hDlg, %IDC_Toolbar To TBW, TBH

End Sub

Sub Settings_INI(Task$)
   Local x,y,w,h, tempz, INIFileName As WStringZ * %Max_Path, WinPla As WindowPlacement

   'set ini filename
   INIFileName = Exe.Path$ + Exe.Name$ + ".ini"    'get INI file name

   Select Case Task$
      Case "get"
         'get dialog width/height from INI file and use to set Dialog size
         GetPrivateProfileString "All", "Width", "1200", w, %Max_Path, INIFileName
         GetPrivateProfileString "All", "Height", "300", h, %Max_Path, INIFileName
         Dialog Set Size hDlg,Val(w), Val(h)   'width/height

         'get dialog top/left from INI file and use to set Dialog location
         Getprivateprofilestring "All", "Left", "0", x, %Max_Path, INIFileName
         Getprivateprofilestring "All", "Top", "0",  y,  %Max_Path, INIFileName
         If IsFile(INIFileName) Then Dialog Set Loc hDlg, Val(x), Val(y)   'left/top but only once INIFileName exists

         'get value for string variables
'         GetPrivateProfileString "All", "FontName", "Arial Black", FontName, %Max_Path, INIFileName

         'get value for numeric variables
         Getprivateprofilestring "All", "ImageWidth", "",        tempz, %Max_Path, INIFileName   : ImageWidth = Val(tempz)
         Getprivateprofilestring "All", "ImageHeight", "",       tempz, %Max_Path, INIFileName   : ImageHeight = Val(tempz)
         Getprivateprofilestring "All", "TimerIntereval", "50", tempz, %Max_Path, INIFileName   : TimerInterval = Val(tempz)
         Getprivateprofilestring "All", "Zoom", "1",             tempz, %Max_Path, INIFileName   : Zoom = Val(tempz)
         Getprivateprofilestring "All", "XDelta", "2",           tempz, %Max_Path, INIFileName   : XDelta = Val(tempz)
         Getprivateprofilestring "All", "ShowLine", "1",         tempz, %Max_Path, INIFileName   : ShowLine = Val(tempz)

      Case "save"
         If IsFile(INIFileName) Then Kill INIFileName    'clear the INI file Name to remove residual entries before saving
         WinPla.Length = SizeOf(WinPla)
         GetWindowPlacement hDlg, WinPla
         WritePrivateProfileString "All", "Left",   Str$(WinPla.rcNormalPosition.nLeft), INIFileName
         WritePrivateProfileString "All", "Top",    Str$(WinPla.rcNormalPosition.nTop), INIFileName
         WritePrivateProfileString "All", "Width",  Str$(WinPla.rcNormalPosition.nRight - WinPla.rcNormalPosition.nLeft), INIFileName
         WritePrivateProfileString "All", "Height", Str$(WinPla.rcNormalPosition.nBottom - WinPla.rcNormalPosition.nTop), INIFileName

         'save string variables
'         WritePrivateProfileString "All", "FontName",   FontName, INIFileName

         'save numeric variables
         WritePrivateProfileString "All", "ImageHeight",    Str$(ImageHeight), INIFileName
         WritePrivateProfileString "All", "ImageWidth",     Str$(ImageWidth), INIFileName
         WritePrivateProfileString "All", "TimerInterval",  Str$(TimerInterval), INIFileName
         WritePrivateProfileString "All", "Zoom",           Str$(Zoom), INIFileName
         WritePrivateProfileString "All", "XDelta",         Str$(XDelta), INIFileName
         WritePrivateProfileString "All", "ShowLine",       Str$(ShowLine), INIFileName
   End Select
End Sub

Sub sBeep : WinBeep(275,150) : End Sub

Sub BuildAcceleratorTable
   Local ac() As ACCELAPI, hAccelerator As Dword, c As Long  ' for keyboard accelator table values
   Dim ac(2)
   ac(c).fvirt = %FVIRTKEY : ac(c).key   = %VK_V  : ac(c).cmd = %IDT_View        : Incr c
   ac(c).fvirt = %FVIRTKEY : ac(c).key   = %VK_L  : ac(c).cmd = %IDT_ShowLine    : Incr c
   ac(c).fvirt = %FVIRTKEY : ac(c).key   = %VK_S  : ac(c).cmd = %IDT_Scroll      : Incr c
   Accel Attach hDlg, AC() To hAccelerator
End Sub

Sub ResizeDialog
   Local w,h, x1,y1 As Long
   Dialog Get Client hDlg To w,h
   Control Set Size hDlg, %IDC_Graphic, w-20, h-TBH-SBH-10
   Control Get Client hDlg, %IDC_Graphic To w,h

   x1 = 0
   y1 = (h-Zoom*ImageHeight)/2

   Graphic Color %Black, %White
   Graphic Width 2
   Graphic Clear
   Graphic Set StretchMode %HalfTone
   Graphic Render Bitmap "merge.bmp", (x1,y1)-(x1+Zoom*ImageWidth,y1+Zoom*ImageHeight)
   If ShowLine Then DrawLines (%Red)
   Graphic ReDraw
   SetStatusBar
End Sub

Sub DrawLines (LineColor As Long)
   Local w,h,i, SingleImageX As Long
   Graphic Get Canvas To w,h
   SingleImageX = w / ImageCount
   Graphic Color LineColor, %White
   For i = 1 To ImageCount-1
      Graphic Line (i*SingleImageX-5,0)-(i*SingleImageX-5,h)
   Next i
End Sub

Sub SetStatusBar
   Statusbar Set Text hDlg, %IDC_StatusBar, 1, 0, "gbScroller v" + $Ver + "       Zoom = " + Str$(Zoom) + "       Timer Interval = " + Str$(TimerInterval) + "      " + Time$
End Sub

Function ImageCount As Long
   Local iCount As Long, temp$
   temp$ = Dir$("images\*.*")
   While Len(temp$)
      Incr iCount
      temp$ = Dir$(Next)
   Wend
   Function = iCount
End Function

Sub GetImageSize 'get image size for bmp$
   Local hBMP As Dword
   Graphic Bitmap Load "merge.bmp", 0, 0 To hBMP
   Graphic Attach hBMP, 0
   Graphic Get Canvas To ImageWidth, ImageHeight
   Graphic Bitmap End
End Sub

Sub ChangeSpeed(iDelta As Long)
   Select Case iDelta
      Case 0   : TimerInterval  = 0  : Scroll = 0 'stopped
      Case 1   : TimerInterval += 10 : Scroll = 1 'slower
      Case -1  : TimerInterval -= 10 : Scroll = 1 'faster
   End Select

   If TimerInterval < 10 Then TimerInterval = 10 : sBeep

   KillTimer hDlg, %ID_Timer
   SetTimer hDlg, %ID_Timer, TimerInterval, %Null
   SetStatusBar
End Sub

Sub Magnify(iDelta As Long)
   Select Case iDelta
      Case 0  : Zoom = 1
      Case 1  : Zoom += 0.25
      Case -1 : Zoom -= 0.25
   End Select
   If Zoom < 1 Then Zoom = 1
   ResizeDialog
End Sub

Sub ManageScroll
   Scroll Xor=1
   If Scroll Then
      SetTimer hDlg, %ID_Timer, TimerInterval, %Null
   Else
      KillTimer hDlg, %ID_Timer
   End If
End Sub

Sub ResetScroll
   Local w,h As Long
   Graphic Get View To w,h
   Graphic Set View 0, h
End Sub

Sub ScrollImage
   Local w,h,ww,hh,www,hhh As Long
   Graphic Get View To w,h
   Graphic Set View w+XDelta, h

   Control Get Client hDlg, %IDC_Graphic To www,hhh
   Graphic Get Canvas To ww,hh
   'Dialog Set Text hDlg, Str$(w+XDelta) + Str$(ImageWidth)

   If w+XDelta >= (ImageWidth-www) Then
      sBeep : sBeep
      ManageScroll : CreateToolbar
   End If
End Sub

Print this item

  gbClientCapture (Discussion)
Posted by: Gary Beene - 20.09.2025, 19:43 - Forum: PowerBASIC for Windows - Replies (21)

I decided to break the gbScroller app into two parts. The first is posted in the forum as gbClientCapture.

It captures the area under the transparent dialog client, merging each new capture into a horizontal image for subsequent scrolling. I've not yet written the scrolling app.

The area between the Toolbar and Statusbar is captured and merged into a horizontal image.

[Image: capture.jpg]


Some new features come to mind:

1. allow using the arrow keys to more accurately position the dialog
2. with transparency, the resize with a mouse ability is limited to the caption and toolbar. Not sure why but I know I don't like it.

Not a feature, but I notice there is a tiny gap between the caption and toolbar. I'm not sure why. I thought the toolbar by default would be positioned immediately next to the caption.

And, another thing, I tweaked the various dimensions to make sure the client area is captured, without overlapping the toolbar, statusbar and dialog borders. But it seems to me that I should have been able to do a more exact dimensioning of the capture positioning/size.

Here's how I envision this working.

1. Call up the electronic copy of the music (PDF in this example).
2. Place gbClientCapture over the first row of music (resize as needed)
3. Click "Copy"
4. Scroll the PDF upwards until the next row of music is under gbClientCapture (that should be easier than moving the dialog itself.
5. Click "Copy"
6. Repeat until all rows of music are captured and placed in the "merge.bmp" file.

In this example, the Adele music sheet PDF is displayed vertically in my browser.  The gbClientCapture is positioned over the first row, ready for "Copy".  Then, instead of moving the dialog to a new position, I scroll the PDF upwards until the next row of music is visible under the dialog client area. Repeat Copying untill all rows of music are captured. With each capture the "merge.bmp" file is updated to contain the most recent capture.

[Image: capture2.jpg]

Print this item

  gbClientCapture
Posted by: Gary Beene - 20.09.2025, 19:38 - Forum: Source Code Library - Replies (1)

This app displays a transparent dialog, with a Toolbar and a Statusbar. Images under the open dialog client area are captured and merged into a horizontal image.  This will be used by my next app to scroll the horizontal image - corresponding to my post about breaking vertical sheet music into scrollable horizontal music.

Discussion is here.

Toolbar buttons:

1. Exit - close gbClientCapture

2. Copy - captures the desktop below the transparent dialog client and saves it as a BMP. each capture is merged with previous captures to form a horizontal image (first captured image on the left, last captured image on the right)

3. New - deletes all images, including the merged image

4. View - opens the current merged image in the default image viewer

The Statusbar keeps track of how many images there are in the image folder.

Here's a picture of the app, with some desktop showing through the client area.

[Image: capture.jpg]

Code and images are here:  https://www.garybeene.com/files/gbclientcapture.zip

Code:
'Compilable Example:  (Jose Includes)
#Compile Exe  "gbclientcapture.exe"
#Dim All

#Debug Error On
#Debug Display On

%Unicode=1
#Include "Win32API.inc"

%IDC_Toolbar   = 500
%IDT_Exit      = 501
%IDT_Copy      = 502
%IDT_New       = 503
%IDT_View      = 504
%IDC_StatusBar = 505

#Resource Manifest, 1,      "icons\xptheme_dpiaware.xml"
#Resource VersionInfo
#Resource StringInfo "0409", "04B0"
#Resource Version$ "CompanyName", "New Vision Concepts"
#Resource Version$ "ProductName", "gbClientCapture"
#Resource Version$ "ProductVersion", "1.0"
#Resource Version$ "FileDescription",  "gbClientCapture - Capture Desktop Behind Client"
#Resource Version$ "LegalCopyright",   "Copyright 2025 New Vision Concepts"

#Resource Icon logo, "icons\alogo.ico"
#Resource Icon zexit, "icons\power.ico"
#Resource Icon zcopy, "icons\copy.ico"
#Resource Icon znew, "icons\new.ico"
#Resource Icon zmerge, "icons\view.ico"

$Ver = "1.0"

Global hDlg, hToolbar, hList, hBrush, hFont As Dword
Global ImageCount, ImageWidth, ImageHeight As Long
Global SBW, SBH, TBW, TBH As Long

Function PBMain() As Long
   Dialog New Pixels, 0, "gbClientCapture  v" + $Ver,300,50,200,100, %WS_OverlappedWindow, %WS_Ex_Layered To hDlg
   Dialog Set Icon hDlg, "logo"
   Dialog Set Color hDlg, %Black, %White
   CreateToolbar

   Control Add Statusbar, hDlg, %IDC_StatusBar, "", 0,0,0,0, %CCS_Bottom Or %SBars_SizeGrip
   Control Get Size hDlg, %IDC_StatusBar To SBW, SBH
   Control Set Color hDlg, %IDC_StatusBar, %Black, %Gray

   Font New "Tahoma",10, 1 To hFont
   Control Set Font hDlg, %IDC_Toolbar, hFont
   Control Set Font hDlg, %IDC_StatusBar, hFont

   Dialog Show Modal hDlg Call DlgProc
End Function

CallBack Function DlgProc() As Long
   Select Case Cb.Msg
      Case %WM_InitDialog
         hBrush = CreateSolidBrush(RGB(243,243,243))
         SetWindowPos hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE Or %SWP_NOSIZE
         If IsFalse IsFolder("images") Then MkDir "images"
         Settings_INI "get"
         Statusbar Set Text hDlg, %IDC_StatusBar, 1, 0, "ImageCount = " + Format$(ImageCount)
         SetLayeredWindowAttributes(hDlg, %White, 255, %LWA_ALPHA Or %LWA_Colorkey)
      Case %WM_ContextMenu
         sBeep : Dialog End hDlg
      Case %WM_Command
         Select Case Cb.Ctl
            Case %IDT_Exit  : sBeep : Dialog End hDlg
            Case %IDT_Copy  : sBeep : SaveDialogToClipboard : MergeImages
            Case %IDT_New   : sBeep : NewProject
            Case %IDT_View : sBeep : ViewMerge
         End Select

      Case %WM_Notify
         Select Case Cb.NmId
            Case %IDC_Toolbar
               Local pTbCustDraw As NmTbCustomDraw Pointer
               pTbCustDraw  = Cb.LParam
               Select Case @pTbCustDraw.nmcd.dwDrawStage
                  Case %CDDS_PREPAINT  ' paint entire toolbar
                     FillRect(@pTbCustDraw.nmcd.hdc, @pTbCustDraw.nmcd.rc, hBrush)
                     Function = %CDRF_NOTIFYITEMDRAW
               End Select
         End Select

      Case %WM_Destroy
         DeleteObject hBrush
         Settings_INI "save"
   End Select
End Function

Sub CreateToolbar
   ImageList New Icon 32,32,32,20 To hList
   ImageList Add Icon hList, "zexit"   '1
   ImageList Add Icon hList, "zcopy"   '2
   ImageList Add Icon hList, "znew"    '3
   ImageList Add Icon hList, "zmerge"  '4

   Control Add Toolbar, hDlg, %IDC_Toolbar, "", 0,0,0,0 ', %TbStyle_Flat
   Control Handle hDlg, %IDC_Toolbar To hToolbar
   Toolbar Set ImageList hDlg, %IDC_Toolbar, hList, 0

   Toolbar Add Button hDlg, %IDC_Toolbar, 1, %IDT_Exit, %TbStyle_Button, " Exit "
   Toolbar Add Button hDlg, %IDC_Toolbar, 2, %IDT_Copy, %TbStyle_Button, " Copy "
   Toolbar Add Button hDlg, %IDC_Toolbar, 3, %IDT_New, %TbStyle_Button, " New "
   Toolbar Add Button hDlg, %IDC_Toolbar, 4, %IDT_View, %TbStyle_Button, " View "

   Control Get Size hDlg, %IDC_Toolbar To TBW, TBH

End Sub

Sub Settings_INI(Task$)
   Local x,y,w,h, tempz, INIFileName As WStringZ * %Max_Path, WinPla As WindowPlacement

   'set ini filename
   INIFileName = Exe.Path$ + Exe.Name$ + ".ini"    'get INI file name

   Select Case Task$
      Case "get"
         'get dialog width/height from INI file and use to set Dialog size
         GetPrivateProfileString "All", "Width", "1200", w, %Max_Path, INIFileName
         GetPrivateProfileString "All", "Height", "300", h, %Max_Path, INIFileName
         Dialog Set Size hDlg,Val(w), Val(h)   'width/height

         'get dialog top/left from INI file and use to set Dialog location
         Getprivateprofilestring "All", "Left", "0", x, %Max_Path, INIFileName
         Getprivateprofilestring "All", "Top", "0",  y,  %Max_Path, INIFileName
         If IsFile(INIFileName) Then Dialog Set Loc hDlg, Val(x), Val(y)   'left/top but only once INIFileName exists

         'get value for string variables
'         GetPrivateProfileString "All", "FontName", "Arial Black", FontName, %Max_Path, INIFileName

         'get value for numeric variables
         Getprivateprofilestring "All", "ImageWidth", "",     tempz, %Max_Path, INIFileName   : ImageHeight = Val(tempz)
         Getprivateprofilestring "All", "ImageHeight", "",    tempz, %Max_Path, INIFileName   : ImageWidth = Val(tempz)
         Getprivateprofilestring "All", "ImageCount", "0",    tempz, %Max_Path, INIFileName   : ImageCount = Val(tempz)

      Case "save"
         If IsFile(INIFileName) Then Kill INIFileName    'clear the INI file Name to remove residual entries before saving
         WinPla.Length = SizeOf(WinPla)
         GetWindowPlacement hDlg, WinPla
         WritePrivateProfileString "All", "Left",   Str$(WinPla.rcNormalPosition.nLeft), INIFileName
         WritePrivateProfileString "All", "Top",    Str$(WinPla.rcNormalPosition.nTop), INIFileName
         WritePrivateProfileString "All", "Width",  Str$(WinPla.rcNormalPosition.nRight - WinPla.rcNormalPosition.nLeft), INIFileName
         WritePrivateProfileString "All", "Height", Str$(WinPla.rcNormalPosition.nBottom - WinPla.rcNormalPosition.nTop), INIFileName

         'save string variables
'         WritePrivateProfileString "All", "FontName",   FontName, INIFileName

         'save numeric variables
         WritePrivateProfileString "All", "ImageHeight",    Str$(ImageHeight), INIFileName
         WritePrivateProfileString "All", "ImageWidth",     Str$(ImageWidth), INIFileName
         WritePrivateProfileString "All", "ImageCount",     Str$(ImageCount), INIFileName
   End Select
End Sub

Sub sBeep : WinBeep(275,150) : End Sub

Sub NewProject  'remove all \images\*.bmp
   Local temp$
   Clipboard Reset
   ImageCount = 0
   temp$ = Dir$("images\*.bmp")
   If Len(temp$) Then Kill "images\*.bmp"
   Statusbar Set Text hDlg, %IDC_StatusBar, 1, 0, "ImageCount = " + Format$(ImageCount)
End Sub

Sub SaveDialogToClipboard
   Local x,y As Long, hBMP, hBMPDC, hDC As Dword       '         abcdegfg
   'create memory bitmap the size of the dialog client (less Toolbar and less StatusBar)
   Dialog Get Client hDlg To ImageWidth, ImageHeight
   ImageWidth = ImageWidth - 1
   ImageHeight = ImageHeight - SBH - TBH - 2

   Graphic Bitmap New ImageWidth, ImageHeight To hBMP
   Graphic Attach hBMP,0
   Graphic Get DC To hBMPDC

   'bitblt dialog rectangle from the screen to the me                            mory bitmap
   Dialog Get Loc hDlg To x,y
   x = x + 9
   y = y + TBH + CaptionHeight - 7
   hDC = GetDC(%Null)
   BitBlt hBMPDC, 0,0,ImageWidth,ImageHeight, hDC, x,y, %SRCCopy 'copy desktop image to
   ReleaseDC(%Null,hDC)

   'save to file
   Incr ImageCount
   Graphic Save "images\" + Format$(ImageCount) + ".bmp"

   'send to clipboard
   Clipboard Reset
   Clipboard Set Bitmap hBMP

   'get rid of the bitmap
   Graphic Bitmap End

   'count images
   Statusbar Set Text hDlg, %IDC_StatusBar, 1, 0, "ImageCount = " + Format$(ImageCount)

End Sub

Function captionHeight As Long
   Local cw,ch,ddw,ddh As Long
   Dialog Get Size hDlg To ddw,ddh
   Dialog Get Client hDlg To cw,ch
   Function = ddh-ch
End Function

Sub MergeImages
   Local i, x1, y1, x2, y2 As Long
   Local hBMP, hBMPDC As Dword, ImageName$

   If IsFile("merge.bmp") Then Kill "merge.bmp"

   Graphic Bitmap New ImageCount*ImageWidth,ImageHeight To hBMP
   Graphic Attach hBMP,0
   Graphic Get DC To hBMPDC

   For i = 1 To ImageCount
      ImageName$ = "images\" + Format$(i) + ".bmp"
      x1 = (i-1) * ImageWidth
      x2 = x1 + ImageWidth
      y1 = 0
      y2 = ImageHeight
      Graphic Render Bitmap ImageName$, (x1,y1)-(x2,y2)
   Next i

   Graphic Save "merge.bmp"
   Graphic Bitmap End
End Sub

Sub ViewMerge
   Local iReturn As Long, hBMP As Dword

   Graphic Bitmap Load "merge.bmp", 0,0 To hBMP
   Graphic Attach hBMP,0

   Clipboard Reset
   Clipboard Set Bitmap hBMP

   Graphic Bitmap End

   iReturn = ShellExecute(hDlg, "Open", "merge.bmp", $Nul, $Nul, %SW_ShowNormal)
End Sub

Print this item

  File Transfer Between PCs
Posted by: Gary Beene - 19.09.2025, 22:32 - Forum: PowerBASIC for Windows - Replies (2)

I want to move all DOCX files from an old PC to my new PC, preferably by first putting them all on a flash drive which I use for the transfer.

I've posted code before that would capture a list of files anywhere on the PC that match a filespec such as "*.docx". I can use that to copy files to the flash.

But because some files have the same name, I can't just fill the root folder of the flash with all the files by their original name.  To do that I would have to rename files - such as with a simple prefix of "00001", "0002", etc.  Or, I could prefix the original folder name onto each file name, substituting the \ characters with an underscore.  That won't recreate the old folder structure on the new PC, but will at least capture all of the files.

Better yet, I could use something like Beyond Compare to find only DOCX files and replicate the original folder structure onto the new PC.  That's the most "exact" approach, but I'd have to be careful not to inappropriately overwrite any files on the new PC.

As best I know, the command line xcopy can do a similar thing but doesn't as easily et you pick and chose which files to copy.

Anyone use a better solution?

Print this item

  DOCX and XLSX Viewer
Posted by: Gary Beene - 18.09.2025, 04:30 - Forum: PowerBASIC for Windows - Replies (9)

I'd like to display DOCX and XLSX files with their full visual content.

But, I need for the solution to NOT require Word/Excel be installed on a user's PC.

Is that possible?

Print this item