Posted in response to http://www.powerbasic.com/support/pb...ad.php?t=40827
Not tested since dates noted
Not tested since dates noted
Code:
$IF 0 File: PBCLIP.BAS Send code to..from the Widows 3.x clipboard. Tested 8.28.98 Works good in IDE in DOS box Win 3.11 Tested 8.19.99 under Windows 98 in IDE, works OK. OK from EXE thru Explorer, too. Posted by Dave Navarroposted 08-26-98 03:44 PM PT (US) ------------------------------------------------------------------------ This code was sent to us by Andy Golden: '--- PBWINCLP.BAS- Windows Clipboard for PowerBasic 3.0 '--- based on '--- WINCLIP.BAS - Windows Clipboard Functions from DOS '--- by Harry F. Harrison, PCMagazine vol13n02.zip (1-25-94) ---------------------------------------------------------------- $ENDIF DEFINT A-Z %FLAGS=0 %AX=1 %BX=2 %CX=3 %DX=4 %SI=5 %DI=6 %BP=7 %DS=8 %ES=9 DECLARE FUNCTION ClearClipboard% () DECLARE FUNCTION GetClipboardData$ () DECLARE FUNCTION GetClipboardDataSize% () DECLARE FUNCTION OpenClipboard% () DECLARE FUNCTION SetClipboardData% (Text$) DECLARE SUB CloseClipboard () DECLARE FUNCTION ASMSetClipB% (BYVAL long, BYVAL long, BYVAL integer) DECLARE FUNCTION ASMGetClipB% (BYVAL long, BYVAL long) %True = -1 %False = 0 '=== BEGIN DEMONSTRATION PORTION cls PRINT "Starting Test Run" IF LEN(ENVIRON$("windir")) = 0 THEN PRINT "Windows is not loaded!" END END IF IF NOT OpenClipboard% THEN PRINT "Unable to open the Windows Clipboard." END END IF Msg$ = "No really, this is being passed through the Clipboard." IF NOT SetClipboardData%(Msg$) THEN PRINT "Unable to send a message to the Clipboard." END IF CALL CloseClipboard 'close it for a moment Dummy = OpenClipboard 'reopen to prove this works NewMsg$ = GetClipboardData$ 'get the message CALL CloseClipboard 'close it for real this time PRINT NewMsg$ 'and print the message END '=== END DEMONSTRATION PORTION FUNCTION OpenClipboard% 'This function opens the Clipboard for your VM (Virtual 'Machine). Once you have opened the Clipboard, no other 'application can access it. You must close the clipboard 'when you are finished, to allow other applications to 'access it. ' returns: -1 if open successful. local temp& ASM mov ax,&H1701 ;open clipboard ASM int &H2F ASM mov temp&,ax IF temp& THEN OpenClipboard% = %TRUE END FUNCTION FUNCTION SetClipboardData%(Text$) local temp&, length%, pointr&, segmnt& IF LEN(Text$) THEN length%=LEN(Text$) IF ClearClipboard% = %TRUE THEN pointr&=STRPTR(Text$):segmnt&=STRSEG(Text$) temp&=0 IF ASMSetClipB%(pointr&,segmnt&,length%) THEN SetClipboardData% = %TRUE END IF END IF END IF END FUNCTION SUB CloseClipboard 'This routine closes the Windows Clipboard. It is essential 'that your application closes the clipboard, or no other 'application can get access to it. local temp& ASM mov ax,&H1708 ;Close Clipboard ASM int &H2f ASM mov temp&,ax END SUB FUNCTION GetClipboardData$ 'This routine gets the Windows clipboard text, and returns it 'in a string. The Clipboard must be opened first before it can 'be accessed. 'Before you can get the data, you must know how large the data 'is, to allocate space for it in a BASIC string. ' local temp&, length%, pointr&, segmnt& Length% = GetClipboardDataSize% IF Length% > 0 THEN 'There is data, get it Temp$ = STRING$(Length%, 0) 'Allocate the space in BASIC pointr&=STRPTR(Temp$):segmnt&=STRSEG(Temp$) ' IF ASMGetClipB% (pointr&, segmnt&) THEN 'If present it's null-terminated Length% = INSTR(Temp$, CHR$(0)) IF Length% THEN 'Return with the data GetClipboardData$ = LEFT$(Temp$, Length%) END IF END IF END IF END FUNCTION FUNCTION GetClipboardDataSize% 'The clipboard stores text and graphics, so DX stores the data 'selector. 1 = Text, 2 = Graphics. The length of the data is 'returned in AX. local temp& ASM mov ax,&H1704 ;Get clipboard data size ASM mov dx,1 ;Request Text ASM int &H2f ASM mov temp&,ax GetClipboardDataSize% = temp& END FUNCTION FUNCTION ClearClipboard% 'This Function returns %TRUE (-1) if the Clipboard was cleared. 'The clipboard must be opened first. local temp& ASM mov ax,&H1702 ;Clear Clipboard ASM int &H2F ASM mov temp&[00],ax IF temp& THEN ClearClipboard% = %TRUE END FUNCTION FUNCTION ASMSetClipB% (BYVAL pointr&, BYVAL segmnt&, BYVAL length%) ASM mov ax,&H1703 ;Set clipboard data ASM mov dx,7 ;Data format is text ASM xor si,si ASM mov cx,length% ASM mov bx,pointr& ASM mov es,segmnt& ASM int &H2f ASM mov temp&,ax If temp& then ASMSetClipB%=%TRUE END FUNCTION FUNCTION ASMGetClipB% (BYVAL pointr&, BYVAL segmnt&) ASM mov ax,&H1705 ;Get clipboard data ASM mov dx,7 ;Data format is text ASM mov bx,pointr& ASM mov es,segmnt& ASM int &H2f ASM mov temp&,ax If temp& then ASMGetClipB%=%TRUE END FUNCTION