Get icon from filename on Windows 8

Hi,
Does anyone knows how the right way to get icon from filename on windows 8? I use the code below on windows 7, and it works. When using the same code on windows 8, some applications (filename), appear with a default icon, although the real icon is another in windows explorer:

function GetFileIcon(FileName: String): HICON;
var lFileInfo: SHFILEINFO;
begin
   FillMemory(@lFileInfo,SizeOf(lFileInfo),0);
   Result := 0;

  if (SHGetFileInfo(PWideChar(FileName), FILE_ATTRIBUTE_DIRECTORY, lFileInfo, SizeOf(lFileInfo), 
      SHGFI_ICON OR SHGFI_SYSICONINDEX) > 0) then //SHGFI_LARGEICON OR SHGFI_SMALLICON
  begin
    Result := lFileInfo.hIcon;
  end;
end;

Is there a different primitive to get the icon?  SHGetFileInfoW, or SHGetFileInfoA? Or the place in registry where we should look for icon information changed from windows 7 to 8, to another place?
Thanks any help.
Best Regards,
Ana Rodrigues
0
Ana
7/30/2015 8:04:34 AM
embarcadero.delphi.nativeapi 1236 articles. 1 followers. Follow

3 Replies
1023 Views

Similar Articles

[PageSpeed] 36
Get it on Google Play
Get it on Apple App Store

Ana wrote:

> Does anyone knows how the right way to get icon from filename
> on windows 8? I use the code below on windows 7, and it works.
> When using the same code on windows 8, some applications
> (filename), appear with a default icon, although the real icon is
> another in windows explorer

What is the actual return value of SHGetFileInfo(), and what does the content 
of the SHFILEINFO look like?

Microsoft is not in the habit of breaking existing APIs, especially one as 
old as SHGetFileInfo().

On a side note, why are you specifying FILE_ATTRIBUTE_DIRECTORY for a file? 
 In any case, since you are not specifying the SHGFI_USEFILEATTRIBUTES flag, 
that parameter is ignored anyway.

-- 
Remy Lebeau (TeamB)
0
Remy
7/30/2015 4:19:12 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Ana wrote:
> 
> > Does anyone knows how the right way to get icon from filename
> > on windows 8? I use the code below on windows 7, and it works.
> > When using the same code on windows 8, some applications
> > (filename), appear with a default icon, although the real icon is
> > another in windows explorer
> 
> What is the actual return value of SHGetFileInfo(), and what does the content 
> of the SHFILEINFO look like?

> 
> Microsoft is not in the habit of breaking existing APIs, especially one as 
> old as SHGetFileInfo().
> 
> On a side note, why are you specifying FILE_ATTRIBUTE_DIRECTORY for a file? 
>  In any case, since you are not specifying the SHGFI_USEFILEATTRIBUTES flag, 
> that parameter is ignored anyway.
> 
> -- 
> Remy Lebeau (TeamB)


Hi,
Thank you for your reply. The value returned from SHGetFileInfo() is an integer non zero for the particular application.
If IconHandle return by that API, is non zero, i get it right. If it is zero, i put a default icon from an ImageList of mine. strangely, today, it worked in windows 8 as windows 7. Yes, microsoft doesnt have that habit, but i though something has changed in registry information, about applications icons, not the API.
Thanks!

                if IconHandle <> 0 then begin
                   Icon.Handle := IconHandle;
                end
                else begin
                   ImagemSemIcon := TIcon.Create;
                   ImgListNoIcon.GetIcon(0,ImagemSemIcon);
                   Icon.Handle   := ImagemSemIcon.Handle;
                end;{Aplicacao não tem icon}
