程序下载:http://download.csdn.net/detail/panshiqu/5850959
近期编程想用CList维护一个对象,来方便的实现增,删,改,查,里面要放多个元素,想实现这种,就要自己写结构体,或是类。类的话就让他派生自CObject吧,然后接下来会遇到两个问题,我在这里整理一下我在网上寻求的解决方法,文中所写是否是问题的标准解决办法,有待高手指教,我只是发此文章帮助和我一样遇到问题的人,和记录一下自己的学习历程。
接下来我要重现我遇到的问题,再接着写我找到的解决办法
首先看一下MSDN对CList的介绍
// CList is a template class that takes two template arguments.
// The first argument is type stored internally by the list, the
// second argument is the type used in the arguments for the
// CList methods.
// This code defines a list of ints.
CList<int,int> myIntList;
// This code defines a list of CStrings
CList<CString,CString&> myStringList;
// This code defines a list of MYTYPEs,
// NOTE: MYTYPE could be any struct, class or type definition
CList<MYTYPE,MYTYPE&> myTypeList;
新建一个MFC对话框应用程序,添加COnlineInfo类继承CObject,添加两个成员变量,DWORD m_dIPAdress; int m_nCount;
#pragma once
// CObjectInfo 命令目标
class CObjectInfo : public CObject
{
public:
CObjectInfo();
virtual ~CObjectInfo();
DWORD m_dIPAddress;
int m_nCount;
};
在对话框类中OnInitDialog()中添加定时器(SetTimer(1, 5000, NULL);)并响应OnTimer()。注意在dlg类的头文件包含自定义类#include "ObjectInfo.h"
void CTestDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (nIDEvent == 1)