Introduction
CodeWizard Version 1.0 includes a series of tools that lets you visually create functionality on-screen and automatically generate C++ code files! Currently it only includes a tool that can generate source code from CObject
class, but this is not the end. I will add many new code wizards that will help you generate source code from ODBC API, MFC ODBC or other classes. To make you know how it works, all the source code is included within the zip files, you can modify it freely. If you have any good ideas about this tool, please let me know.
Below is the CObject code generator:
To use the code generator
- Select "Main Tools|&1 Generate Source Code based on CObject..." menu item, a setting dialog will appear.
- Enter a correct class name at the first edit box, then you can enter the author name and the description of this class.
- Click "Add" button to add as many variables as you want, all the variables will be listed within the list box.
- Double click on the select item of the list box, an edit dialog box will appear. You can now enter the new basic variable name. (Tip: Only the basic name of the variable name is needed, for example: if the basic name is
Text
, it should be converted to m_strText
, ID_PROPERTY_TEXT
, GetText
and SetText
by system, and you can't enter any empty char within the name.) Currently it only support the following types: enum FO_VALUETYPE
{
V_EMPTY = -1,
V_BOOL,
V_STRING,
V_INT,
V_FLOAT,
V_DOUBLE,
V_DWORD,
V_DATETIME,
V_COLOR
};
- Click the "Gen Code" button to generate the source file and header file.
Below is the details of the source code header file:
#if !defined(FO_MYOBJECT_H__8F58549C_BAD3_4FE7_AE14_8C07BCD16A98__INCLUDED_)
#define UFC_MYOBJECT_H__8F58549C_BAD3_4FE7_AE14_8C07BCD16A98__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif
#include "FO_VALUE.h"
#define ID_PROP_TITLE 7000
#define ID_PROP_NUMBER 7001
#define ID_PROP_MATH 7002
#define ID_PROP_GEO 7003
#define ID_PROP_UNDER60 7004
#define ID_PROP_MEMO 7005
#define ID_PROP_STARTTIME 7006
class CMyObject : public CObject
{
DECLARE_SERIAL(CMyObject)
public:
CMyObject();
CMyObject(const CMyObject& newObject);
virtual ~CMyObject();
virtual BOOL PutValue(const int &nPropId,const FO_VALUE &Value);
virtual BOOL GetValue(FO_VALUE &Value,const int &nPropId);
virtual CObject* Copy();
public:
CString GetTitle() const { return m_strTitle;}
void SetTitle( const CString &strValue ) {m_strTitle = strValue; }
int GetNumber() const { return m_nNumber;}
void SetNumber( const int &nValue ) {m_nNumber = nValue; }
float GetMath() const { return m_fMath;}
void SetMath( const float &fValue ) {m_fMath = fValue; }
float GetGeo() const { return m_fGeo;}
void SetGeo( const float &fValue ) {m_fGeo = fValue; }
BOOL GetUnder60() const { return m_bUnder60;}
void SetUnder60( const BOOL &bValue ) {m_bUnder60 = bValue; }
CString GetMemo() const { return m_strMemo;}
void SetMemo( const CString &strValue ) {m_strMemo = strValue; }
COleDateTime GetStartTime() const { return m_dtStartTime;}
void SetStartTime( const COleDateTime &dtValue )
{m_dtStartTime = dtValue; }
protected:
CString m_strTitle;
int m_nNumber;
float m_fMath;
float m_fGeo;
BOOL m_bUnder60;
CString m_strMemo;
COleDateTime m_dtStartTime;
public:
CMyObject& operator=(const CMyObject& newObject);
virtual BOOL IsEqual(CObject* prop);
BOOL operator==(const CMyObject newObject) const;
virtual void Serialize(CArchive& ar);
public:
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};
inline CObject* CMyObject::Copy()
{
return new CMyObject(*this);
}
#endif
Below is the source code of the source code file:
#include "stdafx.h"
#include "MyObject.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CMyObject, CObject,1)
CMyObject::CMyObject() : CObject()
{
m_strTitle = _T("");
m_nNumber = 0;
m_fMath = 0.0f;
m_fGeo = 0.0f;
m_bUnder60 = TRUE;
m_strMemo = _T("");
m_dtStartTime = COleDateTime::GetCurrentTime();
}
CMyObject::CMyObject(const CMyObject& newObject)
{
m_strTitle = newObject.m_strTitle;
m_nNumber = newObject.m_nNumber;
m_fMath = newObject.m_fMath;
m_fGeo = newObject.m_fGeo;
m_bUnder60 = newObject.m_bUnder60;
m_strMemo = newObject.m_strMemo;
m_dtStartTime = newObject.m_dtStartTime;
}
CMyObject::~CMyObject()
{
}
CMyObject& CMyObject::operator=(const CMyObject& newObject)
{
m_strTitle = newObject.m_strTitle;
m_nNumber = newObject.m_nNumber;
m_fMath = newObject.m_fMath;
m_fGeo = newObject.m_fGeo;
m_bUnder60 = newObject.m_bUnder60;
m_strMemo = newObject.m_strMemo;
m_dtStartTime = newObject.m_dtStartTime;
return *this;
}
BOOL CMyObject::IsEqual(CObject* prop)
{
CMyObject* pProp = (CMyObject*)prop;
if (pProp)
return (*this == *pProp);
return FALSE;
}
BOOL CMyObject::operator==(const CMyObject newObject) const
{
if(
GetTitle() == newObject.GetTitle() &&
GetNumber() == newObject.GetNumber() &&
GetMath() == newObject.GetMath() &&
GetGeo() == newObject.GetGeo() &&
GetUnder60() == newObject.GetUnder60() &&
GetMemo() == newObject.GetMemo() &&
GetStartTime() == newObject.GetStartTime() )
{
return TRUE;
}
return FALSE;
}
void CMyObject::Serialize(CArchive& ar)
{
CObject::Serialize(ar);
if (ar.IsStoring())
{
ar << m_strTitle;
ar << m_nNumber;
ar << m_fMath;
ar << m_fGeo;
ar << m_bUnder60;
ar << m_strMemo;
ar << m_dtStartTime;
}
else
{
ar >> m_strTitle;
ar >> m_nNumber;
ar >> m_fMath;
ar >> m_fGeo;
ar >> m_bUnder60;
ar >> m_strMemo;
ar >> m_dtStartTime;
}
}
#ifdef _DEBUG
void CMyObject::AssertValid() const
{
CObject::AssertValid();
}
void CMyObject::Dump(CDumpContext& dc) const
{
CObject::Dump(dc);
}
#endif
BOOL CMyObject::PutValue(const int &nPropId,const FO_VALUE &value)
{
BOOL bReturn = TRUE;
switch(nPropId)
{
case ID_PROP_TITLE:
{
SetTitle(value.m_strValue);
}
break;
case ID_PROP_NUMBER:
{
SetNumber(value.m_nValue);
}
break;
case ID_PROP_MATH:
{
SetMath(value.m_fValue);
}
break;
case ID_PROP_GEO:
{
SetGeo(value.m_fValue);
}
break;
case ID_PROP_UNDER60:
{
SetUnder60(value.m_bValue);
}
break;
case ID_PROP_MEMO:
{
SetMemo(value.m_strValue);
}
break;
case ID_PROP_STARTTIME:
{
SetStartTime(value.m_dtValue);
}
break;
default:
{
bReturn = FALSE;
}
break;
}
return bReturn;
}
BOOL CMyObject::GetValue(FO_VALUE &value,const int &nPropId)
{
BOOL bReturn = TRUE;
switch(nPropId)
{
case ID_PROP_TITLE:
{
value.m_nValueType = V_STRING;
value.m_strValue = GetTitle();
}
break;
case ID_PROP_NUMBER:
{
value.m_nValueType = V_INT;
value.m_nValue = GetNumber();
}
break;
case ID_PROP_MATH:
{
value.m_nValueType = V_FLOAT;
value.m_fValue = GetMath();
}
break;
case ID_PROP_GEO:
{
value.m_nValueType = V_FLOAT;
value.m_fValue = GetGeo();
}
break;
case ID_PROP_UNDER60:
{
value.m_nValueType = V_BOOL;
value.m_bValue = GetUnder60();
}
break;
case ID_PROP_MEMO:
{
value.m_nValueType = V_STRING;
value.m_strValue = GetMemo();
}
break;
case ID_PROP_STARTTIME:
{
value.m_nValueType = V_DATETIME;
value.m_dtValue = GetStartTime();
}
break;
default:
{
bReturn = FALSE;
}
break;
}
return bReturn;
}
That's all. All the source code of this tool is included within the zip files.
To find the latest version of this tool, click here!