本人是C# winform開發程式員,在我們的一個專案之中使用了一個由c++語言寫的文本框控制元件,但是這個控制元件有問題,使用的時候只要視窗滾動條一滾動,GDI物件就飛漲,如果一個視窗使用該文本框過多,來回滾動幾回GDI物件數量就會達到9999,導致程式繪制錯誤,顯示大紅叉。而且被占用的GDI資源哪怕關閉包含該控制元件的視窗都不會降下來,除非把行程徹底退出,這顯然是代碼里面沒有及時釋放brush之類的資源導致的。
雖然有這個控制元件的源代碼,但無奈本人才疏學淺,沒學過c++,只好來求助了,望大佬們給解決解決。
就是這個控制元件:

原始碼鏈接:https://download.csdn.net/download/Learn_change_myself/13025712
uj5u.com熱心網友回復:
汗,上傳的資源需審核,原始碼鏈接需要過些時間才能打開,
uj5u.com熱心網友回復:
看不到代碼,GDI沒釋放唄,這個應該好找的uj5u.com熱心網友回復:
Operations on Graphic ObjectsAfter an application creates a display or 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 memory. However, before drawing begins and sometimes while drawing is in progress, it is often 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. The GetCurrentObject function returns a handle identifying the current pen, brush, palette, bitmap, or font, and the GetObject function initializes a structure containing that object's attributes.
Some printers provide resident pens, brushes, and fonts that can be used to improve drawing speed in an application. Two functions can be used to 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 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.
Graphics Object Function
Bitmap CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDiscardableBitmap, CreateDIBitmap
Brush CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
Color Palette CreatePalette
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.
uj5u.com熱心網友回復:
大佬,雖然你指出了問題所在,但是我不會改啊
,因為我對c++一竅不通,汗,所以才會把原始碼放上來讓大家看著改,最后給我一個編譯好的能注冊的.ocx檔案即可。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/188317.html
標籤:C++ 語言
上一篇:新人C++求助
下一篇:大佬們,我的這個程式哪里有問題呀
