Solved

Application.Icon

Posted on 2002-07-02
4
141 Views
Last Modified: 2010-04-04
I'm having a problem chaning the applications icon at runtime.  

"Application.Icon.LoadFromFile('c:\test\test.ico');"

It seems that the icon looses a lot of quality.  When it's loaded at design time it looks fine!

Is there anyway of loading an icon at runtime and not loosing quality?

I'm using D6 and win2K.  I've tried D5 and NT and many different icons with same result.

Any ideas?
0
Comment
Question by:WoodyJ007
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:TOndrej
Comment Utility
TIcon.LoadFromFile has its limitations (have a look at Graphics.ReadIcon).

When Delphi initializes the application icon (see TApplication constructor) it does not use TIcon.LoadFromFile; instead it uses LoadIcon API and assigns the returned HICON directly to its Icon.Handle.

Try something like this:

  Application.Icon.Handle := LoadImage(HInstance, PChar(ChangeFileExt(Application.ExeName, '.ico')), IMAGE_ICON, 0, 0,
    LR_DEFAULTCOLOR or LR_DEFAULTSIZE or LR_LOADFROMFILE);

HTH
TOndrej
0
 

Author Comment

by:WoodyJ007
Comment Utility
Thanks, but the icon still comes in at a poor resolution at runtime.
0
 
LVL 8

Accepted Solution

by:
TOndrej earned 50 total points
Comment Utility
Does the .ico file contain multiple icons with different sizes/color depths? In that case, perhaps you could specifically load the icon you want by specifying the desired width/height in cxDesired, cyDesired parameters and omit LR_DEFAULTSIZE flag, e.g.:

Application.Icon.Handle := LoadImage(HInstance, PChar(ChangeFileExt(Application.ExeName, '.ico')), IMAGE_ICON, 32, 32,
   LR_DEFAULTCOLOR or LR_LOADFROMFILE);

You could create a new .ico file containing only one icon.
Other than that, I'm outa ideas... Good luck.
0
 

Author Comment

by:WoodyJ007
Comment Utility
Excellent!  

I changed it to 16 x 16 and it worked great.  The icon however is 32 x 32.  All seems very wierd to me.

Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now