LoadIcon的使用

LoadIcon

msdn:

Loads the specified icon resource from the executable (.exe) file associated with an application instance.



Syntax

C++

HICON WINAPI LoadIcon(
  _In_opt_  HINSTANCE hInstance,
  _In_      LPCTSTR lpIconName
);
### Parameters
*hInstance* [in, optional]
Type: **HINSTANCE**

A handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be **NULL** when a standard icon is being loaded.

*lpIconName* [in]
Type: **LPCTSTR**

The name of the icon resource to be loaded. Alternatively, this parameter can contain the resource identifier in the low-order word and zero in the high-order word. Use the [**MAKEINTRESOURCE**](http://msdn.microsoft.com/en-us/library/windows/desktop/ms648029(v=vs.85).aspx) macro to create this value.

To use one of the predefined icons, set the *hInstance* parameter to **NULL** and the *lpIconName* parameter to one of the following values.



在初始化时,我们可以这样使用:

wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;

使用系统预定义图标,必须把第一个参数设置为NULL.

相应的显示:

![](//img-blog.csdn.net/20130924210558406?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveF9peWE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

另外,我们也可以使用自定义的图标:

用到MAKEINTRESOURCE宏

## MAKEINTRESOURCE

Converts an integer value to a resource type compatible with the resource-management functions. This macro is used in place of a string containing the name of the resource.

### Syntax
[C++](C++)

LPTSTR MAKEINTRESOURCE(
  WORD wInteger
);

### Parameters

*wInteger*
The integer value to be converted.

说说使用:

在VS2012下的Resource View下的项目添加ICO文件,它会生成ID号,默认的IDI_ICON1.

![](//img-blog.csdn.net/20130924211148375?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveF9peWE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

引入resource.h

修改如下:

wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1)) ;

![](//img-blog.csdn.net/20130924211208031?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveF9peWE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)



原文链接: https://www.cnblogs.com/lgh1992314/p/5834913.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/105711

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月10日 上午8:19
下一篇 2023年2月10日 上午8:20

相关推荐