CImageList cImageListIcons;
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
char szPath[256]={0};
GetModuleFileName(NULL,szPath,256);
SetDlgItemText(IDC_EDIT1,szPath);
cImageListIcons.Create(35,35,ILC_COLOR24|ILC_MASK,0,0);
//关联
m_listCtrlIcons.SetImageList(&cImageListIcons,LVSIL_NORMAL);
return TRUE; // return TRUE unless you set the focus to a control
}
//参数结构体
struct LParam
{
CListBox*pListBox;
CListCtrl*pListCtrl;
};
int index=0;
//枚举
BOOL CALLBACK EnumResNameProc(
HMODULE hModule,
LPCTSTR lpszType,
LPTSTR lpszName,
LPARAM lParam
)
{
LParam *lpTmp=(LParam*)lParam;
if(lpszType==RT_GROUP_ICON)
{
//load
HICON hic=LoadIcon(hModule,lpszName);
int nImageIndex= cImageListIcons.Add(hic);
//Icon id
DWORD dwIconID=(DWORD)lpszName;
char szFormat[50]={0};
sprintf(szFormat,"Icon[%d]",dwIconID);
lpTmp->pListBox->AddString(szFormat);
lpTmp->pListCtrl->InsertItem(index,szFormat,nImageIndex);
index++;
DestroyIcon(hic);
}
else if(lpszType== RT_BITMAP)
{
HBITMAP bit=LoadBitmap(hModule,lpszName);
CBitmap *bitmap=CBitmap::FromHandle(bit);
int nImageIndex= cImageListIcons.Add(bitmap,RGB(255,255,255));
//Icon id
DWORD dwIconID=(DWORD)lpszName;
char szFormat[50]={0};
sprintf(szFormat,"Bitmap[%d]",dwIconID);
lpTmp->pListBox->AddString(szFormat);
lpTmp->pListCtrl->InsertItem(nImageIndex,szFormat,nImageIndex);
DeleteObject(bit);
}else if (lpszType==RT_DIALOG)
{
DWORD dwIconID=(DWORD)lpszName;
char szFormat[50]={0};
sprintf(szFormat,"Dialog[%d]",dwIconID);
lpTmp->pListBox->AddString(szFormat);
}else if (lpszType==RT_GROUP_CURSOR)
{
HCURSOR hCursor= LoadCursor(hModule,lpszName);
DWORD dwIconID=(DWORD)lpszName;
char szFormat[50]={0};
sprintf(szFormat,"Cursor[%d]",dwIconID);
int nIndex=cImageListIcons.Add((HICON)hCursor);
lpTmp->pListBox->AddString(szFormat);
lpTmp->pListCtrl->InsertItem(nIndex,szFormat,nIndex);
DestroyCursor(hCursor);
}
return TRUE;
}
void CEnumRsrcDlg::OnButton1()
{
//清空
m_listCtrlIcons.DeleteAllItems();
m_listBoxIconIds.ResetContent();
LParam lp;
lp.pListBox=&m_listBoxIconIds;
lp.pListCtrl=&m_listCtrlIcons;
char szPath[256]={0};
GetDlgItemText(IDC_EDIT1,szPath,256);
HMODULE hModule=LoadLibrary(szPath);
//枚举ICON
EnumResourceNames(hModule,RT_GROUP_ICON,EnumResNameProc,(LPARAM)&lp);
//枚举bitmap
EnumResourceNames(hModule,RT_BITMAP,EnumResNameProc,(LPARAM)&lp);
//枚举dialog
EnumResourceNames(hModule,RT_DIALOG,EnumResNameProc,(LPARAM)&lp);
//枚举cursor
EnumResourceNames(hModule,RT_GROUP_CURSOR,EnumResNameProc,(LPARAM)&lp);
}
void CEnumRsrcDlg::OnButton2()
{
CFileDialog fileOpen(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,NULL,this);
//过滤
fileOpen.m_ofn.lpstrFilter="exe\0*.exe\0dll\0*.dll\0All Files\0*.*\0\0";
if (fileOpen.DoModal()==IDOK)
{
SetDlgItemText(IDC_EDIT1,fileOpen.GetPathName());
}
}
效果图: