-------------
Sample01.h
class CSample01App:public CWinApp
{
public :
virtual BOOL InitInstance();};class CSample01Frame:public CFrameWnd
{
public :
CSampele01Frame();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};---------------------
Sample01.cpp
#include<afxwin.h>
#include"Sample01.h"CSample01App theApp;
BOOL CSample01App::InitInstance()
{
m_pMainWnd=new CSample01Frame();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}BEGIN_MESSAGE_MAP(CSample01Frame,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()CSample01Frame::CSampele01Frame()
{
Create(NULL,"MFC应用程序框架");
}void CSample01Frame::OnPaint ()
{
CPaintDC dc(this);
dc.TextOut(100,100,"Hello World!");
}
Sample01.h
class CSample01App:public CWinApp
{
public :
virtual BOOL InitInstance();};class CSample01Frame:public CFrameWnd
{
public :
CSampele01Frame();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};---------------------
Sample01.cpp
#include<afxwin.h>
#include"Sample01.h"CSample01App theApp;
BOOL CSample01App::InitInstance()
{
m_pMainWnd=new CSample01Frame();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}BEGIN_MESSAGE_MAP(CSample01Frame,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()CSample01Frame::CSampele01Frame()
{
Create(NULL,"MFC应用程序框架");
}void CSample01Frame::OnPaint ()
{
CPaintDC dc(this);
dc.TextOut(100,100,"Hello World!");
}
解决方案 »
- vc对话框中添加 视图 带滚动条 实现大图像的显示
- vc编程如何把一个word的内容插入另外一个word的指定位置?
- IPicture::Render方法参数问题
- (急)高分求教:Tab控件的闪烁问题
- 求做聊天网站方面的高手
- PROCESS_MEMORY_COUNTERS类的成员变量中文都是什么意思啊?
- 创建字体的问题?谢谢!!
- VC中类 变量个数问题
- 在MFC中出现libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main错误的可能有几种,如何解决?
- 各位大哥,小弟请教一个问题,在一个对话框中采用一个CStaic控件,在该控件中由下而上以滚动方式显示一段文本信息,如有源代码或demo敬请附上,本人不胜感激
- 在继承CObject和CWnd类的自定义类中如何加入消息映射ON_WM_TIMER()
- EOF和BOF有一个为真的老问题了!
Create(NULL,"MFC应用程序框架");
Constructs a CWnd object.The Windows window is not created and attached until the CreateEx or Create member function is called.
也就是说,调用CWnd()并不能真正的创建对话框。Returns m_hWnd, or NULL if the this pointer is NULL.
HWND GetSafeHwnd( ) const;
Return Value
Returns the window handle for a window. Returns NULL if the CWnd is not attached to a window or if it is used with a NULL CWnd pointer.
这个是对m_hWnd的解释。
也就是说如果没有调用CreateEx,那么m_hWnd始终是NULL,所以没有办法使用。
m_pMainWnd=new CSample01Frame();
m_pMainWnd->Create(NULL,"MFC应用程序框架");
m_pMainWnd- >ShowWindow(m_nCmdShow);
m_pMainWnd- >UpdateWindow();
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.也就是说必须是先调用了constructor,而LZ的Create(NULL,"MFC应用程序框架")方法就在constructor中,这种
逻辑肯定是错了。
m_pMainWnd=new CSample01Frame();
不是就在创建一个窗体吗?我先做个测试试试re:3 楼:单纯的这样是不行的:
m_pMainWnd=new CSample01Frame();
m_pMainWnd- >Create(NULL,"MFC应用程序框架");
m_pMainWnd- >ShowWindow(m_nCmdShow);
m_pMainWnd- >UpdateWindow();
原来是在CFrameWnd里 调用Create,他只接受两个参数,其他均默认即可,但是现在用m_pMainWnd调用的话就
相当于在CWnd里的Create函数,这里不能那么多的缺省参数。
m_pMainWnd=new CSample01Frame();
m_pMainWnd->Create("abc","zhangyanli",WS_OVERLAPPEDWINDOW,CRect(0,0,100,200),NULL,0);
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();还是不行,急哭了 都......
帮帮忙啊!!!!
你们怎么学的mfc 啊
class CSample01Frame:public CFrameWnd
{
public :
CSampele01Frame();//注意这里啊,仔细看
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
((CSample01Frame*)m_pMainWnd)->Create(NULL, "MFC应用程序框架");
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE; 不要在构造函数中调用Create
但绝对不是在诚心捣鬼,抱歉抱歉.也谢谢楼上的几位.另外,to:shanhqk:
首先谢谢你,在我的构造函数中是可以用Create的,其实在这里并不是真正的调用MFC,而是我们自己调用MFC框架里的一些函数
然后自己封装的类,而在MFC框架里可能是你说的那样Create不能放在constructor里.是该好好自己检讨一下了,呵呵,,,