如何获得在C#中的窗口的图标 [英] How to get a Window's Icon in C#

查看:199
本文介绍了如何获得在C#中的窗口的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能从它的指针或过程/进程名称获取窗口的图标?在窗口的角落或在任务栏或ALT-Tab键菜单中显示的图标。

解决方案

阅读 Icon.ExtractAssociatedIcon

  

返回的图像中包含的一个图标重新presentation   指定的文件。

 私人无效ExtractAssociatedIconEx()
{
    ICO图标=
        Icon.ExtractAssociatedIcon(@C:\ WINDOWS \ SYSTEM32 \ NOTEPAD.EXE);
    this.Icon = ICO;

}
 

http://msdn.microsoft.com/en-us/library/system.drawing.icon.extractassociatedicon.aspx

上的每个进程这是行不通的,但它是一个良好的开端。

也看看这些答案 - <一个href="http://stackoverflow.com/questions/203456/how-can-i-get-the-icon-from-the-executable-file-only-having-an-instance-of-its">How可我只从有它的一个实例的可执行文件获得图标的过程在C#

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.

解决方案

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#

这篇关于如何获得在C#中的窗口的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