*** PureBasic version 4.31 Windows XP v5.1 SP3 ***
ExecutablesList = ListIconGadget(#PB_Any, MainWindowLeftOffset, MainWindowTopOffset, MainWindowWidth-2*MainWindowLeftOffset, 225, "", MainWindowWidth-2*MainWindowLeftOffset)
SetGadgetAttribute(ExecutablesList, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
I am currently working on a program launcher of the portable variety. I am populating the above ListIconGadget with user defined executables. Each executable is identified with an icon. Is there an API call or some other method that can be made from within the program to extract the icon (32x32 preferably if exists) from the EXE file (or any other file), or the system default for that file type if the resource is absent from the EXE file. I will offer a manual icon selection for advanced users in the options. Can you offer a PureBasic coding example for this as I am relatively new to PureBasic and haven't written much code in general for quite a while. Thanks in advance.
How to extract icons from EXE, DLL, or any other source
-
- New User
- Posts: 7
- Joined: Wed Oct 21, 2009 11:31 pm
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: How to extract icons from EXE, DLL, or any other source
On Windows, the ExtractIconEx_() api is what you need. You can look it up on MSDN to see how to use it, but it's quite straightforward. You just dim two arrays, one for small icons and one for large and the function will put the icons it finds into the arrays for you. You can also use it to query the file for how many are in there.
Here's a sample:
When that large icon for PureBasic was first introduced I hated it. But then as time went by and I got used to seeing it more, I... naw, I still hate that thing. It always looks like it's just stolen something and is trying to run away.
Here's a sample:
Code: Select all
file$ = #PB_Compiler_Home+"purebasic.exe"
; Query the file
num_icons = ExtractIconEx_(file$, -1, #Null, #Null, #Null)
If num_icons > 0
; Allow room for the icons
Dim small(num_icons)
Dim large(num_icons)
; Retrieve the icons
ExtractIconEx_(file$, 0, large(), small(), num_icons)
; Look at the icons
OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
Repeat
ev=WaitWindowEvent()
Select ev
Case #PB_Event_Repaint
hdc = StartDrawing(WindowOutput(0))
DrawIconEx_(hdc, 10,20,small(0),0,0,0,0,#DI_NORMAL)
DrawIconEx_(hdc, 50,20,large(0),0,0,0,0,#DI_NORMAL)
StopDrawing()
EndSelect
Until ev=#PB_Event_CloseWindow
EndIf
; That's enough work for now, have a beer ;)
BERESHEIT
-
- New User
- Posts: 7
- Joined: Wed Oct 21, 2009 11:31 pm
Re: How to extract icons from EXE, DLL, or any other source
Thanks. Plugged in your code for testing purposes. Saw it in action and I understand how Ill use it. So in general any Windows API call can be used without a declaration or include?
Re: How to extract icons from EXE, DLL, or any other source
> any Windows API call can be used without a declaration or include?
Yep. One of the great features of PureBasic.
Yep. One of the great features of PureBasic.

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.