Solved

Get window icon

Posted on 2001-07-08
8
214 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
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!

 
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

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

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…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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