通过CImageList加载图标 报错

错误代码:

<span style="white-space:pre">			</span><pre name="code" class="cpp"><span style="white-space:pre">			</span>CImageList  m_ProcessImg ;//全局变量  必须声明为全局变量(.h文件中),否则无效

<span style="white-space:pre">			</span>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相关用法 ,以为是我不了解他的其他用法。所以在这个问题上纠结了好久。

正确代码:

<span style="white-space:pre">			</span>CImageList  *m_ProcessImg ;//全局变量  必须声明为全局变量(.h文件中),否则无效

<span style="white-space:pre">			m_ProcessImg =new CImageList();//对CImageList对象进行初始化
<span style="white-space:pre">			</span></span>
<span style="white-space:pre">			HICON hSmallIco=AfxGetApp()->LoadIcon(IDI_ICON1);
<span style="white-space:pre">			</span>m_ProcessImg.Create(16,16, ILC_COLOR32 | ILC_MASK, 2, 2);
<span style="white-space:pre">			</span>m_ProcessImg->Add(hSmallIco);
<span style="white-space:pre">			</span>m_ListCtrl.SetImageList(m_ProcessImg, LVSIL_SMALL);
<span style="white-space:pre">			</span>DestroyIcon(hSmallIco);</span>

就是忘了进行初始化,就是这个简单的一个问题,纠结了我好久,看来要养成好习惯。

时间: 2024-07-29 08:22:56

通过CImageList加载图标 报错的相关文章

python 加载excel报错

from pandas import Series, DataFrame import pandas as pd import numpy as np import os import sys reload(sys) sys.setdefultencoding('utf-8') file1=pd.read_excel('F:/dataanalysis/statistics/PelicanStores.xlsx') Python 加载excel报错: IndexError: list index

kettle登录加载job 报错 Can&#39;t find Job 1

报错原因: Job 1是临时的新建job,我没保存数据库中,或本地文件,所以加载时找不到文件 解决方法: 目录C:\Documents and Settings\Administrator\.kettle\中有个.spoonrc文件 kettle启动会加载.spoonrc文件, 该文件中保存kettle的配置信息,包括启动时要加载哪些文件 删掉对应的 Job 1的键值对就行了,记得要调整相应键值计数. 我的环境中 tabfile1=Job 1 tabfile2=\u5237\u65B0\u5B9

dojo加载树报错

1.错误描述    error loading undefined children.    TypeError:this._arrayOfTopLevelItems is undefied. 2.错误原因 3.解决办法 dojo加载树报错

CentOS重新加载网卡报错 Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/23

重新加载网卡时出现的错误如下: 1 [[email protected] dev]# service network restart 2 Shutting down interface eth0: Device state: 3 (disconnected) 3 [ OK ] 4 Shutting down interface eth1: [ OK ] 5 Shutting down interface eth2: Device state: 3 (disconnected) 6 [ OK ]

加载模块报错:version magic &#39;2.6.32-504.el6.i686 SMP mod_unload 686 &#39; should

在之前我也遇到这个问题,后来我解决了,但是当时没有记录下来,现在又遇到了,害我整了半天,所以现在记录下,供以后参考: 我开始的加载模块的时候报这样的错误: hello: module_layout: kernel tainted. Disabling lock debugging due to kernel taint hello: version magic '2.6.32-504.el6.i686 SMP mod_unload 686 ' should be '2.6.32-504.el6.

Unity3D 5.0版本 加载dll报错, 换用4.5 版本可以正确运行与导出(x86版本)

在Unity3D环境下测试UnityWebCore和awesomium等用来在Unity中显示网页的插件时, 发现总是不能加载dll文件. Win64环境, Unity5.0(64bit) 报错内容如下: Failed to load 'Assets/Plugins/awesomium.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. 网上的回答都是说该d

maven加载ojdbc14报错

问题复现步骤: 1.在pom.xml里面添加ojdbc14的依赖,代码如下: <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc14</artifactId> <version>10.2.0.2</version></dependency> 2.执行mvn install报如下错误: [ERROR] Failed to execute goa

eclipse 加载插件报错 org.eclipse.mylyn.java.tasks

在eclipse 中点按住Ctr 键的时候报以下这个错, The 'org.eclipse.mylyn.java.hyperlink.detector.stack' extension from plug-in 'org.eclipse.mylyn.java.tasks' to the 'org.eclipse.ui.workbench.texteditor.hyperlinkDetectors' extension point failed to load the hyperlink dete

KVM http网络加载镜像报错(mount: wrong fs type, bad option, bad superblock on /dev/loop0)

curl: (23) Failed writing body (7818 != 16384)loop: module loadeddracut-initqueue[579]: mount: wrong fs type, bad option, bad superblock on /dev/loop0dracut-initqueue[579]: missing codepage or helper program, or other errordracut-initqueue[579]: In s