MFC-菜单

MFC-菜单

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

创建菜单-方式1:

#include <afxwin.h>
#include "resource.h"
class MyFrameWnd :public CFrameWnd {
};

class MyWinApp :public CWinApp {
public:
	MyWinApp() {

	}
	virtual BOOL InitInstance() {

	MyFrameWnd* pFrame	= new MyFrameWnd;
	// 挂菜单
	pFrame->Create(NULL,"Test",WS_OVERLAPPEDWINDOW,CFrameWnd::rectDefault,NULL,
		          (CHAR*)IDR_MENU1);
	m_pMainWnd = pFrame;
	pFrame->ShowWindow(SW_SHOW);
	pFrame->UpdateWindow();
	return TRUE;
	}
};

MyWinApp mainApp;

在这里插入图片描述

创建菜单-方式2:

#include <afxwin.h>
#include "resource.h"
class MyFrameWnd :public CFrameWnd {
	// 类内声明宏
	DECLARE_MESSAGE_MAP()
public:
	int OnCreate(LPCREATESTRUCT pcs);
	CMenu menu;
};

// 类外实现宏
BEGIN_MESSAGE_MAP(MyFrameWnd, CFrameWnd)
	ON_WM_CREATE()
END_MESSAGE_MAP()

int MyFrameWnd::OnCreate(LPCREATESTRUCT pcs) {
	menu.LoadMenuA(IDR_MENU1);
	this->SetMenu(&menu);
	return CFrameWnd::OnCreate(pcs);
}


class MyWinApp :public CWinApp {
public:
	MyWinApp() {

	}
	virtual BOOL InitInstance() {

		MyFrameWnd* pFrame = new MyFrameWnd;
		pFrame->Create(NULL, "Test");
		m_pMainWnd = pFrame;
		pFrame->ShowWindow(SW_SHOW);
		pFrame->UpdateWindow();
		return TRUE;
	}
};

MyWinApp mainApp;

在这里插入图片描述

处理消息

在这里插入图片描述

#include <afxwin.h>
#include "resource.h"
class MyFrameWnd :public CFrameWnd {
	// 类内声明宏
	DECLARE_MESSAGE_MAP()
public:
	afx_msg int OnCreate(LPCREATESTRUCT pcs);
	afx_msg void OnNew();
public:
	CMenu menu;
};

// 类外实现宏
BEGIN_MESSAGE_MAP(MyFrameWnd, CFrameWnd)
	ON_WM_CREATE()
	ON_COMMAND(Create_NewFile,OnNew)
END_MESSAGE_MAP()

void MyFrameWnd::OnNew() {
	AfxMessageBox("新建");
}



int MyFrameWnd::OnCreate(LPCREATESTRUCT pcs) {
	menu.LoadMenuA(IDR_MENU1);
	this->SetMenu(&menu);
	// ::SetMenu(this->m_hWnd,menu.m_hMenu);
	return CFrameWnd::OnCreate(pcs);
}


class MyWinApp :public CWinApp {
public:
	MyWinApp() {

	}
	virtual BOOL InitInstance() {

		MyFrameWnd* pFrame = new MyFrameWnd;
		pFrame->Create(NULL, "Test");
		m_pMainWnd = pFrame;
		pFrame->ShowWindow(SW_SHOW);
		pFrame->UpdateWindow();
		return TRUE;
	}
};

MyWinApp mainApp;

在这里插入图片描述

消息处理顺序

#include <afxwin.h>
#include "resource.h"
class MyFrameWnd :public CFrameWnd {
	// 类内声明宏
	DECLARE_MESSAGE_MAP()
public:
	afx_msg int OnCreate(LPCREATESTRUCT pcs);
	afx_msg void OnNew();
public:
	CMenu menu;
};

// 类外实现宏
BEGIN_MESSAGE_MAP(MyFrameWnd, CFrameWnd)
	ON_WM_CREATE()
	ON_COMMAND(Create_NewFile,OnNew)
END_MESSAGE_MAP()

void MyFrameWnd::OnNew() {
	AfxMessageBox("框架-新建");
}



int MyFrameWnd::OnCreate(LPCREATESTRUCT pcs) {
	menu.LoadMenuA(IDR_MENU1);
	this->SetMenu(&menu);
	// ::SetMenu(this->m_hWnd,menu.m_hMenu);
	return CFrameWnd::OnCreate(pcs);
}


class MyWinApp :public CWinApp {
	DECLARE_MESSAGE_MAP()
public:
	MyWinApp() {

	}
	afx_msg void OnNew();

	virtual BOOL InitInstance() {

		MyFrameWnd* pFrame = new MyFrameWnd;
		pFrame->Create(NULL, "Test");
		m_pMainWnd = pFrame;
		pFrame->ShowWindow(SW_SHOW);
		pFrame->UpdateWindow();
		return TRUE;
	}
};
BEGIN_MESSAGE_MAP(MyWinApp, CWinApp) 
	ON_COMMAND(Create_NewFile, OnNew)
END_MESSAGE_MAP()
void MyWinApp::OnNew() {
	AfxMessageBox("应用程序-新建");
}
MyWinApp mainApp;

在这里插入图片描述

#include <afxwin.h>
#include "resource.h"
class MyFrameWnd :public CFrameWnd {
	// 类内声明宏
	DECLARE_MESSAGE_MAP()
public:
	afx_msg int OnCreate(LPCREATESTRUCT pcs);
	afx_msg void OnNew();
public:
	CMenu menu;
};

// 类外实现宏
BEGIN_MESSAGE_MAP(MyFrameWnd, CFrameWnd)
	ON_WM_CREATE()
	//ON_COMMAND(Create_NewFile,OnNew)
END_MESSAGE_MAP()

void MyFrameWnd::OnNew() {
	AfxMessageBox("框架-新建");
}



int MyFrameWnd::OnCreate(LPCREATESTRUCT pcs) {
	menu.LoadMenuA(IDR_MENU1);
	this->SetMenu(&menu);
	// ::SetMenu(this->m_hWnd,menu.m_hMenu);
	return CFrameWnd::OnCreate(pcs);
}


class MyWinApp :public CWinApp {
	DECLARE_MESSAGE_MAP()
public:
	MyWinApp() {

	}
	afx_msg void OnNew();

	virtual BOOL InitInstance() {

		MyFrameWnd* pFrame = new MyFrameWnd;
		pFrame->Create(NULL, "Test");
		m_pMainWnd = pFrame;
		pFrame->ShowWindow(SW_SHOW);
		pFrame->UpdateWindow();
		return TRUE;
	}
};
BEGIN_MESSAGE_MAP(MyWinApp, CWinApp) 
	ON_COMMAND(Create_NewFile, OnNew)
END_MESSAGE_MAP()
void MyWinApp::OnNew() {
	AfxMessageBox("应用程序-新建");
}
MyWinApp mainApp;

在这里插入图片描述

COMMAND-处理顺序:框架类-》应用程序类


设置菜单项状态

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值