Solved

Get window icon

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 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