dll中对话框上的CListCtrl控件,第2次出现时不能设置图标
蒙飞鸿 2011-02-14 05:55:56 一个DLL中有一个对话框窗口类为DLLDlg,是在DLL中加入一个对话框资源后通过CLASSWIZZARD生成的,功能是做个资源管理器样的窗口。
该对话框为了被调用显示,有成员函数:
int DLLDlg::RemoteFileMng(char *ip, UINT uiPort)
{
m_Ip = ip;
m_UiPort = uiPort;
DoModal();
return m_netFuncRet;
}
为了避免“资源切换”的问题,做了一个导出类:
class AFX_EXT_CLASS UIShell : public CObject
{
public:
int RemoteFileMng(char* ip,UINT uiPort);
UIShell();
virtual ~UIShell();
};
int UIShell::RemoteFileMng(char* ip,UINT uiPort)
{
DLLDlg dlg;
return dlg.RemoteFileMng(ip,uiPort);
}
DLL导出的函数为:
int RemoteFileMng(char* ip,UINT uiPort)
{
UIShell shell;
return shell.RemoteFileMng(ip,uiPort);
}
也就是通过一层导出类的封装,通过DLL导出函数RemoteFileMng就可以打开对话框。
而对话框的初始化如BOOL DLLDlg::OnInitDialog()
{
CDialog::OnInitDialog();
。。。
SHFILEINFO sfi;
hImageList = (HIMAGELIST)SHGetFileInfo("",
0,
&sfi,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
//m_ListLeft.SendMessage( LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)hImageList);
//m_ListRight.SendMessage( LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)hImageList);
pCImgList = new CImageList;
pCImgList = CImageList::FromHandle(hImageList);
m_ListLeft.SetImageList(pCImgList,LVSIL_SMALL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/**********************************************************/
代码如上,为什么对话框第1次被某界面程序打开能成功出现图标,而后再打开就不行了,一定要重新运行界面程序重新再次打开对话框才行。