下面的源程序仅仅包括了具备VC基本特点所必须的代码,可是不能通过编译.
"MyApp.h"
*********************************************************
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMyFrame : public CFrameWnd
{
public:
CMyFrame();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
*********************************************************
"MyApp.cpp"
*********************************************************
#include <afxwin.h>
#include "MyApp.h"
CMyApp theApp; //应用程序全局变量
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMyFrame(); //初始化,启动应用程序
m_pMainWnd->ShowWindow(m_nCmdShow); //显示主框架窗口
m_pMainWnd->UpdateWindow();
return TRUE;
}
CMyFrame::CMyFrame()
{
Create(NULL,"MyApp Application"); //构造框架
}
DECLARE_MESSAGE_MAP(CMyFrame,CFrameWnd) //消息映射宏
ON_WM_PAINT()
END_MESSAGE_MAP
void OnPaint() //重新绘制窗口
{
CPaintDC dc(this);
dc.TextOut(0,0,"I enjoy programming!");
}
*********************************************************
我怀疑是WinMain()函数的问题,
可是不是说WinMain()函数是隐藏起来了吗?
要怎么解决才能让程序运行起来?
谢谢!
//second
对CPP文件做了一点改动,我这里已经运行起来了:
#include "stdafx.h"
#include <afxwin.h>
#include "file.h"
CMyApp theApp; //应用程序全局变量
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMyFrame(); //初始化,启动应用程序
m_pMainWnd->ShowWindow(m_nCmdShow); //显示主框架窗口
m_pMainWnd->UpdateWindow();
return TRUE;
}
CMyFrame::CMyFrame()
{
Create(NULL,"MyApp Application"); //构造框架
}
BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd) //这里应该是BEGIN,不是DECLARE
ON_WM_PAINT()
END_MESSAGE_MAP() //括号
void CMyFrame::OnPaint() //重新绘制窗口
{
CPaintDC dc(this);
dc.TextOut(0,0,"I enjoy programming!");
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
AfxWinInit(hInstance,hPrevInstance,lpCmdLine,nCmdShow); //初始化
theApp.InitInstance();
theApp.Run(); //消息循环
return 0;
}
//third
另外你的程序中用错了宏
应该是
BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd) //消息映射宏
ON_WM_PAINT()
END_MESSAGE_MAP()
还有你的OnPaint函数怎么不是类成员函数?
注意函数的实现
void CMyFrame ::OnPaint()
//fourth
.h文件正确 cpp文件如下 工程设置为mfc动态链接
#include <afxwin.h>
#include "MyApp.h"
CMyApp theApp; //应用程序全局变量
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMyFrame(); //初始化,启动应用程序
m_pMainWnd->ShowWindow(m_nCmdShow); //显示主框架窗口
m_pMainWnd->UpdateWindow();
return TRUE;
}
CMyFrame::CMyFrame()
{
Create(NULL,"MyApp Application"); //构造框架
}
BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd) //消息映射宏
ON_WM_PAINT()
END_MESSAGE_MAP()
void CMyFrame ::OnPaint() //重新绘制窗口
{
CPaintDC dc(this);
dc.TextOut(0,0,"I enjoy programming!");
}