EnumResourceNames枚举资源


CImageList cImageListIcons;

BOOL CEnumRsrcDlg::OnInitDialog()
{
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());
}

}


效果图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QPZME

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值