I want to copy bitmaps that are saved in the clipboard from i.e. Paint and such.
My code so far is as follows:
ulong l_handle, l_datasize, l_lock
long l_file
uint i_format
blob lb_blob
n_bitmap ln_bit
l_handle = handle(parent)
OpenClipboard(l_handle)
//2 = Bitmap
//8 = Bitmapinfo
if not IsClipboardFormatAvailable(8) then
closeclipboard()
return
end if
l_handle = GetclipboardData( 8)
l_lock = GlobalLock(l_handle)
if not isnull(l_lock) then
l_datasize = GlobalSize(l_lock)
if l_datasize>0 then
lb_blob = blob(space(l_datasize), EncodingAnsi!)
ReadClipboardData(lb_blob, l_lock, l_datasize)
GlobalUnlock(l_handle)
closeClipboard()
if not isnull(lb_blob) then
//l_file = fileopen("c:\temp\test.dib", StreamMode!, Write!, LockReadWrite!, Replace!)
ln_bit.of_writeblob( "c:\temp\test.bmp", lb_blob)
ln_bit.of_writeblob( "c:\temp\test1.bmp", BlobMid(lb_blob, 15) )
ln_bit.of_writeblob( "c:\temp\test2.bmp", BlobMid(lb_blob, 169))
ln_bit.of_writeblob( "c:\temp\test3.bmp", BlobMid(lb_blob, 14))
ln_bit.of_writeblob( "c:\temp\test4.bmp", BlobMid(lb_blob, 168))
//FileWriteEx(l_file, lb_blob)
//fileclose(l_file)
//p_1.setpicture(lb_blob)
end if
end if
GlobalUnlock(l_handle)
end if
closeClipboard()
External functions
Function Ulong GetClipboardData ( &
uint uFormat&
) Library "user32.dll"
Function boolean OpenClipboard ( &
long hWndNewOwner &
) Library "user32.dll"
Function boolean CloseClipboard ( &
) Library "user32.dll"
Function ulong GlobalLock(&
ulong hMem&
) Library "kernel32.dll"
Function boolean GlobalUnlock( ulong hMem) Library "kernel32.dll"
SUBROUTINE ReadClipboardData(ref blob Destination, ulong Source, ulong&
Length) Library "KERNEL32.DLL" Alias for "RtlMoveMemory"
FUNCTION ulong GlobalSize(ulong hMem) Library "kernel32.dll"
FUNCTION boolean IsClipboardFormatAvailable(ulong format) Library "user32.dll"
for GetclipboardData( ) I use the value 8 (Bitmapinfo), since 2 (Bitmap) always returns zero when calling the GlobalLock function.
So right now I am getting the Bitmapinfo in a Blob but am unable to save it. It always says the image is damaged. The reason I tried all this BlobMid stuff in the of_writeblob function was because I wanted to extract the bitmap out of the bitmapinfo (if that is even possible).
Here "http://www.topwizprogramming.com/freecode_bitmap.html" they are creating a bitmapinfo and the blobheader has a length of 14, so I thought that it might work that way, but the file is still damaged. I guess the info does only contain information and not the actual bitmap.
Did anybody ever solve this, or is there a dll I can simply use?
Edit: in the topwiz sample they are creating a full bitmap with the header, the info and the actual bitmap, so my attempt could only fail I guess. So the mainproblem is, why is the Globallock function returning zero when call getclipboarddata with the parameter 2