65.9K
CodeProject 正在变化。 阅读更多。
Home

CodeWizard--一个自动生成 C++ 代码文件的可视化工具!

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.36/5 (14投票s)

2003年10月24日

2分钟阅读

viewsIcon

45083

downloadIcon

1327

CodeWizard 包括一个工具,让你可以直观地在屏幕上创建功能并自动生成 C++ 代码文件!

引言

CodeWizard 1.0 版本包含一系列工具,允许您在屏幕上可视化地创建功能,并自动生成 C++ 代码文件! 目前它仅包含一个可以从 CObject 类生成源代码的工具,但这并不是终点。 我将添加许多新的代码向导,帮助您从 ODBC API、MFC ODBC 或其他类生成源代码。 为了让您了解它的工作原理,所有源代码都包含在 zip 文件中,您可以自由修改。 如果您对这个工具有任何好的想法,请告知

以下是 CObject 代码生成器

使用代码生成器

  1. 选择“主工具|&1 生成基于 CObject 的源代码...”菜单项,将出现一个设置对话框。
  2. 在第一个编辑框中输入正确的类名,然后您可以输入作者姓名和该类的描述。
  3. 单击“添加”按钮以添加任意数量的变量,所有变量都将列在列表框中。
  4. 双击列表框中的选定项目,将出现一个编辑对话框。 现在您可以输入新的基本变量名。(提示:只需要变量名的基本名称,例如:如果基本名称是 Text,系统应该将其转换为 m_strTextID_PROPERTY_TEXTGetTextSetText,并且您不能在名称中输入任何空字符。)目前它仅支持以下类型
    enum FO_VALUETYPE
    {
    V_EMPTY = -1,
    V_BOOL, // BOOL value type.
    
    V_STRING, // String value type
    
    V_INT, // int value type
    
    V_FLOAT, // float value type
    
    V_DOUBLE, // double value type
    
    V_DWORD, // DWORD value type
    
    V_DATETIME, // COleDateTime value type
    
    V_COLOR // COLORREF value type.
    
    };
  5. 单击“生成代码”按钮以生成源文件和头文件。

以下是源代码头文件的详细信息

#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 // _MSC_VER > 1000


//------------------------------------------------------

// Description

// Author: Author name.

//------------------------------------------------------


#include "FO_VALUE.h"


/////////////////////////////////////////////////////////////

// Property IDs define.


#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)

// Construction/Destruction

public:

    // Constructor with ID.

    CMyObject();

    // Copy constructor. 

    CMyObject(const CMyObject& newObject);

    // Destructor. 

    virtual ~CMyObject();

    // Put value.

    virtual BOOL PutValue(const int &nPropId,const FO_VALUE &Value);

    // Get value.

    virtual BOOL GetValue(FO_VALUE &Value,const int &nPropId);

    // Create a copy of current object.

    virtual CObject* Copy();

public:

    // Return Title value.

    CString GetTitle() const { return m_strTitle;}

    // Change Title value.

    void SetTitle( const CString &strValue ) {m_strTitle = strValue; }

    // Return Number value.

    int GetNumber() const { return m_nNumber;}

    // Change Number value.

    void SetNumber( const int &nValue ) {m_nNumber = nValue; }

    // Return Math value.

    float GetMath() const { return m_fMath;}

    // Change Math value.

    void SetMath( const float &fValue ) {m_fMath = fValue; }

    // Return Geo value.

    float GetGeo() const { return m_fGeo;}

    // Change Geo value.

    void SetGeo( const float &fValue ) {m_fGeo = fValue; }

    // Return Under60 value.

    BOOL GetUnder60() const { return m_bUnder60;}

    // Change Under60 value.

    void SetUnder60( const BOOL &bValue ) {m_bUnder60 = bValue; }

    // Return Memo value.

    CString GetMemo() const { return m_strMemo;}

    // Change Memo value.

    void SetMemo( const CString &strValue ) {m_strMemo = strValue; }

    // Return StartTime value.

    COleDateTime GetStartTime() const { return m_dtStartTime;}

    // Change StartTime value.

    void SetStartTime( const COleDateTime &dtValue ) 
        {m_dtStartTime = dtValue; }

// Attributes

protected:
    // FODO:Add your properties items below.

    // Title value.

    CString                           m_strTitle;

    // Number value.

    int                               m_nNumber;

    // Math value.

    float                             m_fMath;

    // Geo value.

    float                             m_fGeo;

    // Under60 value.

    BOOL                              m_bUnder60;

    // Memo value.

    CString                           m_strMemo;

    // StartTime value.

    COleDateTime                      m_dtStartTime;


public:

    // Sets this set of font properties equal to another. 

    CMyObject& operator=(const CMyObject& newObject);

    // Is equal.

    virtual BOOL IsEqual(CObject* prop);

    // Determines if another set of fill properties is equal to this one. 

    BOOL operator==(const CMyObject newObject) const;

    // Serialize data to file. 

    virtual void Serialize(CArchive& ar);

// Implementation

public:

#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif

};

inline CObject* CMyObject::Copy()
{
    return new CMyObject(*this);
}


#endif 
// !defined(UFC_MYOBJECT_H__8F58549C_BAD3_4FE7_AE14_8C07BCD16A98__INCLUDED_)

以下是源代码文件的源代码

// MyObject.cpp : Defines the class behaviors for the application.

//


#include "stdafx.h"

#include "MyObject.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

/////////////////////////////////////////////////////////////////////////////

// CMyObject construction/destruction


IMPLEMENT_SERIAL(CMyObject, CObject,1)

// CMyObject | CMyObject | Constructor.


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;
}

// Destructor.

CMyObject::~CMyObject()
{
}

//The property to copy.

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;
}

////////////////////////////////////////////////////////////////////////////

// CMyObject serialization

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;

    }
}


/////////////////////////////////////////////////////////////////////////////

// CMyObject diagnostics


#ifdef _DEBUG
void CMyObject::AssertValid() const
{
    CObject::AssertValid();
}

void CMyObject::Dump(CDumpContext& dc) const
{
    CObject::Dump(dc);
}
#endif //_DEBUG


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;
}

就这样。 此工具的所有源代码都包含在 zip 文件中。

要查找此工具的最新版本,请点击 这里

© . All rights reserved.