MFC 刚开始接触特别头疼

// CmdMsg.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

class CCmdFrame:public CFrameWnd{
public:
DECLARE_MESSAGE_MAP()
public:
	//OnCreate必须要大写 一模一样 否则显示不出来
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStr);
	afx_msg void OnTest01();
};

BEGIN_MESSAGE_MAP(CCmdFrame,CFrameWnd)
		ON_WM_CREATE()
		//直接给ID号 就像我们那边的SIWCH CASE 1001一样
		ON_COMMAND(1001,OnTest01)
END_MESSAGE_MAP()
void CCmdFrame::OnTest01(){
	AfxMessageBox("按钮点击事件");
}
//OnCreate必须要大写 一模一样 否则显示不出来
int CCmdFrame::OnCreate(LPCREATESTRUCT lpCreateStr)
{

	CreateWindow("BUTTON","BUTTON",WS_CHILD|WS_VISIBLE,
		50,50,200,30,GetSafeHwnd(),(HMENU)1001,AfxGetApp()->m_hInstance,NULL);
	return 1;
}
class CMsgApp: public CWinApp
{
public:
	virtual BOOL InitInstance();
};

CMsgApp theApp;

BOOL CMsgApp::InitInstance()
{
	CCmdFrame *pWnd=new CCmdFrame();
	pWnd->Create(NULL,"CmdMsg");
	m_pMainWnd=pWnd;

	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	return 1;
}


你可能感兴趣的:(MFC 刚开始接触特别头疼)