14 个解决方案
#1
自己顶上去 ++
#2
培养你良好习惯呗,自己申请的要自己释放。:)
其实handle都有引用计数,感觉是可以自动释放的,难道最初那哥们没这么写,以后改的成本太高,就一直延续下去了?
其实handle都有引用计数,感觉是可以自动释放的,难道最初那哥们没这么写,以后改的成本太高,就一直延续下去了?
#3
原来是这样、、、
#4
感觉成本也不是太高啊 就一个析构函数而已
#5
就像java一样,替你做太多东西,程序员就不*了。
#6
如果太懒就有智能指针
#7
都封装好多东西了 偏偏没把delete这个功能放进析构函数里面 有点想不通 是不是另有原因
#8
我想是不是因为句柄在随时变化的问题
#9
放进析构里,如果是new出来的,还不是得你自己负责?
#10
系统不会帮你做这些事情,在程序退出的时候,系统会回收所有的资源。但是一个程序还在运行,只要资源没有被释放,系统就会认为这个资源在后面都会用到。而事实是,你每次用的时候,都new了一个新的。这些破烂就不断的堆积,吃着内存。
#11
微软很多函数都是C支持的,C里面是没有析构函数的概念的。
#12
Graphic Objects
Home | Overview | How Do I | Tutorial
Windows provides a variety of drawing tools to use in device contexts. It provides pens to draw lines, brushes to fill interiors, and fonts to draw text. MFC provides graphic-object classes equivalent to the drawing tools in Windows. The table below shows the available classes and the equivalent Windows graphics device interface (GDI) handle types.
The general literature on programming for the Windows GDI applies to the Microsoft Foundation classes that encapsulate GDI graphic objects. This article explains the use of these graphic-object classes:
Classes for Windows GDI Objects
Class Windows handle type
CPen HPEN
CBrush HBRUSH
CFont HFONT
CBitmap HBITMAP
CPalette HPALETTE
CRgn HRGN
Each graphic-object class in the class library has a constructor that allows you to create graphic objects of that class, which you must then initialize with the appropriate create function, such as CreatePen.
Each graphic-object class in the class library has a cast operator that will cast an MFC object to the associated Windows handle. The resulting handle is valid until the associated object detaches it. Use the object’s Detach member function to detach the handle.
The following code casts a CPen object to a Windows handle:
CPen myPen;
myPen.CreateSolidPen( PS_COSMETIC, 1, RGB(255,255,0) );
HPEN hMyPen = (HPEN) myPen;
Process of Creating a Graphic Object in a Device Context
The following four steps are typically used when you need a graphic object for a drawing operation:
Define a graphic object on the stack frame. Initialize the object with the type-specific create function, such as CreatePen. Alternatively, initialize the object in the constructor. See the discussion of one-stage and two-stage creation, which provides example code.
Select the object into the current device context, saving the old graphic object that was selected before.
When done with the current graphic object, select the old graphic object back into the device context to restore its state.
Allow the frame-allocated graphic object to be deleted automatically when the scope is exited.
Note If you will be using a graphic object repeatedly, you can allocate it once and select it into a device context each time it is needed. Be sure to delete such an object when you no longer need it.
What do you want to know more about?
One-stage and two-stage construction of graphic objects
Example of constructing a pen in one and two stages
Example of selecting a pen into a device context
Device contexts
Home | Overview | How Do I | Tutorial
Windows provides a variety of drawing tools to use in device contexts. It provides pens to draw lines, brushes to fill interiors, and fonts to draw text. MFC provides graphic-object classes equivalent to the drawing tools in Windows. The table below shows the available classes and the equivalent Windows graphics device interface (GDI) handle types.
The general literature on programming for the Windows GDI applies to the Microsoft Foundation classes that encapsulate GDI graphic objects. This article explains the use of these graphic-object classes:
Classes for Windows GDI Objects
Class Windows handle type
CPen HPEN
CBrush HBRUSH
CFont HFONT
CBitmap HBITMAP
CPalette HPALETTE
CRgn HRGN
Each graphic-object class in the class library has a constructor that allows you to create graphic objects of that class, which you must then initialize with the appropriate create function, such as CreatePen.
Each graphic-object class in the class library has a cast operator that will cast an MFC object to the associated Windows handle. The resulting handle is valid until the associated object detaches it. Use the object’s Detach member function to detach the handle.
The following code casts a CPen object to a Windows handle:
CPen myPen;
myPen.CreateSolidPen( PS_COSMETIC, 1, RGB(255,255,0) );
HPEN hMyPen = (HPEN) myPen;
Process of Creating a Graphic Object in a Device Context
The following four steps are typically used when you need a graphic object for a drawing operation:
Define a graphic object on the stack frame. Initialize the object with the type-specific create function, such as CreatePen. Alternatively, initialize the object in the constructor. See the discussion of one-stage and two-stage creation, which provides example code.
Select the object into the current device context, saving the old graphic object that was selected before.
When done with the current graphic object, select the old graphic object back into the device context to restore its state.
Allow the frame-allocated graphic object to be deleted automatically when the scope is exited.
Note If you will be using a graphic object repeatedly, you can allocate it once and select it into a device context each time it is needed. Be sure to delete such an object when you no longer need it.
What do you want to know more about?
One-stage and two-stage construction of graphic objects
Example of constructing a pen in one and two stages
Example of selecting a pen into a device context
Device contexts
#13
还有官方点的回答吗
#14
跟效率有关,这些要反复用的。
你来来回回的new,delete,系统承受不起。
你来来回回的new,delete,系统承受不起。
#1
自己顶上去 ++
#2
培养你良好习惯呗,自己申请的要自己释放。:)
其实handle都有引用计数,感觉是可以自动释放的,难道最初那哥们没这么写,以后改的成本太高,就一直延续下去了?
其实handle都有引用计数,感觉是可以自动释放的,难道最初那哥们没这么写,以后改的成本太高,就一直延续下去了?
#3
原来是这样、、、
#4
感觉成本也不是太高啊 就一个析构函数而已
#5
就像java一样,替你做太多东西,程序员就不*了。
#6
如果太懒就有智能指针
#7
都封装好多东西了 偏偏没把delete这个功能放进析构函数里面 有点想不通 是不是另有原因
#8
我想是不是因为句柄在随时变化的问题
#9
放进析构里,如果是new出来的,还不是得你自己负责?
#10
系统不会帮你做这些事情,在程序退出的时候,系统会回收所有的资源。但是一个程序还在运行,只要资源没有被释放,系统就会认为这个资源在后面都会用到。而事实是,你每次用的时候,都new了一个新的。这些破烂就不断的堆积,吃着内存。
#11
微软很多函数都是C支持的,C里面是没有析构函数的概念的。
#12
Graphic Objects
Home | Overview | How Do I | Tutorial
Windows provides a variety of drawing tools to use in device contexts. It provides pens to draw lines, brushes to fill interiors, and fonts to draw text. MFC provides graphic-object classes equivalent to the drawing tools in Windows. The table below shows the available classes and the equivalent Windows graphics device interface (GDI) handle types.
The general literature on programming for the Windows GDI applies to the Microsoft Foundation classes that encapsulate GDI graphic objects. This article explains the use of these graphic-object classes:
Classes for Windows GDI Objects
Class Windows handle type
CPen HPEN
CBrush HBRUSH
CFont HFONT
CBitmap HBITMAP
CPalette HPALETTE
CRgn HRGN
Each graphic-object class in the class library has a constructor that allows you to create graphic objects of that class, which you must then initialize with the appropriate create function, such as CreatePen.
Each graphic-object class in the class library has a cast operator that will cast an MFC object to the associated Windows handle. The resulting handle is valid until the associated object detaches it. Use the object’s Detach member function to detach the handle.
The following code casts a CPen object to a Windows handle:
CPen myPen;
myPen.CreateSolidPen( PS_COSMETIC, 1, RGB(255,255,0) );
HPEN hMyPen = (HPEN) myPen;
Process of Creating a Graphic Object in a Device Context
The following four steps are typically used when you need a graphic object for a drawing operation:
Define a graphic object on the stack frame. Initialize the object with the type-specific create function, such as CreatePen. Alternatively, initialize the object in the constructor. See the discussion of one-stage and two-stage creation, which provides example code.
Select the object into the current device context, saving the old graphic object that was selected before.
When done with the current graphic object, select the old graphic object back into the device context to restore its state.
Allow the frame-allocated graphic object to be deleted automatically when the scope is exited.
Note If you will be using a graphic object repeatedly, you can allocate it once and select it into a device context each time it is needed. Be sure to delete such an object when you no longer need it.
What do you want to know more about?
One-stage and two-stage construction of graphic objects
Example of constructing a pen in one and two stages
Example of selecting a pen into a device context
Device contexts
Home | Overview | How Do I | Tutorial
Windows provides a variety of drawing tools to use in device contexts. It provides pens to draw lines, brushes to fill interiors, and fonts to draw text. MFC provides graphic-object classes equivalent to the drawing tools in Windows. The table below shows the available classes and the equivalent Windows graphics device interface (GDI) handle types.
The general literature on programming for the Windows GDI applies to the Microsoft Foundation classes that encapsulate GDI graphic objects. This article explains the use of these graphic-object classes:
Classes for Windows GDI Objects
Class Windows handle type
CPen HPEN
CBrush HBRUSH
CFont HFONT
CBitmap HBITMAP
CPalette HPALETTE
CRgn HRGN
Each graphic-object class in the class library has a constructor that allows you to create graphic objects of that class, which you must then initialize with the appropriate create function, such as CreatePen.
Each graphic-object class in the class library has a cast operator that will cast an MFC object to the associated Windows handle. The resulting handle is valid until the associated object detaches it. Use the object’s Detach member function to detach the handle.
The following code casts a CPen object to a Windows handle:
CPen myPen;
myPen.CreateSolidPen( PS_COSMETIC, 1, RGB(255,255,0) );
HPEN hMyPen = (HPEN) myPen;
Process of Creating a Graphic Object in a Device Context
The following four steps are typically used when you need a graphic object for a drawing operation:
Define a graphic object on the stack frame. Initialize the object with the type-specific create function, such as CreatePen. Alternatively, initialize the object in the constructor. See the discussion of one-stage and two-stage creation, which provides example code.
Select the object into the current device context, saving the old graphic object that was selected before.
When done with the current graphic object, select the old graphic object back into the device context to restore its state.
Allow the frame-allocated graphic object to be deleted automatically when the scope is exited.
Note If you will be using a graphic object repeatedly, you can allocate it once and select it into a device context each time it is needed. Be sure to delete such an object when you no longer need it.
What do you want to know more about?
One-stage and two-stage construction of graphic objects
Example of constructing a pen in one and two stages
Example of selecting a pen into a device context
Device contexts
#13
还有官方点的回答吗
#14
跟效率有关,这些要反复用的。
你来来回回的new,delete,系统承受不起。
你来来回回的new,delete,系统承受不起。