CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

有的类为什么不能在Add Class中进行继承

楼主zyhtz(海阔天空)2002-04-19 18:21:21 在 VC/MFC / 基础类 提问

在ClassWizardr   的MemberVariablesk中的Add   Class为什么不能对Cobject和CMenu   两个类进行继承,在base   classk中没有这两个类那应如何去做 问题点数:100、回复次数:3Top

1 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-04-19 18:33:13 得分 80

HOWTO:   Derive   From   Classes   not   Listed   in   ClassWizard    
   
  Q99161  
   
   
  --------------------------------------------------------------------------------  
  The   information   in   this   article   applies   to:  
   
  The   ClassWizard,   included   with:  
  Microsoft   Visual   C++   for   Windows,   16-bit   edition,   versions   1.0,   1.5,   1.51,   1.52    
  Microsoft   Visual   C++,   32-bit   Editions,   versions   1.0,   2.0,   2.1,   2.2,   4.0,   4.1,   4.2,   5.0,   6.0  
   
  --------------------------------------------------------------------------------  
   
   
  SUMMARY  
  Microsoft   ClassWizard   supports   deriving   classes   only   from   the   classes   listed   in   the   Class   Type   field   of   the   Add   Class   dialog   box.   To   create   a   class   derived   from   a   previously   derived   class   or   to   derive   from   another   class   based   on   the   Microsoft   Foundation   Class   Library   CWnd   class   that   is   not   listed   in   the   Class   Type   field,   a   few   extra   steps   are   required.   The   text   below   presents   these   steps.    
   
   
   
  MORE   INFORMATION  
  For   example,   suppose   the   following   derivation   tree   is   desired:    
   
   
        MyDerivedClass  
                    ^  
                    |  
            MyBaseClass  
                    ^  
                    |  
              CDialog    
  or,   it   is   desirable   to   derive   a   class   from   a   class   based   on   CWnd   that   is   not   listed   in   the   Class   Type   field   in   the   Add   Class   dialog   box,   such   as   CFileDialog.   There   is   no   predefined   method   to   create   this   type   of   class   hierarchy   using   the   ClassWizard.   However,   by   using   the   parsing   techniques   ClassWizard   uses,   you   can   create   these   class   hierarchies.  
   
  The   steps   below   use   CDialog   as   the   default   class   type.   Before   proceeding,   determine   which   predefined   class   type   is   closest   to   the   desired   base   class.   For   example,   CFileDialog   is   similar   to   CDialog.   If   none   of   the   classes   correspond   closely   to   your   desired   class,   use   the   generic   CWnd   class.  
   
  To   create   a   class   with   multiple   levels   of   derivation,   perform   the   following   three   steps:  
   
   
  Use   ClassWizard   to   create   MyDerivedClass,   deriving   it   from   CDialog   (or   another   appropriate   predefined   class).  
   
   
  Use   ClassWizard   to   create   MyBaseClass,   deriving   it   from   CDialog   (or   another   appropriate   predefined   class).  
   
   
  Edit   the   code   generated   for   MyDerivedClass   and   replace   all   references   to   CDialog   with   MyBaseClass.   This   step   is   very   important;   many   errors   occur   if   this   is   not   done   correctly   and   these   errors   may   be   difficult   to   track   down.  
   
   
  To   create   a   class   based   on   a   class   based   on   CWnd   that   is   not   supported   by   ClassWizard,   perform   the   following   two   steps:  
   
   
  Use   ClassWizard   to   create   MyDerivedClass,   deriving   it   from   CDialog   (or   another   appropriate   predefined   class   based   on   CWnd).  
   
   
  Edit   the   code   generated   for   MyDerivedClass   and   replace   all   references   to   CDialog   with   the   name   of   the   class   from   which   you   are   deriving   this   class,   for   example,   CFileDialog.   This   step   is   very   important;   many   errors   occur   if   this   is   not   done   correctly   and   these   errors   may   be   difficult   to   track   down.  
   
   
  Then,   for   either   type   of   class,   perform   the   following   three   steps:  
   
   
  Delete   the   project   .CLW   file.  
   
   
  Start   App   Studio,   load   your   project   .RC   file,   and   activate   Class   Wizard.  
   
   
  Because   the   project   does   not   have   a   .CLW   file,   ClassWizard   prompts   to   generate   a   .CLW   file.   Choose   Yes   to   generate   the   file.   NOTE:   You   must   generate   this   file   in   App   Studio.   If   you   attempt   to   generate   the   file   in   Visual   Workbench,   VWB   instructs   you   to   generate   the   file   in   App   Studio.  
   
   
  Once   App   Studio   has   created   the   .CLW   file,   the   base   class   of   the   derived   class   has   been   changed   successfully.   To   verify   this,   view   the   class   in   ClassWizard   and   see   the   data   in   the   Class   Info   dialog   box.  
   
  For   classes   created   using   multiple   levels   of   derivation,   you   can   use   ClassWizard   to   pass   system   messages,   such   as   WM_INITDIALOG,   to   the   base   class   as   well.   To   do   this,   perform   the   following   nine   steps:  
   
   
  Start   ClassWizard.  
   
   
  Select   the   MyDerivedClass   class.  
   
   
  Select   MyDerivedClass   in   the   Object   IDs   window.  
   
   
  Select   the   WM_INITDIALOG   message   in   the   Messages   window.  
   
   
  Choose   Add   Function   to   add   a   function   skeleton   that   calls   the   OnInitDialog()   function   in   MyBaseClass.  
   
   
  Select   the   MyBaseClass   class.  
   
   
  Select   MyBaseClass   in   the   Object   IDs   window.  
   
   
  Select   the   WM_INITDIALOG   message   in   the   Messages   window.  
   
   
  Choose   Add   Function   to   add   a   function   skeleton   that   calls   the   OnInitDialog()   function   in   CDialog.   This   step   is   required   only   once.   If   you   derive   additional   classes   from   the   base   class,   you   do   not   need   to   redo   this   operation.  
   
   
   
  Additional   query   words:    
   
  Keywords   :   kbwizard   kbVC100   kbVC150   kbVC151   kbVC152   kbVC200   kbVC210   kbVC220   kbVC400   kbVC410   kbVC420   kbVC500   kbVC600   kbGrpDSTools    
  Issue   type   :   kbhowto    
  Technology   :   kbVCsearch   kbAudDeveloper   kbClassWizard    
   
   
  Last   Reviewed:   May   3,   2001  
  ©   2001   Microsoft   Corporation.   All   rights   reserved.   Terms   of   Use.  
     
   
   
   
  --------------------------------------------------------------------------------  
  Send   feedback   to   MSDN.Look   here   for   MSDN   Online   resources.Top

2 楼ytweiwei(又穷又丑农村户口!!!!)回复于 2002-04-19 18:38:34 得分 10

继承CWnd类,然后在手工修改成CMenu类不就行了吗?Top

3 楼ColderRain(一切尽在不言中)回复于 2002-04-19 19:12:17 得分 10

新建为通用类!    
  然后手工修改.  
   
  继承CWnd类,对有些类可以,但有些类就会出问题!而且是莫名其妙的!    
   
   
  Top

相关问题

  • 继承的class能让主类调用继承的函数吗?
  • 怎么在class wizard里继承一个CObject类??
  • 关于概念(concept)的改善(refinement)和类(class)的继承(inheritance):
  • 如何用insert->new class选择从CBitmap类继承啊?
  • runnable的class可以被继承为可以wait、notify的类?
  • 类怎样继承
  • 类继承问题?
  • CDialogBar类的继承
  • VC继承类的困惑!
  • 类继承的问题!

关键词

  • visual c++
  • microsoft
  • 类
  • derive
  • classwizard
  • add
  • listed

得分解答快速导航

  • 帖主:zyhtz
  • jiangsheng
  • ytweiwei
  • ColderRain

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo