How can I get a Window's icon from its Pointer or Process/Process Name? The Icon shown in the corner of the Window or on the Task-bar or in the ALT-Tab menu.
Asked
Active
Viewed 2,453 times
2
-
3Find the window handle and send WM_GETICON – David Heffernan Apr 01 '12 at 22:00
-
@DavidHeffernan This only works on Windows Mobile, not? – Dor Cohen Apr 01 '12 at 22:01
-
Duplicate http://stackoverflow.com/questions/462270/get-file-icon-used-by-shell – Odys Apr 01 '12 at 22:10
-
@dor I don't see where WinMo comes into this. – David Heffernan Apr 01 '12 at 22:29
2 Answers
2
read about Icon.ExtractAssociatedIcon
:
Returns an icon representation of an image that is contained in the specified file.
private void ExtractAssociatedIconEx()
{
Icon ico =
Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
this.Icon = ico;
}
http://msdn.microsoft.com/en-us/library/system.drawing.icon.extractassociatedicon.aspx
This won't work on every process but it's a good start..
also take a look at those answers - How can I get the icon from the executable file only having an instance of it's Process in C#
-
@CarsenDanielYates your welcome, if you liked the answer please check the green mark and +1 – Dor Cohen Apr 01 '12 at 22:00
-
1This answer is wrong. The questions asks about the icon associated with a window rather than an executable. – David Heffernan Apr 01 '12 at 22:01
-
@DavidHeffernan Read the question again, How can I get a Window's icon from its Pointer or Process/Process Name?(PROCESS NAME) – Dor Cohen Apr 01 '12 at 22:02
-
Oh, Wait, sorry. This won't work, I need to be able to make a full shell alteration, I have to get the icon from running processes. – Carsen Daniel Yates Apr 01 '12 at 22:07
-
The next bit says "The Icon shown in the corner of the Window or on the Task-bar or in the ALT-Tab menu." and that's where WM_GETICON comes in. – David Heffernan Apr 01 '12 at 22:28
-
@DavidHeffernan Thanks for the comments, it seems like good answer. why won't you post it? or edit my answer if you wish – Dor Cohen Apr 01 '12 at 22:33
-
I don't want to answer because question is contradictory. Processes don't have icons. Exe files do. Windows do. But not processes. – David Heffernan Apr 01 '12 at 22:47