|
-
Dec 15th, 2001, 08:51 AM
#1
Loading icons from exe files
The other dya i was programming a really good tool to decrease the resources taken to load the desktop but suddenly if found out that i need to load the icons of some programs into my program in run-time ( as my graphics chief wanted ), of course i don't know how, so i programmed my tool so that it runs an icon program, opens the exe file, copies the icon, pastes it into a new file and saves as .ICO , but you know, it is not practical, so i was wondering isn't there any way to do that ( load the icons of exe files in runtime) ?
Thanks
-
Dec 17th, 2001, 03:58 AM
#2
Fanatic Member
Load the EXE into memory using LoadLibrary, use LoadIcon on the returned handle to get the 'MAINICON' resource, use DrawIcon or DrawIconEx if you want to draw it on a picturebox, or use any other API that takes a HICON parameter. You could put it into an imagelist using ImageList_AddIcon:
Remarks
Because the system does not save hicon, you can destroy it after the macro returns if the icon or cursor was created by the CreateIcon function. You do not need to destroy hicon if it was loaded by the LoadIcon function; the system automatically frees an icon resource when it is no longer needed.
You can than unload the EXE from memory using FreeLibrary...
Hope that helped
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Dec 18th, 2001, 12:15 PM
#3
Thanks for your reply,
it's good but it seems that you think i'm an expert in API, well i'm not but i know that i'll use your API function in some way ( maybe after a few hours of trying) but thanks anyway
-
Dec 18th, 2001, 12:23 PM
#4
Fanatic Member
Well, it's not that I assumed you are an expert, it's just that now you know what to look for
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Dec 18th, 2001, 12:29 PM
#5
yes you're right
but i have a question for you
are you an expert ?
-
Dec 18th, 2001, 12:44 PM
#6
Fanatic Member
I wouldn't call myself an expert, but yes, I know how those functions work 
Mhhh... after some investigation, I came to the conclusion that my method sucks. There is no MAINICON resource in for example Notepad.exe, so you'd have to get the first icon in the resources, but I don't know how. Alternative solution: SHGetFileInfo. It returns file information, and in this case also the icon associated with a file, any file...
Don't have VB to test it, but this might get you started (you'd have to get the API declarations from the API viewer though):
VB Code:
Dim pInfo As SHFILEINFO
'// Get the file information
SHGetFileInfo("C:\Winnt\Notepad.exe", 0, pInfo, Len(pInfo), SHGFI_ICON, SHGFI_LARGEICON)
'// In this example: draw the icon onto a picturebox
Picture1.AutoRedraw = True
Picture1.Cls
DrawIcon(Picture1.hDC, 0, 0, pInfo.hIcon)
Picture1.Refresh
That should work
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Dec 18th, 2001, 12:53 PM
#7
well, that seems to be a good one.
and if you want to prove that you're really good reply my new thread in VB Q and A > Visual Basic > Games and graphics programming > ?:Getting colors code
i hope that i'll see a reply from you there soon
see you, HaaHaa!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|