0
Ana
8/3/2015 9:06:21 AM
> {quote:title=Ana Rodrigues wrote:}{quote}
> > {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> > Ana wrote:
> > 
> > > Does anyone knows how the right way to get icon from filename
> > > on windows 8? I use the code below on windows 7, and it works.
> > > When using the same code on windows 8, some applications
> > > (filename), appear with a default icon, although the real icon is
> > > another in windows explorer
> > 
> > What is the actual return value of SHGetFileInfo(), and what does the content 
> > of the SHFILEINFO look like?
> 
> > 
> > Microsoft is not in the habit of breaking existing APIs, especially one as 
> > old as SHGetFileInfo().
> > 
> > On a side note, why are you specifying FILE_ATTRIBUTE_DIRECTORY for a file? 
> >  In any case, since you are not specifying the SHGFI_USEFILEATTRIBUTES flag, 
> > that parameter is ignored anyway.
> > 
> > -- 
> > Remy Lebeau (TeamB)
> 
> 
> Hi,
> Thank you for your reply. The value returned from SHGetFileInfo() is an integer non zero for the particular application.
> If IconHandle return by that API, is non zero, i get it right. If it is zero, i put a default icon from an ImageList of mine. strangely, today, it worked in windows 8 as windows 7. Yes, microsoft doesnt have that habit, but i though something has changed in registry information, about applications icons, not the API.
> Thanks!
> 
>                 if IconHandle <> 0 then begin
>                    Icon.Handle := IconHandle;
>                 end
>                 else begin
>                    ImagemSemIcon := TIcon.Create;
>                    ImgListNoIcon.GetIcon(0,ImagemSemIcon);
>                    Icon.Handle   := ImagemSemIcon.Handle;
>                 end;{Aplicacao não tem icon}

Hi again,
Just found another way to get the correct icon of an application. Just used JclSysInfo from JEDI:
function GetWindowIcon(Wnd: THandle; LargeIcon: Boolean): HICON;
It worked just fine, on both scenarios win 7 and win 8.
Best Regards
0
Ana
8/3/2015 1:49:14 PM
Reply:

Similar Artilces:

Delphi Program Running Under Windows 8 vs. Windows 7
If a program, created with D2007, runs fine under Windows 7, it should run under Windows 8, correct? It's basically the same Intel architecture, right? The program created with D2007 does nothing fancy - I'm no professional programmer. Installation may be slightly different - i.e., the installation program may need some modifying I assume, to install under Windows 8. I don't have Windows 8 right now, I'm just trying to gather some information for a client. Thanks Your program won't run only on Windows RT (ARM version of windows). On all other versio...

Delphi
Dear All, Sorry to ask 2 questions in 24 hours! (I have just come back to using Delphi after a break and I am finding the 2009 version fanstastic! - Just installing 2010 also!) Does anyone know how to call windows to hide/show the Wireless Networking Tray icon in Windows XP from Delphi? Many Thanks Mark <Mark Williams> wrote in message news:178978@forums.codegear.com... > Does anyone know how to call windows to hide/show the > Wireless Networking Tray icon in Windows XP from Delphi? System Tray icons can only be shown/hidden by the apps that call Shell_Notify...

12.1 / Taskbar / Desktop Icon / Windows: How to get the Windows Showing?
Hello, I have the following problem: The taskbar shows 6 Desktop Icons. Mouse over Desktop Icon #1 shows 6 Windows (i.e. Tasks). Can somebody please suggest how I can grab one of those task? My system is x86_64 with all the latest updates, so I am the one who needs to be updated, please! And: If it is possible having all tasks accessible with the taskbar, I would be very happy! Thanks and best regards, J C Anker -- jc_anker ------------------------------------------------------------------------ My guess is you're on KDE, and you're talking about the...

Windows 8+ and Delphi
OK, let me get this clear. With all the discussions on Windows 8 and beyond, and HTML5/JS seemingly doing all the work, we will be needing a programming language to code the backend, right? I mean, if not, then Delphi/C++Builder will cease to exist by the time Windows 8 arrives... "Jennifer-Ashley Kuiper" <jennifer@maindevelopment.com> wrote in message news:372999@forums.embarcadero.com... > OK, let me get this clear. With all the discussions on Windows 8 and > beyond, and HTML5/JS seemingly doing all the work, we will be needing a > programming language...

How about Delphi for Windows 8?
<BG> CB > {quote:title=Charles B wrote:}{quote} > <BG> > > CB My first Win8 test report: business customers will like this "new" "OS". iWindows8! iStupid! iGnore iT! Frankly, Windows 8 is already the past. I guess we should ask what about Delphi for Windows 9, 10, and the next secret version as well. Charles B wrote: > <BG> > > CB The press release said something about a new inter-application interface, that will make it easier to include e.g. pictures from various sources in your email. Dunno if that mean...

Windows 8 Application with Delphi
Hi all: With the release of MS windows 8 beta today, is it possible to create Metro style (with Touch interface) applications with Delphi? Is there a beta version of Delphi you would need for this? Thanks Bob Bob McKinnon wrote: > Is there a beta > version of Delphi you would need for this? If anybody answered this question Embarcadero would have to kill them. ;-) -- Andy Syms Technosoft Systems Ltd "Real knowledge is to know the extent of one's ignorance." -- Confucius So is visual studio my best bet? I believe they have a beta versio...

Delphi XE2 and Windows 8
Are there any issues running Delphi XE2 in Windows 8 ? Google searches have given me nothing. Aware that I can't use Windows 8 features in XE2, just want to be able to continue running XE2 and developing/testing Windows XP -> WIndows 7 applications ? Thanks. > {quote:title=Christopher Burke wrote:}{quote} > Are there any issues running Delphi XE2 in Windows 8 ? > > Google searches have given me nothing. > > Aware that I can't use Windows 8 features in XE2, just want to be able to > continue running XE2 and developing/testing Windows XP -&...

Delphi 2010 and Windows 8
I was going to update to Windows 8 when it comes out but when I ran the compatibilty test on my computer it said Delphi 2010 was not compatible. Does anybody know if this is a real problem ? ...

Delphi and Windows 8 (Metro)
I am beta testing the windows 8 platform. With all the Metro style abilities for touch? Would that require some change out of the existing application development.... According to MS news, the VS11 would support the metro templates as a default.. What does it mean delphi wise? On 9/17/2011 10:31 AM, Amit Bueno wrote: > According to MS news, the VS11 would support the metro templates as a > default.. > What does it mean delphi wise? Its going to require some work. Probably XE3 even... -- "Programming is an art form that fights back" IntraWeb IRC and W...

