VC++的MFC中“CWnd::Create”: 函数不接受 2 个参数,代码如下

程序目的:显示一个空白窗口,视频教程中的执行效果如下//头文件MyApp.h#include<afxwin.h>classMyApp:publicCWinApp{publ... 程序目的:显示一个空白窗口,视频教程中的执行效果如下

//头文件MyApp.h
#include<afxwin.h>
class MyApp :public CWinApp
{
public:
BOOL InitInstance()
{
//创建框架窗口CFrameWnd对象,并用CWinApp内置的指针m_pMainWnd指向它
CFrameWnd*f = new CFrameWnd();
this->m_pMainWnd = f;

//创建窗口
m_pMainWnd->Create(NULL, TEXT("Hello,这是我的第二个MFC")); //这里发生错误
m_pMainWnd->ShowWindow(SW_SHOW);
return true;
}
};

//源文件helloMFC.cpp
#include"MyApp.h"
MyApp app;

错误发生在头文件倒数第五行。
m_pMainWnd->Create(NULL, TEXT("Hello,这是我的第二个MFC"));
我换成p->Create(NULL, TEXT("Hello,这是我的第二个MFC"));就执行正确,不会提示缺少参数
但是p和m_pMainWnd所指向的都是同一个框架窗口对象啊,为什么用m_pMainWnd就提示缺少参数
展开
 我来答
_0x1F1E5E10
推荐于2016-03-06 · TA获得超过295个赞
知道小有建树答主
回答量:293
采纳率:50%
帮助的人:312万
展开全部
参数不止2个 亲
CWnd::Create

virtual BOOL Create( LPCTSTR
lpszClassName, LPCTSTR lpszWindowName,
DWORD dwStyle, const RECT&
rect, CWnd* pParentWnd, UINT
nID, CCreateContext* pContext = NULL);

Return Value

Nonzero if successful; otherwise 0.

Parameters

lpszClassName

Points to a null-terminated character string that names the
Windows class (a WNDCLASS structure). The class name can be any name
registered with the global AfxRegisterWndClass function or any of the
predefined control-class names. If NULL, uses the default CWnd
attributes.

lpszWindowName

Points to a null-terminated character string that contains the
window name.

dwStyle

Specifies the window style
attributes. WS_POPUP cannot be used. If you wish to create a pop-up
window, use CWnd::CreateEx
instead.

rect

The size and position of the window, in client coordinates of
pParentWnd.

pParentWnd

The parent window.

nID

The ID of the child window.

pContext

The create context of the window.

Remarks

Creates a Windows child window and attaches it to the CWnd object.

You construct a child window in two steps. First, call the constructor, which
constructs the CWnd object. Then call Create, which creates the
Windows child window and attaches it to CWnd. Create initializes
the window’s class name and window name and registers values for its style,
parent, and ID.

Example
// Dynamically create static control using CWnd::Create,
// instead of with CStatic::Create, which doesn't
// need the "STATIC" class name.

void CMyDlg::OnCreateStatic()
{
CWnd* pWnd = new CWnd;
pWnd->Create(_T("STATIC"), "Hi", WS_CHILD | WS_VISIBLE,
CRect(0, 0, 20, 20), this, 1234);
}
追问
p->Create(NULL, TEXT("Hello,这是我的第二个MFC"));是正确的
m_pMainWnd->Create(NULL, TEXT("Hello,这是我的第二个MFC"));就是错误的
而p和m_pMainWnd指向相同的框架窗口,为什么能用p指针却不能用m_pMainWnd指针?
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式