Solved

Application.Icon

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

832 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