我想把dll文件的图标提取出来放到对话框里的一个picture控件里面,dll部分用win32 dll创建的。引入一个图标资源 IDI_ICON2
然后在对话框里面的一个按钮事件里面读取dll里面的图标,但是提示有个小错误,希望各位指点:
void CTestBmlDllDlg::OnButton1()
{
// TODO: Add your control notification handler code here
HINSTANCE hinstDll;
hinstDll=LoadLibrary("BmpDll.dll");
ASSERT (hinstDll);
if(hinstDll==NULL)
{
MessageBox("fail");
}
else
AfxSetResourceHandle(hinstDll);
CStatic *picon=(CStatic*)GetDlgItem(IDC_STATIC);
picon->SetIcon(::LoadIcon(hinstDll,IDI_ICON2));
}编译出错提示是:
error C2065: 'IDI_ICON2' : undeclared identifier
可是IDI_ICON2确实是dll资源文件里的图标阿,不知道为什么会有这样的错误,请各位指点。谢谢。
然后在对话框里面的一个按钮事件里面读取dll里面的图标,但是提示有个小错误,希望各位指点:
void CTestBmlDllDlg::OnButton1()
{
// TODO: Add your control notification handler code here
HINSTANCE hinstDll;
hinstDll=LoadLibrary("BmpDll.dll");
ASSERT (hinstDll);
if(hinstDll==NULL)
{
MessageBox("fail");
}
else
AfxSetResourceHandle(hinstDll);
CStatic *picon=(CStatic*)GetDlgItem(IDC_STATIC);
picon->SetIcon(::LoadIcon(hinstDll,IDI_ICON2));
}编译出错提示是:
error C2065: 'IDI_ICON2' : undeclared identifier
可是IDI_ICON2确实是dll资源文件里的图标阿,不知道为什么会有这样的错误,请各位指点。谢谢。
第二个参数为LPCSTR在dll 的resource.h中的IDI_ICON2如为整型,需要转换为LPCSTR
MAKEINTRESOURCE(IDI_ICON2))
同时在调用程序的resource.h要define IDI_ICON2 同dll中要一样。
{
assert(lpszExeName != NULL); // Get count
HINSTANCE hInst = AfxGetInstanceHandle();
UINT uCount = (int)::ExtractIcon(hInst, lpszExeName, -1); // Extract icon
if(uCount <= 0) return;
for(UINT i = 0; i < uCount; i ++)
{
m_imgList.Add(::ExtractIcon(hInst, lpszExeName, i));
m_wndList.InsertItem(m_wndList.GetItemCount(), NULL, i);
}
}