How to get directory icon & Byte Size?
How to get directory icon & Byte Size?
I'm stumped, I could get the icon of a file farely easy but how do you get hold of an directory icon, under xp you can modify your folders so that they can each have a diferent icon for each folder, anyone know how to obtain this icon please ?
Last edited by Inner on Sat Jun 07, 2003 10:21 pm, edited 1 time in total.
Here it comes...
The SHGetFileInfo_() command is also usefull for other things, for example
getting a the file description text Explorer displays.
See all the possible flags of this command here for more info...http://msdn.microsoft.com/library/defau ... leinfo.asp
Timo
Code: Select all
; SHFILEINFO structure is incorrect in PB, got to go fix that...
Structure MySHFILEINFO
hIcon.l
iIcon.l
dwAttributes.l
szDisplayName.b[#MAX_PATH]
szTypeName.b[80]
EndStructure
; The String can be any file on your disk, or a directory name. You will receive
; the same Icon, the M$ Explorer displays for this folder/file.
If SHGetFileInfo_("C:\RECYCLED\", 0, @Info.MySHFILEINFO, SizeOf(MySHFILEINFO), #SHGFI_ICON|#SHGFI_LARGEICON)
IconHandle = Info\hIcon
; display the icon
If OpenWindow(0,0,0,100,100,#PB_Window_Screencentered|#PB_Window_SystemMenu, "Icon")
If CreateGadgetList(WindowID())
ImageGadget(0, 10, 10, 32, 32, IconHandle)
Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
EndIf
EndIf
; Free the Icon handle:
; When your app ends, windows will free all icon handles, so you don't
; necessary need to do it. However, if you load a lot of these icons, it
; might be a good deal to free all those you don't need anymore, to keep
; the system recources free.
DestroyIcon_(IconHandle)
Else
MessageRequester("Error!","Could not get File/Folder Info",0)
EndIf
End
getting a the file description text Explorer displays.
See all the possible flags of this command here for more info...http://msdn.microsoft.com/library/defau ... leinfo.asp
Timo
quidquid Latine dictum sit altum videtur
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
I've adapted the code above for use in a project. My goal is to save the icon as a bitmap file.
Unfortunately, SaveImage doesn't work like this:
SaveImage(IconHandle,bmpfile$)
because IconHandle is a handle, not an image number.
The workaround is pretty clumsy. It involves taking a snapshot of the window (using an ImageGadget etc.) and saving that with SaveImage. This means the window is temporarily visible - just for a split second but it's not the best.
So basically what I'm asking is: is there a way to get the image number from the image handle? Or "how to adapt IconHandle for use with SaveImage"??
Thanks in advance!
Seymour.
Unfortunately, SaveImage doesn't work like this:
SaveImage(IconHandle,bmpfile$)
because IconHandle is a handle, not an image number.
The workaround is pretty clumsy. It involves taking a snapshot of the window (using an ImageGadget etc.) and saving that with SaveImage. This means the window is temporarily visible - just for a split second but it's not the best.
So basically what I'm asking is: is there a way to get the image number from the image handle? Or "how to adapt IconHandle for use with SaveImage"??
Thanks in advance!
Seymour.
Here's one way; just draw the icon onto a PB image :
Code: Select all
;Convert icon to bitmap. (You will lose the transparency with this method.)
;Returns a PB Image# of the image containing a copy of the icon.
;Returns zero if an error.
Procedure.l ConvertIconToBitmap(hIcon)
Protected iconinfo.ICONINFO, bmap.BITMAP, image, hdc
;Check icon.
If GetIconInfo_(hIcon, iconinfo)
If GetObject_(iconinfo\hbmMask, SizeOf(BITMAP), bmap)
image = CreateImage(#PB_Any, bmap\bmWidth, bmap\bmHeight, 32)
If image
;Draw a copy of the icon onto the bitmap.
If StartDrawing(ImageOutput(image))
Box(0,0,bmap\bmWidth, bmap\bmHeight,#White)
DrawImage(hIcon, 0, 0)
StopDrawing()
Else
FreeImage(image)
image=0
EndIf
EndIf
EndIf
EndIf
ProcedureReturn image
EndProcedure
;/////////////////////////////////////////////////////////////
;Test.
LoadImage(1, "open.ico") ;Replace with your own icon.
image = ConvertIconToBitmap(ImageID(1))
;Let us now save the bitmap.
SaveImage(image, "test.bmp")
;Tidy up.
FreeImage(image)
End
I may look like a mule, but I'm not a complete ass.
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: How to get directory icon & Byte Size?
And mine is to save the Icon to a .ICO file....My goal is to save the icon as a bitmap file.
Me to i have try SaveImage(GetDlgCtrlID_(IconHandle), IconFile$, #PB_ImagePlugin_PNG) but obviously.... that not works because PNG is transparent yes, but ICO is not PNG format, i believe ...


Not a destination
Re: How to get directory icon & Byte Size?
Salut KCK
may be it's what you're looking for (a good code from SROD)
http://www.purebasic.fr/english/viewtop ... 12&t=23387
may be it's what you're looking for (a good code from SROD)
http://www.purebasic.fr/english/viewtop ... 12&t=23387
A+
Denis
Denis
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: How to get directory icon & Byte Size?
Hello DENIS
Yeeeeesss !!!!!
It's exactely what i want !!!
I don't understand..i have search and found several code except this

Thanks a lot my friend
Ps:
My pseudo is KCC
My Nickname (Surnom) is "ToutKC" or also "CKC" (In french)
But KCK, never i have see that !!!!

The first time perhaps a kind member call me "KparK"

http://www.kpark.fr/
Again thanks and the pleasure to read you another time

Yeeeeesss !!!!!
It's exactely what i want !!!

I don't understand..i have search and found several code except this


Thanks a lot my friend


Ps:
My pseudo is KCC
My Nickname (Surnom) is "ToutKC" or also "CKC" (In french)

But KCK, never i have see that !!!!




The first time perhaps a kind member call me "KparK"




http://www.kpark.fr/
Again thanks and the pleasure to read you another time


Not a destination
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: How to get directory icon & Byte Size?
I have try the splendid code of SROD, and that works very well
I have forgotten
to thanks also the great SROD for this good and splendid code 
I have take a look to this jewel....and i'm surprising
to have understand something inside it, and can make the same easily now
It's already a beginning no ????
(Say yes ..pleaaaase !!!)
Again thanks at FREAK, SROD and you DENIS

I have forgotten


I have take a look to this jewel....and i'm surprising


Code: Select all
Else
result= 0
EndIf

Again thanks at FREAK, SROD and you DENIS


Not a destination