CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

看vc技术内幕产生的问题

楼主gradeyong(草籽)2004-03-04 08:53:27 在 VC/MFC / 基础类 提问

vc技术内幕里面在5.2章里面有如下的一段讲解,说的是在生成新的GUI对象时,应先保存旧的对象,使用新对象之后再调用旧的GUI对象,析构函数会自动删除新建的对象,原文及代码如下:  
   
  OK,   so   you   know   that   you   have   to   delete   your   GDI   objects   and   that   they   must   first   be   disconnected   from   their   device   contexts.   How   do   you   disconnect   them?   A   member   of   the   CDC::SelectObject   family   of   functions   does   the   work   of   selecting   a   GDI   object   into   the   device   context,   and   in   the   process   it   returns   a   pointer   to   the   previously   selected   object   (which   gets   deselected   in   the   process).   Trouble   is,   you   can't   deselect   the   old   object   without   selecting   a   new   object.   One   easy   way   to   track   the   objects   is   to   "save"   the   original   GDI   object   when   you   select   your   own   GDI   object   and   "restore"   the   original   object   when   you're   finished.   Then   you'll   be   ready   to   delete   your   own   GDI   object.   Here's   an   example:  
   
  void   CMyView::OnDraw(CDC*   pDC)  
  {  
          CPen   newPen(PS_DASHDOTDOT,   2,   (COLORREF)   0);     //   black   pen,  
                                                                                                      //     2   pixels   wide  
          CPen*   pOldPen   =   pDC->SelectObject(&newPen);       //奇怪呀,这不是把新生成的对象又赋给了CPen*   pOldPen吗?哪有保存呢?老对象存在哪里呢?  
   
          pDC->MoveTo(10,   10);  
          pDC->Lineto(110,   10);                                                   //这应该是用新画笔画线  
          pDC->SelectObject(pOldPen);                                       //   newPen   is   deselected  
  }   //   newPen   automatically   destroyed   on   exit  
   
   
  难道,pDC->SelectObject(&newPen)返回值是老GUI对象不成?  
  本人不才,望各位指点,多谢了。  
  问题点数:20、回复次数:3Top

相关问题

  • 《vc++技术内幕》
  • 关于《VC++技术内幕》
  • VC++6.0技术内幕
  • 关于《Vc++技术内幕》
  • 关于《vc技术内幕》
  • <<VC 技术内幕>> 的例子问题
  • 看过《VC++技术内幕》的请进。。。。。。
  • 求:《vc++技术内幕》的原代码。
  • 谁有VC++技术内幕(中文)
  • <<VC++技术内幕第五版>>如何?

关键词

  • newpen
  • 对象
  • deselected
  • pdc
  • gdi
  • selectobject
  • object
  • select

得分解答快速导航

  • 帖主:gradeyong

相关链接

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

广告也精彩

反馈

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