精简的手动写的MFC代码

  下面的源程序仅仅包括了具备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!");  
  }  
   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值