ThisForm.oleListView.Picture = ClipToPicture()The code is following (requires VFP7):
#define PICTYPE_BITMAP 1 #define CF_BITMAP 2 #define CF_PALETTE 9 #define OBJ_BITMAP 7 #define IID_IDispatch Chr(0x00)+Chr(0x04)+Chr(0x02)+Chr(0x00)+ ; Replicate(Chr(0x00), 4)+Chr(0xC0)+Replicate(Chr(0x00), 6)+Chr(0x46) #define VT_DISPATCH 9 #define CP_ACP 0 && default to ANSI code page *-- Global Memory Flags #define GMEM_MOVEABLE 0x0002 #define GMEM_ZEROINIT 0x0040 #define GMEM_SHARE 0x2000 Procedure ClipToPicture() * API declarations Declare Long OpenClipboard in user32 Long hWnd Declare Long CloseClipboard in user32 Declare Long GetClipboardData in user32 Long uFormat Declare Long GetObjectType in gdi32 Long h Declare Long OleCreatePictureIndirect In oleaut32 ; String @ PicDesc, String @ RefIID, Long fPictureOwnsHandle, Object @ IPic Local hBmp, hPal, PistDesc, IPic, iid, lnStrLen, var, lhMem, lnPtr hBmp = 0 hPal = 0 If OpenClipboard(0) != 0 hBmp = GetClipboardData(CF_BITMAP) hPal = GetClipboardData(CF_PALETTE) CloseClipboard() Else Error "Cannot open the clipboard" EndIf If hBmp = 0 Or GetObjectType(hBmp) <> OBJ_BITMAP Error "No bitmap data found on the clipboard" EndIf * Create Picture object according to PICTDESC structure PictDesc = DWord(16) ; && Size of PICTDESC structure + DWord(PICTYPE_BITMAP) ; && Type of picture + DWord(hBmp) ; && HBMP + DWord(hPal) && HPALETTE IPic = 0 iid = IID_IDispatch OleCreatePictureIndirect(@PictDesc, @iid, 0, @IPic) Return Ipic EndProc Function DWord(lnValue) * Creates a DWORD (unsigned 32-bit) string from a number Local byte(4) If lnValue < 0 lnValue = lnValue + 4294967296 EndIf byte(1) = lnValue % 256 byte(2) = BitRShift(lnValue, 8) % 256 byte(3) = BitRShift(lnValue, 16) % 256 byte(4) = BitRShift(lnValue, 24) % 256 Return Chr(byte(1))+Chr(byte(2))+Chr(byte(3))+Chr(byte(4)) EndFunc