");
if (fileDialog.DoModal() == IDOK)
{
szOpenFileName=fileDialog.GetPathName();
szOpenFileExtName= fileDialog.GetFileExt ();
szOpenFileExtName.MakeLower ();
m_List.ResetContent (); //选清空左侧图标列表框
//读取并显示ICON文件
if(szOpenFileExtName =="ico")
{
lpIR=pIcons->ReadIconFromICOFile (szOpenFileName);
HICON hIcon;
hIcon=ExtractIcon(AfxGetInstanceHandle(),szOpenFileName,0);
if(hIcon!=NULL)
m_List.AddString (szOpenFileName);
CStatic* pStatic = (CStatic*) GetDlgItem(IDC_ICONS);
pStatic->SetIcon (hIcon);
}
else if(szOpenFileExtName == "bmp") //读取并显示BMP文件
{
pIcons->IconImageFromBMPFile (szOpenFileName,&lpIR->IconImages[0],TRUE);
HICON hIcon;
hIcon=pIcons->MakeIconFromResource (&lpIR->IconImages [0]);
if(hIcon!=NULL)
m_List.AddString (szOpenFileName);
CStatic* pStatic = (CStatic*) GetDlgItem(IDC_ICONS);
pStatic->SetIcon (hIcon);
}
else //读取并显示EXE、DLL等资源文件
{
HINSTANCE hLibrary;
// Load the DLL/EXE - NOTE: must be a 32bit EXE/DLL for this to work
if( (hLibrary = LoadLibraryEx( szOpenFileName, NULL, LOAD_LIBRARY_AS_DATAFILE )) == NULL )
{
// Failed to load - abort
MessageBox( szOpenFileName+ "文件载入错误,必须是WIN32的文件!", "错误", MB_OK );
return;
}
// Store the info
EDII.szFileName =szOpenFileName;
EDII.hInstance = hLibrary;
// Fill in the listbox with the icons available
if( ! EnumResourceNames( EDII.hInstance, RT_GROUP_ICON, (ENUMRESNAMEPROC )MyEnumProcedure, (LPARAM)GetSafeHwnd()) )
{
MessageBox( "列举图标资源名时出错!", "错误", MB_OK );
return;
}
}
m_List.SetCurSel (0);
if( m_List.GetCount() == 0 )
{
MessageBox( "此文件中没有图标资源!", "错误", MB_OK );
//无图标资源,置保存和复制按钮为无效状态
m_Copy.EnableWindow (false);
m_SaveAs.EnableWindow (false);
return;
}
//有图标资源,置保存和复制按钮为有效状态
m_Copy.EnableWindow (true);
m_SaveAs.EnableWindow (true);
//刷新调用OnPaint来显示图标
InvalidateRect(NULL,TRUE);
}
}
在OnPaint()涵数中加入下面代码用来具体显示提取出的图标或位图资源。
//根据左侧图标列表,利用OnPaint()来更新右侧相应图标
LPTSTR lpIconID;
HICON hIcon;
if((lpIconID=(LPTSTR)m_List.GetItemData(m_List.GetCurSel()))!=(LPTSTR)LB_ERR )
{
if(szOpenFileExtName=="exe"(北联网教程,专业提供视频软件下载)
……