WEB开发网
开发学院软件开发VC VC精华教程:MFC入门系列(三) 阅读

VC精华教程:MFC入门系列(三)

 2007-03-22 21:31:32 来源:WEB开发网   
核心提示: lpszMenuNameIdentifies the name of the menu resource to be used with the window. Use MAKEINTRESOURCE if the menu has an integer ID instead of a s

lpszMenuName

Identifies the name of the menu resource to be used with the window. Use MAKEINTRESOURCE if the menu has an integer ID instead of a string. This parameter can be NULL.

我们看到我们要使用MAKEINTRESOURCE这个宏来包装我们的菜单ID,其他的参数我们用默认的。

Create(NULL,"MFC Window",WS_OVERLAPPEDWINDOW,rectDefault,NULL,MAKEINTRESOURCE(IDR_MENU1),0,NULL);

不要忘记在前面加上#include "resource.h",在运行程序就会发现菜单。全部程序如下(不包括资源文件)

#include <afxwin.h>
#include "resource.h"
class sample:public CFrameWnd
{
public:
 
sample()
 
{
 
Create(NULL,"MFC Window",WS_OVERLAPPEDWINDOW,rectDefault,NULL,MAKEINTRESOURCE(IDR_MENU1),0,NULL);
 
MessageBox("My MFC Window","CFrame constructor",MB_OK);
 
}
 
void OnLButtonDown(UINT,CPoint)//添加的消息处理函数
 
{
::MessageBox(NULL,"ddd","dd",MB_OK);
 
}
 
DECLARE_MESSAGE_MAP()//消息映射的申明
};
BEGIN_MESSAGE_MAP(sample,CFrameWnd)
//这个宏填写两个参数,一个子类,一个父类
 
ON_WM_LBUTTONDOWN()//左键按下的事件
END_MESSAGE_MAP()//结束宏
class App:public CWinApp
{
public:
BOOL InitInstance();
BOOL ExitInstance();
};
BOOL App::InitInstance()
{
MessageBox(0,"My MFC Window","InitInstance",MB_OK|MB_ICONASTERISK);
sample *obj;
obj=new sample;
m_pMainWnd=obj;
obj->ShowWindow(SW_SHOWMAXIMIZED);
return TRUE;
}
BOOL App::ExitInstance()
{
MessageBox(0,"My Window","ExitInstance",MB_OK|MB_ICONHAND);
return TRUE;
}
App a;

我们这一节用菜单为例子,讲解了资源文件,以及填写参数的方法,下一节再见。

上一页  1 2 3 

Tags:VC 精华 教程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接