vs2010最简单的MFC窗口程序

在Visual Studio中创建一个新的空Win32工程,配置属性--常规---在静态库中使用 MFC

内容如下:

1.h

#ifndef MFCTEST_HEAD
#define MFCTEST_HEAD
#pragma once

#include <afxwin.h>
#include <afxframewndex.h>

#define IDC_START   1012            //按钮定义


class CMyApp:public CWinApp
{
public:
	//构造函数
	CMyApp();
	//析构函数
	virtual ~CMyApp();

	//重载函数
public:
	//初始函数
	virtual BOOL InitInstance();
};



class CMyWindow : public CFrameWndEx
{
public:
	//构造函数
	CMyWindow();
	//析构函数
	virtual ~CMyWindow();

	//虚函数
public:
	//命令响应消息
	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
	
	//消息映射
public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	DECLARE_MESSAGE_MAP()
public:
	CButton       m_button;       //按钮

};



#endif


 

1.cpp

#include "1.h"

CMyApp myapp;

//构造函数
CMyApp::CMyApp()
{

}

//析构函数
CMyApp::~CMyApp()
{

}

//初始函数
BOOL CMyApp::InitInstance()
{
	m_pMainWnd = new CMyWindow();
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	return TRUE;
}



BEGIN_MESSAGE_MAP(CMyWindow, CFrameWndEx)
	ON_WM_CREATE()
END_MESSAGE_MAP()

//构造函数
CMyWindow::CMyWindow()
{
	Create(NULL, TEXT("My Window"));
}
//析构函数
CMyWindow::~CMyWindow()
{
}

//命令响应消息
BOOL CMyWindow::OnCommand( WPARAM wParam, LPARAM lParam )
{
	int wmId=LOWORD(wParam);
	switch (wmId)
	{
	case IDC_START:
		{
			MessageBox(TEXT("测试一下哈"),TEXT("提示"),MB_OK);
			return true;
		}
		break;
	default:
		return true;
	}

	return __super::OnCommand(wParam,lParam);

}

//创建事件
int CMyWindow::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
	__super::OnCreate(lpCreateStruct);

	//居中窗口
	SetActiveWindow();
	SetForegroundWindow();
	CenterWindow(GetParent());

	//创建按钮
	RECT rect={0,0,50,30};
	m_button.Create(TEXT("按钮"),WS_CHILD|WS_VISIBLE,rect,this,IDC_START);

	return true;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值