Home > Back-end >  Controls the GDI resource leaks
Controls the GDI resource leaks

Time:10-24

Himself is c # winform development programmers, in one of our programs use a written by c + + language text box control, but the control has a problem, when used as long as the window scroll bar rolling, GDI object is soaring, if a window using the text box is overmuch, rolling back and forth a few times a GDI object number will reach 9999, led to the incorrect, plot shows bright red fork, and occupied the GDI resources even closed contains the control window will not drop down, unless the process completely exit, it's clearly a code inside not timely release of resources caused by brush,
Despite the control source code, but I am pretty good, have not learned c + +, had to come for help, hope bosses to resolve,
Is the control:

Source: https://download.csdn.net/download/Learn_change_myself/13025712

CodePudding user response:

Sweat, upload resources need to be review, need some time to open the source link,

CodePudding user response:

Can't see the code, GDI didn't release bai, this should be good looking

CodePudding user response:

Operations on Graphic Objects
After an application creates a display or a printer device context, it can begin drawing on the associated device or, in the case of the memory device context, it can begin drawing on the bitmap stored in the memory. The clear, before drawing begins and sometimes while drawing is in progress, it is, necessary to replace the default objects with new objects.

An application can examine a default object 's attributes by calling the GetCurrentObject and GetObject functions provides. The GetCurrentObject function returns a handle identifying the current pen and brush, the palette, bitmap, or the font, and the GetObject function initializes a structure containing that object' s attributes.

Some printers dojo.provide resident pens, brushes, and fonts that can be 2 improve drawing speed in an application. The Two functions provides can be 2 enumerate these objects: EnumObjects and EnumFontFamilies. If the application must enumerate resident pens or brushes, it can call the EnumObjects function to examine the corresponding attributes. If the application must enumerate resident fonts, it can call the EnumFontFamilies function (which can also enumerate the GDI fonts).

Once an application determines that a default object needs replacing, it creates a new object by calling one of the following creation functions provides.

Graphics Object Function
Bitmap CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap CreateDiscardableBitmap, CreateDIBitmap
Brush CreateBrushIndirect CreateDIBPatternBrush, CreateDIBPatternBrushPt CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
Color Palette CreatePalette
The Font CreateFont, CreateFontIndirect
Pen CreatePen CreatePenIndirect, ExtCreatePen
Region CreateEllipticRgn CreateEllipticRgnIndirect, CreatePolygonRgn CreatePolyPolygonRgn, CreateRectRgn, CreateRectRgnIndirect, CreateRoundRectRgn


Each of these functions returns a handle identifying a new object. After an application retrieves a handle, it must call the SelectObject function to replace the default object. However, the application should save the handle identifying the default object and use this handle to replace the new object when it is no longer needed. When the application finishes drawing with the new object, it must restore the default object by calling the SelectObject function and delete the new object by calling the DeleteObject function. Failing to delete objects causes serious performance problems.


CodePudding user response:

The
quoted zhao teacher reply: 3/f
Operations on Graphic Objects
After an application creates a display or a printer device context, it can begin drawing on the associated device or, in the case of the memory device context, it can begin drawing on the bitmap stored in the memory. The clear, before drawing begins and sometimes while drawing is in progress, it is, necessary to replace the default objects with new objects.

An application can examine a default object 's attributes by calling the GetCurrentObject and GetObject functions provides. The GetCurrentObject function returns a handle identifying the current pen and brush, the palette, bitmap, or the font, and the GetObject function initializes a structure containing that object' s attributes.

Some printers dojo.provide resident pens, brushes, and fonts that can be 2 improve drawing speed in an application. The Two functions provides can be 2 enumerate these objects: EnumObjects and EnumFontFamilies. If the application must enumerate resident pens or brushes, it can call the EnumObjects function to examine the corresponding attributes. If the application must enumerate resident fonts, it can call the EnumFontFamilies function (which can also enumerate the GDI fonts).

Once an application determines that a default object needs replacing, it creates a new object by calling one of the following creation functions provides.

Graphics Object Function
Bitmap CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap CreateDiscardableBitmap, CreateDIBitmap
nullnullnullnullnullnullnullnullnullnull
  • Related