[译]CodeWizard-自动生成C ++代码文件的可视工具!
By robot-v1.0
本文链接 https://www.kyfws.com/applications/codewizard-a-visual-tool-to-automatically-generate-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2062 个词 阅读量 0[译]CodeWizard-自动生成C ++代码文件的可视工具!
原文地址:https://www.codeproject.com/Articles/5287/CodeWizard-A-visual-tool-to-automatically-generate
原文作者:ucc801
译文由本站 robot-v1.0 翻译
前言
CodeWizard includes a tool that lets you visually create functionality on-screen and automatically generate C++ code files!
CodeWizard包含一个工具,可让您在屏幕上直观地创建功能并自动生成C ++代码文件!
介绍(Introduction)
CodeWizard 1.0版包含一系列工具,可让您在屏幕上直观地创建功能并自动生成C ++代码文件!目前,它仅包含可以从中生成源代码的工具(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
课,但这还没有结束.我将添加许多新的代码向导,这些向导将帮助您从ODBC API,MFC ODBC或其他类生成源代码.为了让您知道它的工作原理,所有源代码都包含在zip文件中,您可以自由对其进行修改.如果您对此工具有任何好的想法,请让(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.)
下面是CObject代码生成器:(Below is the CObject code generator:)
使用代码生成器(To use the code generator)
- 选择"主要工具|&1基于CObject生成源代码…“菜单项,将出现一个设置对话框.(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:) - 单击"通用代码"按钮以生成源文件和头文件.(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 // _MSC_VER > 1000
//------------------------------------------------------
// Description
// Author: Author name.
//------------------------------------------------------
#include <span class="code-string">"FO_VALUE.h"</span>
/////////////////////////////////////////////////////////////
// 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_)
下面是源代码文件的源代码:(Below is the source code of the source code file:)
// MyObject.cpp : Defines the class behaviors for the application.
//
#include <span class="code-string">"stdafx.h"</span>
#include <span class="code-string">"MyObject.h"</span>
#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文件中.(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) !(!)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VC7.0 VC7.1 C++ VC6 WinXP Win2003 Win2K MFC Visual-Studio Dev 新闻 翻译