$CPU 8086 ' make compatible with XT systems $LIB ALL OFF ' turn off all PowerBASIC libraries $ERROR ALL OFF ' turn off all PowerBASIC error checking $OPTIMIZE SIZE ' optimize for smaller code $COMPILE UNIT ' compile to a UNIT (.PBU) '$COMPILE EXE ' compile to a UNIT (.PBU) DEFINT A-Z ' Required for all numeric functions, forces PB to not ' include floating point in UNIT (makes it smaller) '/*------------------------------------------------------------------*/ $CODE SEG "MLIB2" '/*------------------------------------------------------------------*/ ' AWCLIP MSG$,OPT,RCODE ' Access Windows CLIPboard. ' Puts or Gets windows (3.1,3.11,95,98) clipboard contents and places ' in MSG$, a binary string. ' OPT = 1 = Put MSG$ into clipboard ' 2 = Get clipboard into MSG$ ' RCODE = 99 - Windows not running ' 98 - Unable to open clipboard ' 97 - Unable to put MSG$ into clipboard ' 0 - Operation successful ' EXAMPLE: AWCLIP MSG$,1,RCODE ' ' $INCLUDE "C:\CODE\MLIB\MLIB.INC" ' MSG$ = "a test to see if this will work." ' OPT% = 1 ' RCODE% = 0 ' AWCLIP MSG$,OPT%,RCODE% ' PRINT MSG$ ' INPUT Z ' '/*------------------------------------------------------------------*/ SUB AWCLIP(MSG$,OPT%,RCODE%) PUBLIC ASM PUSH AX ASM PUSH CX ASM PUSH DX ASM PUSH ES ASM PUSH DI RCODE% = 0 %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 '/* '/*IF LEN(ENVIRON$("windir")) = 0 THEN '/* PRINT "Windows is not loaded!" '/* END '/*END IF IF LEN(ENVIRON$("windir")) = 0 THEN RCODE% = 99 GOTO EEXITAWCLIP END IF '/* '/*IF NOT OpenClipboard% THEN '/* PRINT "Unable to open the Windows Clipboard." '/* END '/*END IF IF NOT OpenClipboard% THEN RCODE% = 98 GOTO EEXITAWCLIP END IF '/* '/*Msg$ = "No really, this is being passed through the Clipboard." '/*Msg2$ = "Second Line here." '/*IF NOT SetClipboardData%(Msg$) THEN '/* PRINT "Unable to send a message to the Clipboard." '/*END IF IF OPT% = 1 THEN IF NOT SetClipboardData%(Msg$) THEN RCODE% = 97 ELSE RCODE% = 0 END IF END IF IF OPT% = 2 THEN MSG$ = GetClipboardData$ 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 EEXITAWCLIP: ASM POP DI ASM POP ES ASM POP DX ASM POP CX ASM POP AX END SUB 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. 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 '/*------------------------------------------------------------------- ' $INCLUDE "C:\CODE\MLIB\MLIB.INC" ' MSG$ = "a THIRD test to see if this will work." ' OPT% = 1 ' RCODE% = 0 ' AWCLIP MSG$,OPT%,RCODE% ' PRINT MSG$ ' INPUT Z '/*-------------------------------------------------------------------