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:
00669373
Vues:
20
I am still trying to get the basics working. Even using the posted code, I am getting nowhere. At least this is not generating the C00000005 errors.
What am I missing? I am passing the file path, the icon index, and a reference to the imagelist.

Function SetImageListIconFile
LPARAMETERS IconFile,IconIndex,oImageList
IF VARTYPE(IconIndex)#[N]
IconIndex=6
ENDIF
#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

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)

oImageList.ListImages.ADD(,[img_]+JUSTEXT(IconFile),IPic)
endfunc

FUNCTION DWord

LPARAMETERS pnInteger, pnbytes

LOCAL lcresult, lnbytes, lnmask,;
lninteger, lni, lnchar
lcresult = ""
IF PCOUNT() = 2
lnbytes = pnbytes
ELSE
* Default to DWORD
lnbytes = 4
ENDIF
lninteger = pnInteger
lnmask = 255
FOR lni = 1 TO lnbytes
lnchar = BITAND(lninteger, lnmask)
lcresult = lcresult + CHR(lnchar)
lninteger = BITRSHIFT(lninteger, 8)
NEXT
RETURN lcresult
ENDFUNC


>>It looks like the code in message 656045 will accomplish what I am trying to do. However, it does not have the code behind the DWord function. What does that function do (so I can recreate that behavior)?
>>
>Troy,
>
>In playing around with the code, I assumed (and aparently correctly) that the function returns a string representing a four byte integer to create a structure. I used my own routine for this, which is as follows:
FUNCTION IntegerToString
>
>  LPARAMETERS pnInteger, pnbytes
>
>  LOCAL lcresult, lnbytes, lnmask,;
>    lninteger, lni, lnchar
>  lcresult = ""
>  IF PCOUNT() = 2
>    lnbytes = pnbytes
>  ELSE
>    * Default to DWORD
>    lnbytes = 4
>  ENDIF
>  lninteger = pnInteger
>  lnmask = 255
>  FOR lni = 1 TO lnbytes
>    lnchar = BITAND(lninteger, lnmask)
>    lcresult = lcresult + CHR(lnchar)
>    lninteger = BITRSHIFT(lninteger, 8)
>  NEXT
>  RETURN lcresult
>ENDFUNC
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform