Solved

Get window icon

Posted on 2001-07-08
8
202 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now