SHFILEINFO shFinfo; int iIcon, iIconSel; CString strTemp = "temp.txt";
if ( strTemp.Right(1) != '\\' ) strTemp += "\\"; if ( !SHGetFileInfo( strTemp, 0, &shFinfo, sizeof( shFinfo ), SHGFI_ICON | SHGFI_SMALLICON ) ) { m_strError = "Error Gettting SystemFileInfo!"; return NULL; } iIcon = shFinfo.iIcon; // we only need the index from the system image list DestroyIcon( shFinfo.hIcon ); if ( !SHGetFileInfo( strTemp, 0, &shFinfo, sizeof( shFinfo ), SHGFI_ICON | SHGFI_OPENICON | SHGFI_SMALLICON ) ) { m_strError = "Error Gettting SystemFileInfo!"; return NULL; } iIconSel = shFinfo.iIcon; // we only need the index of the system image list DestroyIcon( shFinfo.hIcon );
int iIcon, iIconSel;
CString strTemp = "temp.txt";
if ( strTemp.Right(1) != '\\' )
strTemp += "\\";
if ( !SHGetFileInfo( strTemp,
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_ICON |
SHGFI_SMALLICON ) )
{
m_strError = "Error Gettting SystemFileInfo!";
return NULL;
} iIcon = shFinfo.iIcon; // we only need the index from the system image list DestroyIcon( shFinfo.hIcon ); if ( !SHGetFileInfo( strTemp,
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_ICON | SHGFI_OPENICON |
SHGFI_SMALLICON ) )
{
m_strError = "Error Gettting SystemFileInfo!";
return NULL;
} iIconSel = shFinfo.iIcon; // we only need the index of the system image list DestroyIcon( shFinfo.hIcon );
谢谢你的代码,刚才测试了一下,在程序启动时将窗口左上角的图标换成取得的图标,结果没什么效果,不知为什么?请指教。
我打开的是一个Word文档,取它的关联图标。public:
HICON hicon;.Cpp BOOL CMyDlg::OnInitDialog()
{
.....
CString strTemp = "C:\\resume.doc";
.....
hicon= AfxGetApp()->LoadIcon(hicon);
SetIcon(hIconBrowse,true);
.....
}
调用。iIconSel是int类型啊。
调用。iIconSel是int类型啊。
为什么下面将系统中图标序号转换HICON的形式会出错????? HICON myIcon, mysIcon;
ExtractIconEx("shell32.dll", 0, &myIcon, &mysIcon, 55); //55为系统中图标序号 SetIcon(mysIcon,true); //设置窗口图标
比如我想把取得的关联图标显示出来,结果不行。
我打开的是一个Word文档,取它的关联图标。在对话框启动时用来显示左上角的图标。public:
HICON hicon;.Cpp BOOL CMyDlg::OnInitDialog()
{
.....
CString strTemp = "C:\\resume.doc";
..... // oracle3(kk)的代码,已经将DestroyIcon( shFinfo.hIcon );语句注释掉了。 ExtractIconEx("shell32.dll", 0, &myIcon, &mysIcon, iIcon); //自己加的语句,用于转换成HICON的类型,但好像不行。
hicon= AfxGetApp()->LoadIcon(hicon);
SetIcon(hIconBrowse,true);
.....
}