用下面代码可获取文件关联程序的图标:
CFileDialog fileDialog( TRUE,"*.*",NULL,NULL,NULL);
if (fileDialog.DoModal() != IDOK) return;
CString str= fileDialog.GetFileExt();
str="."+str;
SHFILEINFO sfi;
SHGetFileInfo(str,0,&sfi,sizeof(sfi),SHGFI_ICON|SHGFI_LARGEICON|SHGFI_USEFILEATTRIBUTES);
int i=sfi.iIcon;
CStatic* pStatic = (CStatic*) GetDlgItem(IDC_STATIC);
HICON hIcon=sfi.hIcon;
pStatic->SetIcon (hIcon);
上面的IDC_STATIC是一个静态控件。