Solved

Application.Icon

Posted on 2002-07-02
4
154 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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