Extract An Icon From Associated EXE

BlitzPlus Forums/BlitzPlus Programming/Extract An Icon From Associated EXE

SebHoll(Posted 2005) [#1]
Hi,
I'm making a program at the moment which I want to be able to put the icon associated with the file that's loaded onto a GUI screen. For extracting icons from EXEs and DLLs you can just use "ExtractIcon" in the Windows API, but say if you want to extract the icon given to *.DOC files etc. I found a Windows API function which does it "ExtractAssociatedIcon" and made some test code. But the program crashes as soon as you get to the ExtractAssociatedIcon line. Any ideas?

.lib "kernel32.dll"
GetModuleHandle%(lpModuleName%):"GetModuleHandleA""

.lib "user32.dll"
DestroyIcon%(hIcon$):"DestroyIcon"
DrawIcon%(hdc%,x%,y%,hIcon%):"DrawIcon"
GetDC%(hwnd%):"GetDC"

.lib "shell32.dll"
ExtractAssociatedIcon%(hInst%,FileName$,IconIndex%)



wnd = CreateWindow("Hello",10,10,200,200,0,5)
gadIconPanel = CreatePanel(0,0,32,32,wnd)
Global icnPanelDC	= GetDC(QueryObject(gadIconPanel,1))
Global icnModHandle	= GetModuleHandle(0)
Stop
Global icnImage		= ExtractAssociatedIcon(icnModHandle,"C:\word.doc",1)
DrawIcon(icnPanelDC,0,0,icnImage)

Repeat

If WaitEvent() = $803 Then End

Forever

End


Obviously, you need to make a word document called "C:\word.doc" or change the path. :P

Thanks in advance

Seb