Solved

Get window icon

Posted on 2001-07-08
8
209 Views
Last Modified: 2010-04-06
How to get window icon if I have its handle?
thanks
0
Comment
Question by:duke_n
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 161
Process Javascript errors with Delphi TWebBrowser 1 177
Printing problem 2 102
scroll down TListBox component in Delphi 1 19
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…

828 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