Home > Software engineering >  MFC static text background color run after a period of time to bleach
MFC static text background color run after a period of time to bleach

Time:09-26

Good god, test today a small program, small program to build process is 1. Create a based on the MFC dialog, 2. Add a static text box 3. Change the background color in the Onctlcolor 4. Let the figures in the text box in the Ontimer from 0 to 1000 cycle, running about 20 minutes later, a static text box automatically turned white, dragging the interface after the entire computer screen flower, don't know what's the matter, the great god help me, thank you, application and problems in the pictures,

CodePudding user response:

Task manager to check the number of GDI handle, should be constantly CreateSolidBrush GDI leaks cause resource depletion

The static CBrush mBrush;
If (mBrush m_hObject==NULL)
{
MBrush. CreateSolidBrush (RGB (255, 0, 0));
}
Return (HBRUSH) mBrush;

CodePudding user response:

Search "GDI leak detection"

CodePudding user response:

CreateSolidBrush continuously create, do not need to create repeatedly, reuse

CodePudding user response:


Create a is enough, gets the if found guilty of empty is created,

CodePudding user response:

The dialog initialization, create good, then use it.
Try
The GetStockObject
It is not necessary, but It is not harmful) to delete stock objects by calling DeleteObject.

CodePudding user response:

GDI to more than 9999,
  • Related