#define PICTYPE_ICON 3 #define IID_IDispatch Chr(0x00)+Chr(0x04)+Chr(0x02)+Chr(0x00)+ ; Replicate(Chr(0x00), 4)+Chr(0xC0)+Replicate(Chr(0x00), 6)+Chr(0x46) * Large icons Declare long ExtractIconEx in shell32 String @ File, long iconIndex, ; long @ iconLarge, long iconSmall, long nIcons * Small icons *Declare long ExtractIconEx in shell32 String @ File, long iconIndex, ; * long iconLarge, long @ iconSmall, long nIcons Declare Long OleCreatePictureIndirect In oleaut32 ; String @ PicDesc, String @ RefIID, Long fPictureOwnsHandle, Object @ IPic IconFile = "D:\Program Files\Microsoft Visual Studio\VFP98\VFP6.exe" IconIndex = 6 hIcon = 0 * Large icon ExtractIconEx(@IconFile, IconIndex, @hIcon, 0, 1) * SmallIcon *ExtractIconEx(@IconFile, IconIndex, 0, @hIcon, 1) * Create Picture object according to PICTDESC structure PictDesc = DWord(16) ; && Size of PICTDESC structure + DWord(PICTYPE_ICON) ; && Type of picture + DWord(hIcon) ; && HICON + DWord(0) && HPALETTE IPic = 0 iid = IID_IDispatch OleCreatePictureIndirect(@PictDesc, @iid, 1, @IPic) ImageList.ListImages.ADD(,"SomePict",IPic)In VFP6 it's more complex:
#define PICTYPE_ICON 3 #define IID_IDispatch Chr(0x00)+Chr(0x04)+Chr(0x02)+Chr(0x00)+ ; Replicate(Chr(0x00), 4)+Chr(0xC0)+Replicate(Chr(0x00), 6)+Chr(0x46) #define CP_ACP 0 && default to ANSI code page *-- Global Memory Flags #define GMEM_MOVEABLE 0x0002 #define GMEM_ZEROINIT 0x0040 #define GMEM_SHARE 0x2000 Declare long ExtractIconEx in shell32 String @ File, long iconIndex, ; long @ iconLarge, long iconSmall, long nIcons 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 * This function is not documented in MSDN, but present in Platform SDK .h file Declare Long OleSavePictureFile In oleaut32 Long IPic, Long bstrFile IconFile = "D:\Program Files\Microsoft Visual Studio\VFP98\VFP6.exe" IconIndex = 6 hIcon = 0 ExtractIconEx(@IconFile, IconIndex, @hIcon, 0, 1) * Create Picture object according to PICTDESC structure PictDesc = DWord(16) ; && Size of PICTDESC structure + DWord(PICTYPE_ICON) ; && Type of picture + DWord(hIcon) ; && HICON + DWord(0) && HPALETTE IPic = 0 iid = IID_IDispatch OleCreatePictureIndirect(@PictDesc, @iid, 1, @IPic) tcData = "tmp.ico" lnDataLen = 7 lhMem = GlobalAlloc(GMEM_MOVEABLE+GMEM_ZEROINIT+GMEM_SHARE, 2*(lnDataLen+1)) lnPtr = GlobalLock(lhMem) * Convert file name to wide char MultiByteToWideChar(CP_ACP, 0, @tcData, lnDataLen, lnPtr, lnDataLen+1) OleSavePictureFile(IPic, SysAllocString(lnPtr)) GlobalUnlock(lhMem) GlobalFree(lhMem) * Memory leak here - IPic not released * Will be fixed later ImageList.ListImages.ADD(,"SomePict",LoadPicture("tmp.ico"))This code is from my Clipboard class. I'm going to post it into download section when I'll have a time.