Try this... The code below copies a buffer to the clipboard.
ExampleCopyBuffer buffer,width,height
> Run the code below (after creating the userlibs file). > Press a key to randomize canvas > Choose Menu>Edit>Copy > Open MSPAINT etc and paste!
NOTE: I have only implemented 'Image Copy' so far.
UserLibs needed ===============
.lib "user32.dll"
OpenClipboard%(hwnd%):"OpenClipboard"
CloseClipboard%():"CloseClipboard"
EmptyClipboard%():"EmptyClipboard"
SetClipboardImage%(format%,img%):"SetClipboardData"
CBLoadImage%(Inst%,filename$,ImageType%,DesiredWidth%,DesiredHeight%,Flags%):"LoadImageA"
; Clipboard Image COPY/PASTE
; ===========================
; Syntax Error
; userlibs required
; *********************************************
; .lib "user32.dll"
; OpenClipboard%(hwnd%):"OpenClipboard"
; CloseClipboard%():"CloseClipboard"
; EmptyClipboard%():"EmptyClipboard"
; SetClipboardImage%(format%,img%):"SetClipboardData"
; CBLoadImage%(Inst%,filename$,ImageType%,DesiredWidth%,DesiredHeight%,Flags%):"LoadImageA"
;
; *********************************************
Const w=400,h=300 ; image width & height
Const title$="Clipboard Image Copy/Paste"
AppTitle title$
win=CreateWindow(title$,50,50,w+8,h+24,Desktop(),8+4+1)
Global can=CreateCanvas(0,0,w,h,win)
menu=WindowMenu(win)
editmenu=CreateMenu("Edit",0,menu)
copy=CreateMenu("Copy (to clipboard)",1,editmenu)
paste=CreateMenu("Paste (from clipboard)",2,editmenu)
SetStatusText win,"press a key to draw new ovals"
UpdateWindowMenu win
SeedRnd MilliSecs()
DrawOvals
Repeat
ev=WaitEvent()
If ev=$103
If EventData()=27 Exit
DrawOvals()
EndIf
If ev=$1001 ; menu
If EventData()=1 ; copy
CopyBuffer CanvasBuffer(can),w,h
Notify "Copied to clipboard!"
EndIf
If EventData()=2 ; paste
Notify "Not implemented yet :-<"
EndIf
EndIf
Until ev=$803
End
;-----------------------------------
Function CopyBuffer(buff,w%,h%)
Local LR_LOADFROMFILE=$10
Local cf_BITMAP=2
Local filename$=SystemProperty$("tempdir")+"tmp.bmp"
SaveBuffer buff,filename$
img=CBLoadImage(0,filename$, 0, w,h, LR_LOADFROMFILE)
OpenClipboard 0 : EmptyClipboard
SetClipboardImage cf_BITMAP,img
CloseClipboard
DeleteFile filename$
End Function
;-----------------------------------
Function DrawOvals()
SetBuffer CanvasBuffer(can)
Cls
For r=1 To 50
Color Rand(255),Rand(255),Rand(255)
Oval Rand(0,w),Rand(0,h),Rand(5,50),Rand(5,50)
Next
FlipCanvas can
End Function
|