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就提示缺少参数 展开
//头文件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就提示缺少参数 展开
1个回答
展开全部
参数不止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);
}
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指针?
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询