主题:高人指点:加载图标到按钮控件的奇怪现象,是不是微软故弄玄虚
asfno1
[专家分:40] 发布于 2008-08-07 00:04:00
先设置属性:ICON
我先用:
HICON hic;
hic=AfxGetApp()->LoadIcon(IDI_ICON1);
GetDlgItem(IDC_BUTTON1)->SetIcon(hic,TRUE);//TRUE:32*32,FALSE:16*16
上面的代码加载无效
如添加一个控件变量:m_iconbt换成下:
HICON hic;
hic=AfxGetApp()->LoadIcon(IDI_ICON1);
m_iconbt.SetIcon(hic);
加载图标成功
这是怎么回事,是不是VC++的漏洞太多?还是微软故意的?
真搞不懂也!!!!!!!!!!!!!!!!!!!!!!
回复列表 (共1个回复)
沙发
小小C [专家分:4570] 发布于 2008-08-07 12:39:00
呵呵,正因为这样,所以我尽量少用MFC,坚持用WIN32API
The LoadIcon function loads the specified icon resource from the executable (.EXE) file associated with an application instance.
HICON LoadIcon(
HINSTANCE hInstance, // handle of application instance
LPCTSTR lpIconName // icon-name string or icon resource identifier
);
Parameters
hInstance
Identifies 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
Points to a null-terminated string that contains 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 macro to create this value.
To use one of the Windows predefined icons, set the hInstance parameter to NULL and the lpIconName parameter to one of the following values:
Value Description
IDI_APPLICATION Default application icon.
IDI_ASTERISK Asterisk (used in informative messages).
IDI_EXCLAMATION Exclamation point (used in warning messages).
IDI_HAND Hand-shaped icon (used in serious warning messages).
IDI_QUESTION Question mark (used in prompting messages).
IDI_WINLOGO Windows logo.
Return Values
If the function succeeds, the return value is the handle of the newly loaded icon.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
我来回复