>* Usage: SaveClipImage("clipfile.bmp") > >#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 SaveClipImage(tcFileName) > If Vartype(tcFileName) != 'C' > Error 11 > EndIf > tcFileName = DefaultExt(tcFileName, "bmp") > > * 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, Long @ IPic > Declare Long GlobalAlloc In kernel32 Long wFlags, Long dwBytes > Declare Long GlobalFree In kernel32 Long hMem > Declare Long GlobalLock In kernel32 Long hMem > Declare Long GlobalUnlock In kernel32 Long hMem > Declare Long MultiByteToWideChar In kernel32 ; > Long iCodePage, Long dwFlags, String @ lpStr, Long iMultiByte, ; > Long lpWideStr, Long iWideChar > Declare Long SysAllocString In oleaut32 Long szString > Declare Long VariantClear in oleaut32 String @ pvarg > > * This function is not documented in MSDN, but present in Platform SDK .h file > Declare Long OleSavePictureFile In oleaut32 Long IPic, Long bstrFile > > 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) > > lnStrLen = Len(tcFileName) > lhMem = GlobalAlloc(GMEM_MOVEABLE+GMEM_ZEROINIT+GMEM_SHARE, 2*(lnStrLen+1)) > lnPtr = GlobalLock(lhMem) > MultiByteToWideChar(CP_ACP, 0, @tcFileName, lnStrLen, lnPtr, lnStrLen+1) > OleSavePictureFile(IPic, SysAllocString(lnPtr)) > > * IPic.Release() > var = Chr(VT_DISPATCH) + Replicate(Chr(0), 7) + DWord(IPic) > VariantClear(@var) > > GlobalUnlock(lhMem) > GlobalFree(lhMem) >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 >>I have also a code for storing clipboard content in JPG, GIF and other formats, but this code is based on another approach and I'm going to publish it later.