[REBOL] Wanna paste images to the Windows Clipboard?
From: greggirwin::mindspring::com at: 20-Sep-2002 16:57
Hi Gang,
Here's a first shot at getting binary data (i.e. an image) onto the Windows
Clipboard. If anyone wants to try it out and let me know if it works for
you, that would be great.
Requires View/Pro or Command (for library access).
Doesn't work on View 1.2.1. Looks like you can't use an image! as a routine
parameter under that version.
--Gregg
REBOL [
Title: "Windows Clipboard Library"
Author: "Gregg Irwin"
eMail: [greggirwin--acm--org]
]
win-clip: context [
win-user: load/library %user32.dll
win-gdi: load/library %gdi32.dll
create-bitmap: make routine! [
width [integer!]
height [integer!]
planes [integer!]
bits-per-pel [integer!]
lpv-bits [image!]
return: [integer!] ; HBMP on success, 0 on failure
] win-gdi "CreateBitmap"
CF_TEXT: 1
CF_BITMAP: 2
_open: make routine! [
hwnd-owner [integer!]
return: [integer!]
] win-user "OpenClipboard"
; Returns 0 on failure
open: does [
either 0 <> _open 0 [true][false]
]
close: make routine! [
return: [integer!]
] win-user "CloseClipboard"
; Returns 0 on failure
clear: make routine! [
return: [integer!]
] win-user "EmptyClipboard"
; Returns 0 on failure
get-data: make routine! [
format [integer!]
return: [integer!]
] win-user "GetClipboardData"
; Returns 0 on failure; hData on success
; After SetClipboardData is called, the system owns the object
; identified by the hMem parameter. The application can read
; the data, but must not free the handle or leave it locked.
set-data: make routine! [
format [integer!]
hMem [integer!]
return: [integer!]
] win-user "SetClipboardData"
; It looks like we either need to clear the clipboard, or write
; some text to it via the clipboard scheme, in order for image stuff
; to work. What happens is that the DIB rendering format doesn't
; update if we don't do that and that is what gets pasted into most,
; if not all, apps (even though the BITMAP format is in the clipboard
; with our data.
write: func [data] [
either not image? data [
system/words/write clipboard:// form data
][
if open [
clear
set-data CF_BITMAP create-bitmap data/size/x data/size/y 1
32 data
close
]
]
]
]
;win-clip/write "abc"
;win-clip/write to image! layout [button]
;halt