可以先从CStatic派生,然后改动一下,以下是一个例子:
.h文件
(Msg_SRText.h)
#if !defined(AFX_MSG_SRTEXT_H__EF85DC22_7896_4741_B543_5D92350DD54F__INCLUDED_)
#define AFX_MSG_SRTEXT_H__EF85DC22_7896_4741_B543_5D92350DD54F__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Msg_SRText.h : header file
//
#include "UserDefineGram.h"
/////////////////////////////////////////////////////////////////////////////
// CMsg_SRText windowclass CMsg_SRText : public CObject
{
protected: DECLARE_SERIAL(CMsg_SRText)
protected:
public:
MSG_SRTEXT Msg_SRText;//MSG_SRTEXT为自定义的数据类型
public:
CMsg_SRText();
CMsg_SRText(CString Index,UINT message,CString SRText,int STextType=0,int MatchType=0,WPARAM wParam=NULL,LPARAM lParam=NULL);
~CMsg_SRText();
virtual void Serialize(CArchive& ar);
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MSG_SRTEXT_H__EF85DC22_7896_4741_B543_5D92350DD54F__INCLUDED_)
.cpp文件
// Msg_SRText.cpp : implementation file
//#include "stdafx.h"
#include "Msg_SRText.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CMsg_SRText
IMPLEMENT_SERIAL(CMsg_SRText,CObject,1)
CMsg_SRText::CMsg_SRText()
{
Msg_SRText.Index="0";
Msg_SRText.message=WM_USER+0;
Msg_SRText.strSRText="";
Msg_SRText.STextType=0;
Msg_SRText.MatchType=0;
Msg_SRText.wParam=NULL;
Msg_SRText.lParam=NULL;
}CMsg_SRText::~CMsg_SRText()
{
}
CMsg_SRText::CMsg_SRText(CString Index,UINT message,CString SRText,int STextType,int MatchType,WPARAM wParam,LPARAM lParam)
{
Msg_SRText.Index=Index;
Msg_SRText.message=message;
Msg_SRText.strSRText=SRText;
Msg_SRText.STextType=STextType;
Msg_SRText.MatchType=MatchType;
Msg_SRText.wParam=wParam;
Msg_SRText.lParam=lParam;
}void CMsg_SRText::Serialize(CArchive& ar)
{
if(ar.IsStoring())
{
ar<<(UINT)Msg_SRText.message;
ar<<(WPARAM)Msg_SRText.wParam;
ar<<(LPARAM)Msg_SRText.lParam;
ar<<(CString)Msg_SRText.strSRText;
ar<<(int)Msg_SRText.STextType;
ar<<(int)Msg_SRText.MatchType;
}
else
{
UINT message;
ar>>message;
Msg_SRText.message=message;
WPARAM wParam;
ar>>wParam;
Msg_SRText.wParam=wParam;
LPARAM lParam;
ar>>lParam;
Msg_SRText.lParam=lParam;
CString srText;
ar>>srText;
Msg_SRText.strSRText=srText;
int STextType;
ar>>STextType;
Msg_SRText.STextType=STextType;
int MatchType;
ar>>MatchType;
Msg_SRText.MatchType=MatchType;
}
}
.h文件
(Msg_SRText.h)
#if !defined(AFX_MSG_SRTEXT_H__EF85DC22_7896_4741_B543_5D92350DD54F__INCLUDED_)
#define AFX_MSG_SRTEXT_H__EF85DC22_7896_4741_B543_5D92350DD54F__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Msg_SRText.h : header file
//
#include "UserDefineGram.h"
/////////////////////////////////////////////////////////////////////////////
// CMsg_SRText windowclass CMsg_SRText : public CObject
{
protected: DECLARE_SERIAL(CMsg_SRText)
protected:
public:
MSG_SRTEXT Msg_SRText;//MSG_SRTEXT为自定义的数据类型
public:
CMsg_SRText();
CMsg_SRText(CString Index,UINT message,CString SRText,int STextType=0,int MatchType=0,WPARAM wParam=NULL,LPARAM lParam=NULL);
~CMsg_SRText();
virtual void Serialize(CArchive& ar);
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MSG_SRTEXT_H__EF85DC22_7896_4741_B543_5D92350DD54F__INCLUDED_)
.cpp文件
// Msg_SRText.cpp : implementation file
//#include "stdafx.h"
#include "Msg_SRText.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CMsg_SRText
IMPLEMENT_SERIAL(CMsg_SRText,CObject,1)
CMsg_SRText::CMsg_SRText()
{
Msg_SRText.Index="0";
Msg_SRText.message=WM_USER+0;
Msg_SRText.strSRText="";
Msg_SRText.STextType=0;
Msg_SRText.MatchType=0;
Msg_SRText.wParam=NULL;
Msg_SRText.lParam=NULL;
}CMsg_SRText::~CMsg_SRText()
{
}
CMsg_SRText::CMsg_SRText(CString Index,UINT message,CString SRText,int STextType,int MatchType,WPARAM wParam,LPARAM lParam)
{
Msg_SRText.Index=Index;
Msg_SRText.message=message;
Msg_SRText.strSRText=SRText;
Msg_SRText.STextType=STextType;
Msg_SRText.MatchType=MatchType;
Msg_SRText.wParam=wParam;
Msg_SRText.lParam=lParam;
}void CMsg_SRText::Serialize(CArchive& ar)
{
if(ar.IsStoring())
{
ar<<(UINT)Msg_SRText.message;
ar<<(WPARAM)Msg_SRText.wParam;
ar<<(LPARAM)Msg_SRText.lParam;
ar<<(CString)Msg_SRText.strSRText;
ar<<(int)Msg_SRText.STextType;
ar<<(int)Msg_SRText.MatchType;
}
else
{
UINT message;
ar>>message;
Msg_SRText.message=message;
WPARAM wParam;
ar>>wParam;
Msg_SRText.wParam=wParam;
LPARAM lParam;
ar>>lParam;
Msg_SRText.lParam=lParam;
CString srText;
ar>>srText;
Msg_SRText.strSRText=srText;
int STextType;
ar>>STextType;
Msg_SRText.STextType=STextType;
int MatchType;
ar>>MatchType;
Msg_SRText.MatchType=MatchType;
}
}
解决方案 »
- 多视图显示问题,创建一个类似于VC++6.0那种左边有个工作列表的窗口(求高手指点,不甚感激!)
- ADO删除字段及数据转移问题
- 保留System menu样式的标题栏重绘问题!!求救高人!!!!
- 如何在VC中定义变参宏
- 想找一个VC读取dxf格式的源代码和不规则图形的算法?
- 哪位大哥帮帮忙啊!!!!我有7道数据结构的题能帮我做一下吗?救急啊星期天我必须交啊
- 可以帮忙看看以下代码的意思吗??谢谢(高分哦,希望今晚有答案)
- ---怎么样从一个文件路径中得到LPSHELLFOLDER和LPITEMIDLIST---
- 难道没人知道com+的问题???
- 请教高手如何用VC++实现这样的系统
- 如何用ADO调用有返回值的存储过程?
- 神啊救救我吧"mstcpip.h"、"iphlpapi.h"
我上面写的类就是用MFC的ClasswIzard生成的(基于CStatic),然后做了小
的修改,用于序列化(Serialize)
class CMsg_SRText : public CObject, 然后把那些函数全部改成自己的?
还有没有更直接简单的方法?
为什么不能直接从CObject派生呢?