#include "afxwin.h"class CMyApp:public CWinApp
{
public:
virtual bool InitInstance();
};CMyApp theApp;class CMyFrame:public CFrameWnd
{
public:
CMyFrame();
protected:
afx_msg void OnPaint();

};bool CMyApp::InitInstance()
{
m_pMainWnd = new CMyFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}CMyFrame::CMyFrame()
{
Create(NULL,"welcome to my web!!!");
}void CMyFrame::OnPaint()
{
CPaintDC dc(this);
dc.TextOut(20,20,"hello word!!!");
}我运行上面的代码,为什么总是出问题啊。它提示的信息是:d:\program files\microsoft visual studio\myprojects\test\test.cpp(6) : error C2555: 'CMyApp::InitInstance' : overriding virtual function differs from 'CWinApp::InitInstance' only by return type or calling convention
我看这个语句没有用到,需要吗?
还有afx_msg、DECLARE_MESSAGE_MAP()是什么意思,可以具体的给我讲讲吗?谢谢了!!!

解决方案 »

  1.   

    bool CMyApp::InitInstance()
    改为
    BOOL ....................
      

  2.   

    谢谢。
    那我的hello word!!!文字怎么没有啊?
    还有bool和 BOOL有什么区别?
      

  3.   

    BOOL 就是int
    typedef int BOOL;Create(NULL,"welcome to my web!!!")是不是又创建了一个窗口?
      

  4.   

    没有啊。
    不过添加下面代码就可以,可以告诉我为什么吗?
    BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
        ON_WM_LBUTTONDOWN()
        ON_WM_PAINT()
    END_MESSAGE_MAP()
      

  5.   

    BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
        ON_WM_PAINT() //是让OnPaint响应WM_PAINT消息,
                      //因此只有加了这句话才能执行OnPaint()
    END_MESSAGE_MAP()
      

  6.   

    哥们,一般不要在cmainframe中生成onpaint最好在view中,你试试。