⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfc.h

📁 MFC的框架
💻 H
字号:
//#define BOOL	int
#define TRUE	1
#define FALSE	0

typedef char *LPSTR;
typedef const char *LPCSTR;

typedef unsigned long DWORD;
typedef int	BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef int INT;
typedef unsigned int UINT;
typedef long LONG;

#define WM_COMMAND		0x0111
#define CObjectid		0xffff
#define CCmdTargetid	1
#define CWinThreadid	11
#define CWinAppid		111
#define CMyWinAppid		1111
#define CWndid			12
#define CFrameWndid		121
#define CMyFrameWndid	1211
#define CViewid			122
#define CMyViewid		1221
#define CDocumentid		13
#define CMyDocid		131

//#define LPCSTR LPSTR
//typedef char *LPSTR;
//#define UINT int
//#define PASCAL _stdcall		//函数的参数自右向左通过栈传递,被调用的函数在返回前清理传送参数的内存栈
//							//C编译时函数名修饰约定规则: 
//							//__stdcall调用约定在输出函数名前加上一个下划线前缀,后面加上一个"@"符号和其参数的字节数,格式为_functionname@number,例如 :function(int a, int b),其修饰名为:_function@8 
//#define TRACE1 printf

#include <iostream>
//#include <stdio.h>
//#include <string.h>
using   namespace   std; 

///////////////////////////////////////////////////////
//	Window message map handling

struct AFX_MSGMAP_ENTRY;		//declared below after CWnd

struct AFX_MSGMAP
{
	AFX_MSGMAP *pBaseMessageMap;
	AFX_MSGMAP_ENTRY *lpEntries;
};

#define DECLARE_MESSAGE_MAP() \
        static AFX_MSGMAP_ENTRY _messageEntries[]; \
        static AFX_MSGMAP messageMap; \
        virtual AFX_MSGMAP* GetMessageMap() const;

#define BEGIN_MESSAGE_MAP(theClass, baseClass) \
        AFX_MSGMAP* theClass::GetMessageMap() const \
                { return &theClass::messageMap; } \
        AFX_MSGMAP theClass::messageMap = \
        { &(baseClass::messageMap), \
                (AFX_MSGMAP_ENTRY*) &(theClass::_messageEntries) }; \
        AFX_MSGMAP_ENTRY theClass::_messageEntries[] = \
        {

#define END_MESSAGE_MAP() \
        { 0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } \
        };

// Message map signature values and macros in separate header
#include <afxmsg_.h>

class CObject
{
	//注意:CObject并不属于信息流动网的一份子
public:
	CObject::CObject() {cout << "CObject Constructor\n";}
	CObject::~CObject(){}
};

class CCmdTarget:public CObject
{
public:
	CCmdTarget::CCmdTarget() {cout << "CCmdTarget Constructor\n";}
	CCmdTarget::~CCmdTarget(){}

	DECLARE_MESSAGE_MAP()       // base class - no {{ }} macros
	//相当于
	//struct AFX_MSGMAP
	//{
	//	AFX_MSGMAP *pBaseMessageMap;
	//	AFX_MSGMAP_ENTRY *lpEntries;
	//};
    //static AFX_MSGMAP_ENTRY _messageEntries[]; \
    //static AFX_MSGMAP messageMap; \
    //virtual AFX_MSGMAP* GetMessageMap() const
	//{ return &CCmdTarget::messageMap}
};

typedef void (CCmdTarget::*AFX_PMSG)(void);

struct AFX_MSGMAP_ENTRY  // MFC 4.0
{
    UINT nMessage; // windows message
    UINT nCode;    // control code or WM_NOTIFY code
    UINT nID;      // control ID (or 0 for windows messages)
    UINT nLastID;  // used for entries specifying a range of control id's
    UINT nSig;     // signature type (action) or pointer to message #
    AFX_PMSG pfn;  // routine to call (or special value)
};

class CWinThread:public CCmdTarget
{
	//注意:CWinThread并不属于信息流动网的一份子
public:
	CWinThread::CWinThread() {cout << "CWinThread Constructor\n";}
	CWinThread::~CWinThread(){}

	virtual BOOL InitInstance()
	{
		cout << "CWinThread::InitInstance \n";
		return TRUE;
	}

	virtual int Run()
	{
		cout << "CWinThread::Run \n";
		return 1;
	}
};

class CWnd;

class CWinApp:public CWinThread
{
public:
	CWinApp *m_pCurrentWinApp;
	CWnd * m_pMainWnd;		//此结构下的classCWnd结构是由DECLARE_DYNCREATE(CWnd)和IMPLEMENT_DYNCREATE(CWnd,CCmdTarget)产生
							//CCmdTarget表示基类
							//[CMyFrameWnd]表示指向的是一个模块化的结构

public:
	CWinApp::CWinApp() { 
							cout << "CWinApp Constructor\n";
							m_pCurrentWinApp = this;
						}
	CWinApp::~CWinApp(){}

	virtual BOOL InitApplication()
	{
		cout << "CWinApp::InitApplication \n";
		return TRUE;
	}

	virtual BOOL InitInstance()
	{
		cout << "CWinApp::InitInstance \n";
		return TRUE;
	}

	virtual int Run()
	{
		cout << "CWinApp::Run \n";
		return CWinThread::Run();
	}
	DECLARE_MESSAGE_MAP()
};

typedef void (CWnd::*AFX_PMSGW)(void);
        // like 'AFX_PMSG' but for CWnd derived classes only

class CDocument:public CCmdTarget
{
public:
	CDocument::CDocument() {cout << "CDocument Constructor\n";}
	CDocument::~CDocument(){}

	DECLARE_MESSAGE_MAP()
};

class CWnd:public CCmdTarget
{
public:
	CWnd::CWnd() {
					cout << "CWnd Constructor\n";
				 }
	CWnd::~CWnd(){}

	virtual BOOL Create();
	BOOL	CreateEx();
	virtual BOOL PreCreateWindow();

	DECLARE_MESSAGE_MAP()
};

class CFrameWnd:public CWnd
{
public:
	CFrameWnd::CFrameWnd() {
								cout << "CFrameWnd Constructor\n";
							}
	CFrameWnd::~CFrameWnd(){}
	BOOL Create();
	virtual BOOL PreCreateWindow();

	DECLARE_MESSAGE_MAP()
};

class CView:public CWnd
{
public:
	CView::CView() {cout << "CView Constructor\n";}
	CView::~CView(){}

	DECLARE_MESSAGE_MAP()
};

//global function
CWinApp *AfxGetApp();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -