using the clipboard for communicatign between programs
#13
No fancy local hosting in this example but it is a useful example on how to use _clipboard$ to open another window (well it's really another program) to serve as a control panel.

A simple ascii doodle program that will let the user doodle in the window with the mouse.
(EDIT: updated to use colorpick16.exe)

Code: (Select All)
'clipboard communcation sample
'an ascii doodle pad that opens a control panel app in another window
'
Screen _NewImage(60, 30, 0)
_Title "ClipDoodle"
Cls
_Clipboard$ = "ClipDoodleOn" ' "clears" clipboard for use
Shell _DontWait "pickclip.exe" ' Open the pickclip control panel
Shell _DontWait "colorpick16.exe" ' Open the color control panel

_ControlChr Off
AK = 42
Do
    _Limit 100
    Do While _MouseInput 'mouse status changes only
        _Limit 2000
        x = _MouseX
        y = _MouseY

        If _MouseButton(1) Then
            _PrintString (x, y), brush$
        End If
    Loop
    kk$ = InKey$
    ik$ = _Clipboard$
    If Left$(ik$, 2) = "AC" Then AK = Val(Right$(ik$, Len(ik$) - 2))
    If Left$(ik$, 2) = "CK" Then
        ff$ = " "
        n = 2
        Do
            n = n + 1
            A$ = Mid$(ik$, n, 1)
            If A$ <> "/" Then ff$ = ff$ + A$
        Loop Until A$ = "/"
        bb$ = ""
        Do
            A$ = Mid$(ik$, n, 1)
            If A$ <> "/" Then bb$ = bb$ + A$
            n = n + 1
        Loop Until n > Len(ik$)
        FG = Val(ff$): BG = Val(bb$)
        Color FG, BG
    End If
    brush$ = Chr$(AK)
Loop Until kk$ = Chr$(27)
_Clipboard$ = "QUITCOLORPICK16"
Sleep 1
_Clipboard$ = "QUITCLIPPICK"
System


compile this part as pickclip.exe
Code: (Select All)
'pickclip
'complie as pickclip.exe
'sample of a "control panel" feeding output to the clipboard
Screen _NewImage(33, 20, 0)
_ScreenMove 600, 0
_Title "Pick Clip"
_ControlChr Off
AA = 0
'builds ascii grid
For y = 1 To 16
    For x = 1 To 16
        _PrintString (x * 2, y), Chr$(AA)
        AA = AA + 1
    Next
Next
Do
    _Limit 100
    Do While _MouseInput 'mouse status changes only
        x = _MouseX
        y = _MouseY
        If _MouseButton(1) Then
            x = Int(x / 2)
            AK = (y - 1) * 16 + (x - 1)
            _PrintString (1, 18), "                     "
            If AK > -1 And AK < 256 Then pp$ = "Picked ASCII " + Str$(AK) + " : " + Chr$(AK)
            _PrintString (1, 18), pp$
            _Clipboard$ = "AC" + Str$(AK)
        End If
    Loop
    kk$ = InKey$
    If _Clipboard$ = "QUITCLIPPICK" Then kk$ = "QUITALL"
Loop Until kk$ = "QUITALL" Or kk$ = "Q"
_Clipboard$ = "pickclip did quit" 'so QUIT message isn't left in clipboard
System


When both are compiled clipdoodle will open pickclip. Anytime you click on a character to select it that character will get put in the clipboard as "AC"+ascii# to be read by clipdoodle. If you accidentally close pickclip you can reopen it again without impacting the clipdoodle.
When you quit clipdoodle by pressing <esc> it will put a message on the clipboard telling pickclip to quit as well.
Reply


Messages In This Thread
RE: using the clipboard for communicatign between programs - by James D Jarvis - 10-24-2022, 01:09 PM



Users browsing this thread: 8 Guest(s)