Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Application.Icon

Posted on 2002-07-02
4
Medium Priority
?
169 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 200 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

Industry Leaders: 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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