Solved

Application.Icon

Posted on 2002-07-02
4
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:TOndrej
ID: 7125975
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
ID: 7126360
Thanks, but the icon still comes in at a poor resolution at runtime.
0
 
LVL 8

Accepted Solution

by:
TOndrej earned 50 total points
ID: 7126394
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
ID: 7126429
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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