错误代码:
CImageList m_ProcessImg ;//全局变量 必须声明为全局变量(.h文件中),否则无效
HICON hSmallIco=AfxGetApp()->LoadIcon(IDI_ICON1); m_ProcessImg.Create(16,16, ILC_COLOR32 | ILC_MASK, 2, 2); m_ProcessImg。Add(hSmallIco); m_ListCtrl.SetImageList(&m_ProcessImg, LVSIL_SMALL); DestroyIcon(hSmallIco);
上面这段代码当我在一个要响应WM_TIMER消息 在一个OnTimer函数中执行时总报错:
错误提示是:Unhandled exception at 0x55f650ae (mfc100ud.dll) in Meomory17.exe: 0xC0000005: Access violation reading location 0xccccccd0.
同时光标指向:内部文件winctrl2.cpp中的
ASSERT(m_hImageList == NULL); // only attach once, detach on destroy
ASSERT(FromHandlePermanent(hImageList) == NULL); 看到错误时想过对CImageList 对象进行初始化 可没有成功,还有就是初次接触CImageList相关用法 ,以为是我不了解他的其他用法。所以在这个问题上纠结了好久。
正确代码:
CImageList *m_ProcessImg ;//全局变量 必须声明为全局变量(.h文件中),否则无效
m_ProcessImg =new CImageList();//对CImageList对象进行初始化
HICON hSmallIco=AfxGetApp()->LoadIcon(IDI_ICON1); m_ProcessImg.Create(16,16, ILC_COLOR32 | ILC_MASK, 2, 2); m_ProcessImg->Add(hSmallIco); m_ListCtrl.SetImageList(m_ProcessImg, LVSIL_SMALL); DestroyIcon(hSmallIco);
就是忘了进行初始化,就是这个简单的一个问题,纠结了我好久,看来要养成好习惯。 版权声明:本文为博主原创文章,未经博主允许不得转载。