首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

好心人来帮忙-练习MSDN中的TNO62示例程序解决方法

2012-01-12 
好心人来帮忙------练习MSDN中的TNO62示例程序好心人给讲讲这七个错误的原因,解决方法,需要那些参考资料--

好心人来帮忙------练习MSDN中的TNO62示例程序
好心人给讲讲这七个错误的原因,解决方法,需要那些参考资料


--------------------Configuration:   TNO62   -   Win32   Debug--------------------
Compiling   resources...
Compiling...
StdAfx.cpp
Compiling...
TNO62.cpp
1:   error   C2146:   syntax   error   :   missing   '; '   before   identifier   'm_YellowEdit '


2:   error   C2501:   'CYelloEdit '   :   missing   storage-class   or   type   specifiers


3:   error   C2501:   'm_YellowEdit '   :   missing   storage-class   or   type   specifiers
TNO62Dlg.cpp


4:   error   C2146:   syntax   error   :   missing   '; '   before   identifier   'm_YellowEdit '


5:   error   C2501:   'CYelloEdit '   :   missing   storage-class   or   type   specifiers


6:   error   C2501:   'm_YellowEdit '   :   missing   storage-class   or   type   specifiers


7:   error   C2065:   'm_YellowEdit '   :   undeclared   identifier


YelloEdit.cpp
Generating   Code...
Error   executing   cl.exe.

TNO62.exe   -   7   error(s),   0   warning(s)

前六个错误都指向这里:

//{{AFX_DATA(CTNO62Dlg)
enum   {   IDD   =   IDD_TNO62_DIALOG   };
CYelloEditm_YellowEdit;
//}}AFX_DATA

这个m_YellowEdit,我按照MSDN的要求定义为(Control)CYellowEdit类型,这个CYellowEdit从CEdit继承

最后一个错误指向这里:

CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTNO62Dlg)
DDX_Control(pDX,   IDC_EDIT1,   m_YellowEdit);
//}}AFX_DATA_MAP
}

按照MSDN的要求,先在Dialog   Box上画一个edit,然后设置其变量为Control   并且为CYellowEdit类型


令问:     ON_WM_CTLCOLOR_REFLECT()   干吗的?


附MSDN的示例

To   try   the   example   that   creates   a   reusable   control
Create   a   new   dialog   box   in   an   existing   application.   For   more   information,   see   the   dialog   editor   topic.  

You   must   have   an   application   in   which   to   develop   the   reusable   control.   If   you   don 't   have   an   existing   application   to   use,   create   a   dialog-based   application   using   AppWizard.  

With   your   project   loaded   into   Visual   C++,   use   ClassWizard   to   create   a   new   class   called   CYellowEdit   based   on   CEdit.

Add   three   member   variables   to   your   CYellowEdit   class.   The   first   two   will   be   COLORREF   variables   to   hold   the   text   color   and   the   background   color.   The   third   will   be   a   CBrush   object   that   will   hold   the   brush   for   painting   the   background.   The   CBrush   object   allows   you   to   create   the   brush   once,   merely   referencing   it   after   that,   and   to   destroy   the   brush   automatically   when   the   CYellowEdit   control   is   destroyed.



Initialize   the   member   variables   by   writing   the   constructor   as   follows:  

    Copy   Code  
CYellowEdit::CYellowEdit()
{
      m_clrText   =   RGB(   0,   0,   0   );
      m_clrBkgnd   =   RGB(   255,   255,   0   );
      m_brBkgnd.CreateSolidBrush(   m_clrBkgnd   );
}
 

Using   ClassWizard,   add   a   handler   for   the   reflected   WM_CTLCOLOR   message   to   your   CYellowEdit   class.   Note   that   the   equal   sign   in   front   of   the   message   name   in   the   list   of   messages   you   can   handle   indicates   that   the   message   is   reflected.   This   is   described   in   Defining   a   Message   Handler   for   a   Reflected   Message.  

ClassWizard   adds   the   following   message-map   macro   and   skeleton   function   for   you:  

    Copy   Code  
ON_WM_CTLCOLOR_REFLECT()

//   Note:   other   code   will   be   in   between....

HBRUSH   CYellowEdit::CtlColor(CDC*   pDC,   UINT   nCtlColor)  
{
      //   TODO:   Change   any   attributes   of   the   DC   here
     
      //   TODO:   Return   a   non-NULL   brush   if   the
      //       parent 's   handler   should   not   be   called
      return   NULL;
}
 

Replace   the   body   of   the   function   with   the   following   code.   The   code   specifies   the   text   color,   the   text   background   color,   and   the   background   color   for   rest   of   the   control.  

    Copy   Code  
      pDC-> SetTextColor(   m_clrText   );       //   text
      pDC-> SetBkColor(   m_clrBkgnd   );       //   text   bkgnd
      return   m_brBkgnd;                         //   ctl   bkgnd
 

Create   an   edit   control   in   your   dialog   box,   then   attach   it   to   a   member   variable   by   double-clicking   the   edit   control   while   holding   a   control   key   down.   In   the   Add   Member   Variable   dialog   box,   finish   the   variable   name   and   choose   "Control "   for   the   category,   then   "CYellowEdit "   for   the   variable   type.   Don 't   forget   to   set   the   tab   order   in   the   dialog   box.   Also,   be   sure   to   include   the   header   file   for   the   CYellowEdit   control   in   your   dialog   box 's   header   file.



Build   and   run   your   application.   The   edit   control   will   have   a   yellow   background.


感激不尽啦~~~~~~~~~~~~~~~~~~~~~~~~~~~   只剩20分了


[解决办法]
要包含含有类CYellowEdit的头文件
[解决办法]
没有找到CYelloEdit的定义,你没有包含头文件

看看有没有 "Cyelloedit.h "这样的文件
[解决办法]
CYellowEdit.h文件是否以近添加到工程文件中?

热点排行