Delphi XE application on Windows 8
Hi, I am using Delphi XE to develop my application. The app runs fine on XP, Vista and Win7. When it is run on Win8, however, the user says that the app always starts up with a small form size so he has to re-size it each time before he can use it. He also says that if he runs it in XP Compatibility Mode then it starts ok with the correct form size. I've tried setting the main form height and width in the OnActivate event but this makes no difference. It seems that the user can re-size the app but the app cannot re-size itself! I don't have a Win8 machine yet to test this myself...

Buying a new Windows 8.1 laptop with Windows 8.1 installed
When buying a new laptop from one of the major manufacturers, like Dell or Lenovo, with Windows 8.1 installed, is it possible to set it up with just a Local Account and not a Microsoft Account? -- Chris On 11/2/2013 11:28 AM, Chris wrote: > When buying a new laptop from one of the major > manufacturers, like Dell or Lenovo, with Windows 8.1 > installed, is it possible to set it up with just a Local > Account and not a Microsoft Account? Yes, look here; http://www.techrepublic.com/blog/windows-and-office/quick-tip-change-to-a-local-account-in-windows-81/ On 11/2/201...

Windows 8 WinRT & Delphi
Gartner predicts Tablet sales to total 119 million units in 2012, a 98 percent increase from 2011. They predict 2013 sales to be 182 Million units, a 53% increase from 2012. Whatever figures you believe, the Tablet market is HUGE and growing VERY quickly over the next few years. Windows 8 tablets running WinRT will be a significant player in this market. They are in the shops in 2 months. It has JUST been publicly made clear that Delphi developers will NOT be able to develop WindowsRT applications for this market using XE3. Note: this is via newsgroups from Allen Bauer https://forum...

Getting a Temporary filename from windows or NT
I need a temporary file name, and I'd like to get it from windows. The stdio.h call Iwould make in C is tmpnam() to get a string pointer. Any idea how I can get this in PB 6.5? Thanks On Mon, 11 Jan 1999 19:57:38 GMT, in powersoft.public.powerbuilder.general Peter Kellner <peter@kellner.com> wrote: >I need a temporary file name, and I'd like to get it from windows. >The stdio.h call Iwould make in C is tmpnam() to get a string pointer. >Any idea how I can get this in PB 6.5? > >Thanks There is a GetTempFileName function in the Windows API: UIN...

Migrating all Delphis from Vista to Windows 8
Imagine you have Delphi 5, Delphi 2010, and Delphi XE2 on your Vista development machine. You want to upgrade to Windows 8.1. From what I gather, the MS upgrade procedure will just dump everything in the bit bucket in the sky and all applications need to be re-installed. Imagine you don't want to spend a week or two re-installing everything and you're not using any VM. How would you go about it? The best I can find is CnPack's IDE config backup/restore. Anyone tried it with this? For all other applications that use the registry, any reliable registry migration uti...

Web resources about - Get icon from filename on Windows 8 - embarcadero.delphi.nativeapi

Filename - Wikipedia, the free encyclopedia
directory (or path ) – directory tree (e.g., /usr/bin , \TEMP, [USR.LIB.SRC], etc.) type (format or extension ) – indicates the content type ...

Leaked Windows Phone 7 ROM filename suggests an HTC Mondrian?
The lads and lassies at XDA-Developers made an intriguing discovery this week: a leaked 100MB file that might be the first Windows Phone 7 ROM ...

Patent US5758352 - Common name space for long and short filenames - Google Patents
An operating system provides a common name space for both long filenames and short filenames. In this common namespace, a long filename and a ...

Girls playing with cell phones Original Filename: kids texting.jpg
Mediaite Gossip Cop Geekosystem Styleite SportsGrid The Mary Sue The Jane Dough The Braiser Stewart Rips Obama's Drone Hypocrisy: Only Transparent ...


LG Smart TV spying, owner claims his USB filenames posted on LG servers
A new LG Smart TV owner claimed that LG collects info from connected devices, like USBs, and uploads it to LG servers, even when collection of ...

[INI file] [uwsgi] project_name = cb # important for unicode filenames env - Pastebin.com
PASTEBIN - #1 paste tool since 2002 create new paste tools api archive faq PASTEBIN create new paste trending pastes sign up login my alerts ...

CryptoWall 4.0 Released With Filename Encryption Feature
CryptoWall 4.0 has been released recently and the latest version of the notorious file-encrypting ransomware brings several notable changes. ...

LG Smart TVs logging USB filenames and viewing info to LG servers
DoctorBeet : LG Smart TVs logging USB filenames and viewing info to LG servers — Earlier this month I discovered that my new LG Smart TV was ...

Terminal Tips: Generate random filenames for digital photo frame images
It's not at all unlikely that you or a relative have received a digital photo frame as some sort of gift. The concept is great, one frame on ...

Resources last updated: 12/13/2015 2:03:29 PM