Solved

Get window icon

Posted on 2001-07-08
8
210 Views
Last Modified: 2010-04-06
How to get window icon if I have its handle?
thanks
0
Comment
Question by:duke_n
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6262234
Hi duke_n,

here is it:

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  H: HIcon;
begin
  H := SendMessage(Handle, WM_GETICON, ICON_BIG, 0);
  DrawIcon(Canvas.Handle, 30, 30, H);

  H := SendMessage(Handle, WM_GETICON, ICON_SMALL, 0);
  DrawIcon(Canvas.Handle, 50, 30, H);
end;

-----
Igor
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 6262247
Hi Igor,
I don't know why, but your code doesn't work for me:

procedure TForm1.Button1Click(Sender: TObject);
var
 hwindow : THandle;
 H : HIcon;
begin
 hwindow := FindWindow('notepad',nil);
 H := SendMessage(hwindow, WM_GETICON, ICON_BIG, 0);
 {or ICON_SMALL}
 DrawIcon(Canvas.Handle, 30, 30, H);
end;

But this code works for me:

procedure TForm1.Button1Click(Sender: TObject);
var
 hwindow : THandle;
 H: HIcon;
begin
 hwindow := FindWindow('notepad',nil);
 H := CopyIcon(GetClassLong(hwindow, GCL_HICON ));
 DrawIcon(Canvas.Handle, 30, 30, H);
end;

tas
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 6262253
Hi Igor,
I don't know why, but your code doesn't work for me:

procedure TForm1.Button1Click(Sender: TObject);
var
 hwindow : THandle;
 H : HIcon;
begin
 hwindow := FindWindow('notepad',nil);
 H := SendMessage(hwindow, WM_GETICON, ICON_BIG, 0);
 {or ICON_SMALL}
 DrawIcon(Canvas.Handle, 30, 30, H);
end;

But this code works for me:

procedure TForm1.Button1Click(Sender: TObject);
var
 hwindow : THandle;
 H: HIcon;
begin
 hwindow := FindWindow('notepad',nil);
 H := CopyIcon(GetClassLong(hwindow, GCL_HICON ));
 DrawIcon(Canvas.Handle, 30, 30, H);
end;

tas
0
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!

 
LVL 2

Expert Comment

by:Tasomia
ID: 6262262
Hi Igor,
I don't know why, but your code doesn't work for me:

procedure TForm1.Button1Click(Sender: TObject);
var
 hwindow : THandle;
 H : HIcon;
begin
 hwindow := FindWindow('notepad',nil);
 H := SendMessage(hwindow, WM_GETICON, ICON_BIG, 0);
 {or ICON_SMALL}
 DrawIcon(Canvas.Handle, 30, 30, H);
end;

But this code works for me:

procedure TForm1.Button1Click(Sender: TObject);
var
 hwindow : THandle;
 H: HIcon;
begin
 hwindow := FindWindow('notepad',nil);
 H := CopyIcon(GetClassLong(hwindow, GCL_HICON ));
 DrawIcon(Canvas.Handle, 30, 30, H);
end;

tas
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6262272
hi tas,

CopyIcon works for different modules while SendMessage(...WM_GETICON...) for current.

----
Igor.
0
 
LVL 1

Author Comment

by:duke_n
ID: 6262332
Wow, emailbomb :))
Wait a sec.

I need to get icons of all programs' icons, not only mine(I can do that one with Form.Icon easier)
0
 
LVL 1

Author Comment

by:duke_n
ID: 6262341
nope, I don't know what the fuss is all about.
ITUgay's function works fine on all the processes.

although there isn't always a small icon, but that can be handled.

lemme check the second suggestion
0
 
LVL 1

Author Comment

by:duke_n
ID: 6262352
the second suggestion always seems to get the small icon.
But ITugay was first and the points are his.
0

Featured Post

Independent Software Vendors: 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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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