首页 > 其他分享 >MFC关键技术之仿真(DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC)

MFC关键技术之仿真(DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC)

时间:2023-08-29 10:07:01浏览次数:35  
标签:MFC name CRuntimeClass DYNAMIC public BOOL IMPLEMENT class


MFC.h
#ifndef __MFC_H_
#define __MFC_H_
#define BOOL int
#define TRUE 1
#define FALSE 0
#define LPCSTR LPSTR
typedef char* LPSTR;
#define UINT int
#define PASCAL _stdcall

#include <iostream>

class CObject;

struct CRuntimeClass {

	LPCSTR m_lpszClassName;
	int m_nObjectSize;
	UINT m_wSchema;
	CObject* (PASCAL* m_pfnCreateObject) ();
	CRuntimeClass* m_pBaseClass;

	static CRuntimeClass* pFirstClass;
	CRuntimeClass* m_pNextClass;
};

struct AFX_CLASSINIT {
	AFX_CLASSINIT(CRuntimeClass* pNewClass);
};


#define RUNTIME_CLASS(class_name) \
	(&class_name::class##class_name)


#define DECLARE_DYNAMIC(class_name) \
	public: \
	static CRuntimeClass class##class_name; \
	virtual CRuntimeClass* GetRuntimeClass() const;


#define _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
	static char _lpsz##class_name[] = #class_name; \
	CRuntimeClass class_name::class##class_name = { \
	_lpsz##class_name, sizeof(class_name), wSchema, pfnNew, \
	RUNTIME_CLASS(base_class_name), NULL}; \
	static AFX_CLASSINIT _init_##class_name(&class_name::class##class_name); \
	CRuntimeClass* class_name::GetRuntimeClass() const \
{ \
	return &class_name::class##class_name; \
}

#define IMPLEMENT_DYNAMIC(class_name, base_class_name) \
	_IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0XFFFF, NULL)

class CObject {
public:
	CObject() {}
	~CObject() {}

	virtual CRuntimeClass* GetRuntimeClass() const;
	static  CRuntimeClass classCObject;
};

class CCmdTarget : public CObject {
	DECLARE_DYNAMIC(CCmdTarget)
public:
	CCmdTarget() {}
	~CCmdTarget() {}
};

class CWinThread : public CCmdTarget {
	DECLARE_DYNAMIC(CWinThread)
public:
	CWinThread() {}
	~CWinThread() {}
	virtual BOOL InitInstance() {
		return TRUE;
	}
	virtual int Run() {
		return 1;
	}
};

class CWnd;

class CWinApp : public CWinThread {
	DECLARE_DYNAMIC(CWinApp)
public:
	CWinApp* m_pCurrentWinApp;
	CWnd* m_pMainWnd;

public:
	CWinApp() {
		m_pCurrentWinApp = this;
	}
	~CWinApp() {}

	virtual BOOL InitApplication() {
		return TRUE;
	}
	virtual BOOL InitInstance() {
		return TRUE;
	}

	virtual int Run() {
		return CWinThread::Run();
	}
};

class CDocument : public CCmdTarget {
	DECLARE_DYNAMIC(CDocument)
public:
	CDocument::CDocument() {

	}
	~CDocument() {}
};

class CWnd : public CCmdTarget {
	DECLARE_DYNAMIC(CWnd)
public:
	CWnd() {}
	~CWnd() {}
	virtual BOOL Create();
	BOOL CreateEx();
	virtual BOOL PreCreateWindow();
};

class CFrameWnd : public CWnd {
	DECLARE_DYNAMIC(CFrameWnd)
public:
	CFrameWnd() {}
	~CFrameWnd() {}
	BOOL Create();
	virtual BOOL PreCreateWindow();
};

class CView : public  CWnd {
	DECLARE_DYNAMIC(CView)
public:
	CView() {}
	~CView() {}
};

CWinApp* AfxGetApp();
#endif
MFC.cpp
#include "my.h"
extern CMyWinApp theApp;


static char szCObject[] = "CObject";
struct CRuntimeClass CObject::classCObject = {
	szCObject, sizeof(CObject), 0xffff, NULL, NULL, NULL};
	static AFX_CLASSINIT _init_CObject(&CObject::classCObject);
	CRuntimeClass* CRuntimeClass::pFirstClass = NULL;




AFX_CLASSINIT::AFX_CLASSINIT(CRuntimeClass* pNewClass) {
	pNewClass->m_pNextClass = CRuntimeClass::pFirstClass;
	CRuntimeClass::pFirstClass = pNewClass;
}


CRuntimeClass* CObject::GetRuntimeClass() const {
	return &CObject::classCObject;
}


BOOL CWnd::Create() {
	return TRUE;
}


BOOL CWnd::CreateEx() {
	PreCreateWindow();
	return TRUE;
}


BOOL CWnd::PreCreateWindow() {
	return TRUE;
}


BOOL CFrameWnd::Create() {
	CreateEx();
	return TRUE;
}


BOOL CFrameWnd::PreCreateWindow() {
	return TRUE;
}


IMPLEMENT_DYNAMIC(CCmdTarget, CObject)
IMPLEMENT_DYNAMIC(CWinThread, CCmdTarget)
IMPLEMENT_DYNAMIC(CWinApp, CWinThread)
IMPLEMENT_DYNAMIC(CWnd, CCmdTarget)
IMPLEMENT_DYNAMIC(CFrameWnd, CWnd)
IMPLEMENT_DYNAMIC(CDocument, CCmdTarget)
IMPLEMENT_DYNAMIC(CView, CWnd)


CWinApp* AfxGetApp() {
	return theApp.m_pCurrentWinApp;
}
MY.h
#ifndef __MY_H_
#define	__MY_H_ 
#include <IOSTREAM>
#include "MFC.H"
using namespace std;
class CMyFrameWnd:public CFrameWnd
{
public:
	CMyFrameWnd();
	~CMyFrameWnd(){}
};


class CMyWinApp:public CWinApp
{
public:
	CMyWinApp(){}
	~CMyWinApp(){}
	virtual BOOL InitInstance();
};


class CMyDocument:public CDocument
{
public:
	CMyDocument(){}
	~CMyDocument(){}
};


class CMyView:public CView
{
public:
	CMyView(){}
	~CMyView(){}
};
void PrintAllClasses();
#endif



MY.cpp
#include "MY.h"


CMyWinApp theApp;


BOOL CMyWinApp::InitInstance() {
	m_pMainWnd = new CMyFrameWnd;
	return TRUE;
}


CMyFrameWnd::CMyFrameWnd() {
	Create();
}


void PrintAllClasses() {
	CRuntimeClass* pClass;


	for(pClass = CRuntimeClass::pFirstClass; pClass != NULL;
		pClass = pClass->m_pNextClass) {
			std::cout << pClass->m_lpszClassName << std::endl;
			std::cout << pClass->m_nObjectSize << std::endl;
			std::cout << pClass->m_wSchema << std::endl;
	}
}


int main() {
	CWinApp* pApp = AfxGetApp();
	pApp->InitApplication();
	pApp->InitInstance();
	pApp->Run();
	PrintAllClasses();
	return 0;
}

标签:MFC,name,CRuntimeClass,DYNAMIC,public,BOOL,IMPLEMENT,class
From: https://blog.51cto.com/u_13566975/7272455

相关文章

  • Dynamic ReLU:根据输入动态确定的ReLU
    这是我最近才看到的一篇论文,它提出了动态ReLU(DynamicReLU,DY-ReLU),可以将全局上下文编码为超函数,并相应地调整分段线性激活函数。与传统的ReLU相比,DY-ReLU的额外计算成本可以忽略不计,但表示能力明显增强,并且实现简单,所以可以非常简单的对我们现有的模型进行修改。DynamicReL......
  • MFC-剪贴板
     复制文本到剪贴板 //**********复制文本到剪贴板**********CStringtext=_T("我是中国人");BOOLb=OpenClipboard();//打开剪贴板/*返回值:如果通过CWnd打开了剪贴板,则返回非零值如果其他应用程序或窗口已经打开......
  • MFC-GetDlgItemText获取指定控件的文本
     TCHARname[256];HWNDhWnd=GetSafeHwnd();intn=::GetDlgItemText(hWnd,IDC_STATIC1,name,254);/*参数1:窗口句柄参数2:控件ID参数3:LPTSTRlpStr,//保存获取的文本的缓冲区参数4:nMaxCount指定了要拷贝到lpStr的字符串的最大......
  • MFC视频教学第一课,做一个简单的界面,理解应用程序和操作系统之间的消息传递机制
     #include<windows.h>#include<stdio.h>LRESULTCALLBACKWinSunProc(HWNDhwnd,UINTuMsg,WPARAMwParam,LPARAMlParam);//WinMain是操作系统调用的,是系统的入口函数intWINAPIWinMain(HINSTANCEhInstance,//当前应运程序......
  • springboot结合baomidou dynamic-datasource组件实现多数据源
    当系统数据量过大,系统性能问题逐渐浮出水面。使用主从模式,不失是一个较好的选择。即业务在主库执行,不影响业务的查询考虑走从库。这时,程序需要动态多数据源配置。......
  • 学习笔记:DSTAGNN: Dynamic Spatial-Temporal Aware Graph Neural Network for Traffic
    DSTAGNN:DynamicSpatial-TemporalAwareGraphNeuralNetworkforTrafficFlowForecastingICML2022论文地址:https://proceedings.mlr.press/v162/lan22a.html代码地址:https://github.com/SYLan2019/DSTAGNN一个用于时空序列预测的交通流量预测模型。可学习的地方:提出......
  • 【刷题笔记】28. Implement strStr()
    题目ImplementstrStr().Returntheindexofthefirstoccurrenceofneedleinhaystack,or-1ifneedleisnotpartofhaystack.Example1:Input:haystack="hello",needle="ll"Output:2Example2:Input:haystack="aaaaa&quo......
  • C# 通过DynamicObject让Dictionary可以通过dynamic进行操作
    测试代码DynamicDictionarydict=newDynamicDictionary();dict.Value["ID"]=1;dict.Value["Name"]="李二";dict.Value["Address"]="李家坡";dynamic......
  • MFC-TeeChart图标控件
    OCX组件下载:链接:https://pan.baidu.com/s/1yOEbV4NBFdkusK_3CilLxA提取码:6666   系统注册下载之后,看安装说明       ......
  • 静态缓存(static Buffer)和动态缓存(dynamic Buffer)
    创建缓存时,如果未使用D3DUSAGE_DYNAMIC,则所创建的缓存为静态缓存(staticBuffer),我们用静态缓存来存储静态数据(那些不需要经常修改或访问的数据),例如,地图和城市建筑的数据,如果使用的动态缓存,动态缓存一般放置在AGP存储区中,其内容可以迅速的更新,动态缓存的一个最大的优点是更新的速度......