Thread View: borland.public.cppbuilder.nativeapi
16 messages
16 total messages
Started by Mike Collins
Mon, 30 Jun 2008 23:51
Loading x48 icons with ExtractIconEx...
Author: Mike Collins
Date: Mon, 30 Jun 2008 23:51
Date: Mon, 30 Jun 2008 23:51
27 lines
1804 bytes
1804 bytes
Hay all,
Got a little issue / problem. I have an event log that stores a list of
applications and programs that have been run. I'm using a GUI design that
displays a x48 icon that corrisponds to the application. Currently i'm
using ExtractIconEx() becuase this seems like the only to get the default
icon used for an applicaiton, i.e.
HICON hIconLarge[1];
ExtractIconEx(szAppPath.c_str(), 0, hIconLarge, NULL, 1);
if (hIconLarge[0])
{
// Use the icon in the GUI
::DestroyIcon(hIconLarge[1]);
}
- however, i only get the x32 icon. I can't workout retrieve the x48 icon.
I assum that i could extend the icon array and retrieve more large icons but
there doesn't seem to be anyway to determine exactly which icon size you are
getting.
Based on this, how does Explorer.exe load the correct, default, large icon
when you change the view to Titles.
Hope this makes sense.
Mike C
Re: Loading x48 icons with ExtractIconEx...
Author: Remy Lebeau (TeamB)
Date: Mon, 30 Jun 2008 23:18
Date: Mon, 30 Jun 2008 23:18
16 lines
1373 bytes
1373 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote in message news:486960ab@newsgroups.borland.com... > - however, i only get the x32 icon. As you should be. 32x32 is the "large" icon size. 48x48 is "extra-large", which most functions do not recognize. > I can't workout retrieve the x48 icon. ExtractIconEx() does not support 48x48. Use SHGetImageList() to get an IImageList/HIMAGELIST that you can then extract 48x48 icons from. Gambit
Re: Loading x48 icons with ExtractIconEx...
Author: Bob Gonder
Date: Tue, 01 Jul 2008 02:51
Date: Tue, 01 Jul 2008 02:51
13 lines
1336 bytes
1336 bytes
Mike Collins wrote: >displays a x48 icon that corrisponds to the application. Currently i'm >using ExtractIconEx() becuase this seems like the only to get the default >icon used for an applicaiton, i.e. > however, i only get the x32 icon. Does ExtractAssociatedIcon work for you? Also you might look at SHGetFileInfo. I seem to remember that LoadImage was the one to use. Fairly good info here: Icons in Win32 http://msdn.microsoft.com/en-us/library/ms997538.aspx
Re: Loading x48 icons with ExtractIconEx...
Author: Mike Collins
Date: Tue, 01 Jul 2008 12:07
Date: Tue, 01 Jul 2008 12:07
43 lines
2677 bytes
2677 bytes
Hay Bob, thanks for the pointers and links. I had actually looked at these two API's, along with a a whole list of others. However, the problem (as i see it) is this: 1) I want to extract and display the default icon that is displayed for an executable program. In BCB this would be "MAINICON" and in most other applications I think it is the icon with the ID 101 (but i'm not sure here). I don't want to get the shells associated icon which is displayed if not icon is embedded for a program. Therefore, both SHGetFileInfo and ExtractAssociatedIcon will not work, becuase both look at the association between the .exe extension and the shell icons. 2) The problem with using LoadImage is that i need to provide it with lpszName value to identify the icon that i want to return. So the question is, what value do i provide? Is the default icon always 101? In BCB / Delphi applications it is "MAINICON". So based on the fact that i have a list of random applications, how do i determine the idetifier of the default icon? Any ideas? Many thanks Mike "Bob Gonder" <none@nowhere.invalid> wrote in message news:d73j6491uh8j0ess67ai2ht5jdkj5remsf@4ax.com... > Mike Collins wrote: > >>displays a x48 icon that corrisponds to the application. Currently i'm >>using ExtractIconEx() becuase this seems like the only to get the default >>icon used for an applicaiton, i.e. >> however, i only get the x32 icon. > > Does ExtractAssociatedIcon work for you? > Also you might look at SHGetFileInfo. > I seem to remember that LoadImage was the one to use. > Fairly good info here: > Icons in Win32 > http://msdn.microsoft.com/en-us/library/ms997538.aspx > >
Re: Loading x48 icons with ExtractIconEx...
Author: Bob Gonder
Date: Tue, 01 Jul 2008 15:14
Date: Tue, 01 Jul 2008 15:14
23 lines
1946 bytes
1946 bytes
Mike Collins wrote: >1) I want to extract and display the default icon that is displayed for an >executable program. In BCB this would be "MAINICON" and in most other >applications I think it is the icon with the ID 101 (but i'm not sure here). No, the name and number have no (external) meaning. The standard icon is the first icon, as the link mentioned. >I don't want to get the shells associated icon which is displayed if not >icon is embedded for a program. Therefore, both SHGetFileInfo and >ExtractAssociatedIcon will not work, becuase both look at the association >between the .exe extension and the shell icons. So you would rather have No icon for a non-icon exe or data file? >2) The problem with using LoadImage is that i need to provide it with Rats. Do you have a (publicly available) 48x48 icon-containing-exe I can play with? I suppose I could write one. I'll be at the Dr's all day, so it'll be Wed before I can mess with it.
Re: Loading x48 icons with ExtractIconEx...
Author: Mike Collins
Date: Tue, 01 Jul 2008 16:55
Date: Tue, 01 Jul 2008 16:55
40 lines
2543 bytes
2543 bytes
Cheers for the offer... As you've said, the default icon is basically determined by the first icon that the OS comes across - i really need to mimic this... As for your second point, I'll only ever have programs in my listing so there will never be a need to display any file associations. I'll stick a demo app on the .attachments group if you want to have a look. Best regards, Mike "Bob Gonder" <none@nowhere.invalid> wrote in message news:bdgk64p9sfo43qu90s1plgmf08v9h4m6rp@4ax.com... > Mike Collins wrote: > >>1) I want to extract and display the default icon that is displayed for an >>executable program. In BCB this would be "MAINICON" and in most other >>applications I think it is the icon with the ID 101 (but i'm not sure >>here). > > No, the name and number have no (external) meaning. > The standard icon is the first icon, as the link mentioned. > >>I don't want to get the shells associated icon which is displayed if not >>icon is embedded for a program. Therefore, both SHGetFileInfo and >>ExtractAssociatedIcon will not work, becuase both look at the association >>between the .exe extension and the shell icons. > > So you would rather have No icon for a non-icon exe or data file? > >>2) The problem with using LoadImage is that i need to provide it with > > Rats. > Do you have a (publicly available) 48x48 icon-containing-exe > I can play with? I suppose I could write one. I'll be at the > Dr's all day, so it'll be Wed before I can mess with it. > >
Re: Loading x48 icons with ExtractIconEx...
Author: Mike Collins
Date: Wed, 02 Jul 2008 15:51
Date: Wed, 02 Jul 2008 15:51
8 lines
1105 bytes
1105 bytes
Cheers, just been playing around with SHGetImageList(). Can you give me any pointers on accessing or converting the returned HIMAGELIST? (Hate shell programming :-( ) Mike
Re: Loading x48 icons with ExtractIconEx...
Author: Mike Collins
Date: Wed, 02 Jul 2008 15:59
Date: Wed, 02 Jul 2008 15:59
8 lines
1291 bytes
1291 bytes
Actually, I'll take it one step closer - how to you direct SHGetImageList() to a particular execuatble? From what i can see, it only returns the System / shell icons - i don't see a way of retrieving default icons for a given executable. :-( ????? Mike
Re: Loading x48 icons with ExtractIconEx...
Author: Remy Lebeau (TeamB)
Date: Wed, 02 Jul 2008 16:47
Date: Wed, 02 Jul 2008 16:47
23 lines
1694 bytes
1694 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote in message news:486b952d@newsgroups.borland.com... > Actually, I'll take it one step closer - how to you direct > SHGetImageList() to a particular execuatble? You don't. > From what i can see, it only returns the System / shell icons Yes, it does. > i don't see a way of retrieving default icons for a given executable. Try LoadImage() instead. It requires an HINSTANCE instead of a filename, though. You can use LoadLibraryEx() with the LOAD_LIBRARY_AS_DATAFILE and/or LOAD_LIBRARY_AS_IMAGE_RESOURCE flag to load the .exe file into memory without actually executing it, and then pass the returned HMODULE to LoadImage(). Gambit
Re: Loading x48 icons with ExtractIconEx...
Author: Bob Gonder
Date: Wed, 02 Jul 2008 20:38
Date: Wed, 02 Jul 2008 20:38
47 lines
2593 bytes
2593 bytes
Mike Collins wrote:
>I'll stick a demo app on the .attachments group if you want to have a look.
Ok, in a nutshell, here it is (from the "Icons in Win32" link).
Filter your results on e->bWidth or height.
{
String Filename = FileListBox->FileName; // full path
HMODULE hLib = LoadLibraryEx( Filename.c_str(), NULL, LOAD_LIBRARY_AS_DATAFILE );
EnumResourceNames( hLib, RT_GROUP_ICON,
(ENUMRESNAMEPROC)EnumNamesFunc, 0 );
FreeLibrary( hLib );
}
BOOL EnumNamesFunc(
HANDLE hModule, // module handle
LPCTSTR lpType, // address of resource type
LPTSTR lpName, // address of resource name
LONG lParam) // extra parameter
{
HRSRC hRsrc = FindResource( hModule, lpName, lpType );
HGLOBAL hGroup = LoadResource( hModule, hRsrc );
GRPICONDIR * lpGrpIconDir = (LPGRPICONDIR)LockResource( hGroup );
for( int i=0; i < lpGrpIconDir->idCount; ++i )
{
int x = (i%7)*64;
int y = (i/8)*64;
GRPICONDIRENTRY * e = &lpGrpIconDir->idEntries[i];
hRsrc = FindResource( hModule, MAKEINTRESOURCE( e->nID ), RT_ICON );
HGLOBAL hGlobal = LoadResource( hModule, hRsrc );
ICONIMAGE *lpIconImage = (LPICONIMAGE)LockResource( hGlobal );
HICON hicon = CreateIconFromResourceEx(
(PBYTE)lpIconImage,
e->dwBytesInRes,
TRUE,
0x00030000,//DWORD dwVersion,
e->bWidth,
e->bHeight,
0 );
TIcon *icon = new TIcon;
icon->Handle = hicon;
Form2->Image1->Canvas->Draw( x, y, icon );
};
return TRUE;
}
Re: Loading x48 icons with ExtractIconEx...
Author: Mike Collins
Date: Wed, 02 Jul 2008 22:23
Date: Wed, 02 Jul 2008 22:23
19 lines
1728 bytes
1728 bytes
I get all this - i think maybe i'm not expaining myself very well. I know how to use LoadLibrary / LoadImage to access a give x48 icon. However, I don't know the Icon ID. This is the situation - I have an event log that holds a list of applications that have be logged. I want to display the default icon for the individual application - NOT the shells default application. I want to show the icon that the programs author has assigned as the displayed icon. I can't work out how to do this becuase i don't know the icon ID. Using ExtractIconEx will give me the default icon but only up to 32x32. Does this make sense? Mike "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:486bb18e$1@newsgroups.borland.com... >
Re: Loading x48 icons with ExtractIconEx...
Author: Bob Gonder
Date: Wed, 02 Jul 2008 22:34
Date: Wed, 02 Jul 2008 22:34
7 lines
1323 bytes
1323 bytes
Mike Collins wrote: >Bob, you the man!!!!! Thank you. Cleaned up source code for my testing app is in attachments. It shows your project1 icons have 0 for many values that other apps have filled in.
Re: Loading x48 icons with ExtractIconEx...
Author: Mike Collins
Date: Wed, 02 Jul 2008 22:47
Date: Wed, 02 Jul 2008 22:47
26 lines
2045 bytes
2045 bytes
Bob, you the man!!!!! To be honest, I read that msdn article and just thought that it was ridiculously complicated and that there MUST be a shell method of doing the same thing. I really can't believe that it is that complicated and convoluted. If you consider the Explorer.exe must perform the same process for all programs in a given directory - it's a considerable overhead. I took the definitions for GRPICONDIRENTRY, GRPICONDIR and ICONIMAGE from the msdn article - I couldn't find any headers that contained them. I also defined the EnumNamesFunc as a static call back - it all works perfectly. I've also stuck in a check on e->bWidth to determine the icon size. Finally, I've free the TIcon once it's finished with. Excellent, many, many thanks Mike "Bob Gonder" <none@nowhere.invalid> wrote in message news:nion645ihefqe5tua1emrg8hl9jt11jb8r@4ax.com... > Mike Collins wrote: >
Re: Loading x48 icons with ExtractIconEx...
Author: Remy Lebeau (TeamB)
Date: Thu, 03 Jul 2008 00:31
Date: Thu, 03 Jul 2008 00:31
76 lines
3484 bytes
3484 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote in message
news:486bef13@newsgroups.borland.com...
> I know how to use LoadLibrary / LoadImage to access a
> give x48 icon. However, I don't know the Icon ID.
If you read the documentation for ExtractIconEx(), it says the index you
pass to it corresponds to the executable's RT_GROUP_ICON resources. So you
would simply extract the first RT_GROUP_ICON resource, see if it has a 48x48
icon in it, and if so then extract the RT_ICON using the provided icon ID.
Here is a function for you to do that:
struct MyEnumData
{
UINT nIconIndex;
HICON hIcon;
};
BOOL CALLBACK FindGroupIconProc(HANDLE hModule, LPCTSTR lpszType, LPTSTR
lpszName, LONG lParam)
{
MyEnumData *data = (MyEnumData*) lParam;
if( data->nIconIndex == 0 )
{
HRSRC hRsrc = FindResource(hModule, lpszName, lpszType);
HGLOBAL hGroup = LoadResource(hModule, hRsrc);
PBYTE lpGrpIconDir = (PBYTE) LockResource(hGroup);
int nIconID = LookupIconIdFromDirectoryEx(lpGrpIconDir, TRUE,
48, 48, 0);
data.hIcon = LoadImage(hModule, MAKEINTRESOURCE(nIconID),
IMAGE_ICON, 48, 48, 0);
return FALSE;
}
--(data->nIconIndex);
return TRUE;
}
HICON WINAPI ExtractIcon48(LPCSTR lpszFile, UINT nIconIndex)
{
HMODULE hLib = LoadLibraryEx(lpszFile, NULL,
LOAD_LIBRARY_AS_DATAFILE);
if( !hLib )
return NULL;
MyEnumData data;
data.nIconIndex = nIconIndex;
data.hIcon = NULL;
EnumResourceNames(hLib, RT_GROUP_ICON,
(ENUMRESNAMEPROC)&FindGroupIconProc, (LONG)&data);
FreeLibrary(hLib);
return data.hIcon;
}
> I want to show the icon that the programs author has
> assigned as the displayed icon.
That would be the icon(s) in the first RT_GROUP_ICON resource. Even a VCL
app's "MAINICON" is actually an RT_GROUP_ICON, not an individual RT_ICON
(though it usually only has 1 icon in the group).
> Using ExtractIconEx will give me the default icon but only
> up to 32x32.
When using ExtractIconEx(), you have to pass an icon index. It retreives
the RT_GROUP_ICON at the index, then extracts the contained RT_ICON
resource(s) for the HICON size(s) you specify.
Gambit
Re: Loading x48 icons with ExtractIconEx...
Author: Mike Collins
Date: Fri, 04 Jul 2008 14:04
Date: Fri, 04 Jul 2008 14:04
26 lines
2042 bytes
2042 bytes
Hay Bob, you've zip files seems to have embedded itself into the message instead of being attached as a file. Have you tested this on XP? I knocked but a demo based on the code you posted here, and ran it on my 2k3 dev machine, looking at the application that i sent you (the one with the x48 3d shield) and it all looked fine. However, when i run it on an XP test bed, it only seems to get the 4-bit (crappy) icons - which makes my gui look poor. I'll post a screen shot back on the .attachements forum for you to see. Mike C "Bob Gonder" <none@nowhere.invalid> wrote in message news:toun64912sdifaviopabqfcg395u48c9m2@4ax.com... > Mike Collins wrote: > >>Bob, you the man!!!!! > > Thank you. > Cleaned up source code for my testing app is in attachments. > It shows your project1 icons have 0 for many values that other apps have > filled in. > > >
Re: Loading x48 icons with ExtractIconEx...
Author: Bob Gonder
Date: Sat, 05 Jul 2008 01:27
Date: Sat, 05 Jul 2008 01:27
36 lines
2568 bytes
2568 bytes
Mike Collins wrote: >Hay Bob, you've zip files seems to have embedded itself into the message >instead of being attached as a file. Strange. Agent reads it fine. >Have you tested this on XP? Wrote it on XP, worked fine. Tested on Vista too. > I knocked but a demo based on the code you >posted here, and ran it on my 2k3 dev machine, looking at the application >that i sent you (the one with the x48 3d shield) and it all looked fine. >However, when i run it on an XP test bed, it only seems to get the 4-bit >(crappy) icons - which makes my gui look poor. iexplorer 7 has 3 groups of the 'e', 1)bad dither, 2)jaggies, 3)smooth. Your jpg showed what would be the second one if you had vers 7. I don't have outlook or msn so can't look up their icons. email me at embarqmail.com and I'll return-mail the zip. I'll add the exe too if you wish (32k, needs 2006 runtime). robertgonder Needs scroll bars added to the memo and image. Ok, added scroll to memo, but image can't figure out. Added TImageList and TListView, but result is TUgly. (TImageList and TListView only works with 32x AFAIKT) In the process, found out that TIcon.Width is always 32 even with a larger (or smaller) icon? Weird that Form->Image->Canvas->Draw( x, y, icon ) draws full-size icons when icon tells the world it is only 32x32.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads