Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Extract Associated Icon to a Treeview
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00668799
Message ID:
00669471
Vues:
54
That seem to get me somewhere. I think that gives me enough to get started.
One final question I must ask: "How do you post such formated code into the thread?"

Thanks for all your help.

Troy

>Here's the correct declaration for ExtractAssociatedIcon
DECLARE INTEGER ExtractAssociatedIcon IN Shell32'
>  INTEGER hInst, STRING @lpIconPath,;
>  INTEGER @lpiIcon
>* Get VFP's instance handle
>DECLARE INTEGER GetClassLong IN Win32API;
>  INTEGER hWnd, INTEGER nItem
>lninstance = GetClassLong(_VFP.hWnd, -16)
>* lcfile is the file of interest
>* it should exist
>lnIndex = 0
>lnhIcon = ExtractAssociatedIcon(lninstance, @lcfile, @lnIndex)
>
>>Still getting nowhere. I have been replacing my C5 code with these attempts. My latest version is pretty much the code posted here. I have tried to change the IconIndex to a reference pass, but that did nothing. I have been passing as a test an htm,xls, and doc files. hIcon reamains 0 and iPic is NULL. Dword calls the function you posted earlier.
>>
>>Code:
>>
>>#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)
>>LPARAMETERS IconFile,oImageList
>>*Add the associated file icon to the ImageList
>>IF FILE(IconFile)
>> Declare long ExtractAssociatedIcon 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
>> LOCAL IconIndex,hIcon,PictDesc,IPic,IID
>> IconIndex=0
>> hIcon = 0
>> ExtractAssociatedIcon(@IconFile, IconIndex, @hIcon, 0, 1)
>> 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)
>> IF !ISNULL(IPic)
>> oImageList.ListImages.ADD(,[img_]+JUSTEXT(IconFile),IPic)
>> ENDIF
>>ENDIF
>>
>>
>>>>I have been passing 0 as the IconIndex. Perhaps I am trying to accomplish the wrong task: I am not trying to extract an icon from an EXE file, but I want to display the icon of the application associated with a file extension. For Example, a file with a '.doc' extension will display the MS Word icon. Am I using the wrong API? If so, which one does Windows Explorer use?
>>>>
>>>>Thanks for your patience and rapid response.
>>>>
>>>Troy,
>>>
>>>No problem. Substitute ExtractAssociatedIcon(). As I mentioned earlier it sounds like you weren't passing the icon index parameter properly (by value rather than reference). All you need is a valid icon handle. If you like post the code that was causing the C5.
>>>
>>>One note, however, the icon displayed in the Explorer, is determined sometimes by the index in the registry. For example, VFP has 12 icons embedded in its exectuable. That's how the Explorer knows to display which icon for the various types of VFP files.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform