MFC flash screen solution

These two days I have been doing UI design, because the company did not use commercial Direct UI and other interface libraries. So the developers had to draw their own controls, so the task of writing the UI fell to me as a new coder. Then the problem I had been avoiding came up against me. Smecta.

problem a, own drawing background is hiding the interface on the original control, in order to solve this problem, but get me hanging silk maxed out.

a, painted a background, and then the area of access to all controls, make it invalid. So the problem was solved, but a new problem came, is the flash screen problem. This problem is caused by overwriting the background and control color. In other words, this scheme is eunuch.

> For this kind of scheme, I just thought, should be OK. But it’s too difficult. I don’t have the ability to do it.

> Set the dialog’s clipChildren property to true. When you draw a window, you cut out the area of the control and copy it back when it is finished. This property is customized for the drawing, so the above problem is solved with just one click. The solution turned out to be so simple.

if draw refresh frequently, this there is no doubt that the splash screen will appear.

Scheme 1, the use of double buffer, no pressure. So every time I draw it, I just paste it on.

2, in painting background brush set for NULL_BRUSH background before you leave. The system could not draw.

3, to draw the background of function (OnEraseBkgnd (pDC) CDC *) content to watch out, with the return true replacement, and then system, there is no way to use the default brush to draw the background. However, the latter two methods solve the flicker, but the interface can be a mess.

using GDI resource summary:

first of all, we all know this law have borrow have also, so when learning c + + so follow this rule, otherwise you will hit a wall.

when using handle with H, for example: the HBITMAP etc, after using DeleteObject remember;

For GDI wrapped classes with C, this is not necessary because the system has already freed them during object destructing. If you leave the system resource handle with the class Detach, then you need to take over the management of the system resource, otherwise the system resource leak will occur.

when using CDC, if the memory DC created after running out also need DeleteDc…..


Read More: