Static controls flicker slightly when the main window changes

INTRODUCTION AND RELATED INFORMATION:

I have a complicated picture to implement in my main WM_PAINT window.

I presented the image below to illustrate this:

enter image description here

The main window has static controls, not buttons with the SS_NOTIFY style.

When the user clicks on them, certain actions take place in the program.

The following figure shows which static controls are in the main window:

enter image description here

The map on the orange panel is an EMF file, the top left and right logos are PNG files, and other images are bitmap images.

To implement this task, I decided to draw the whole picture in WM_PAINT and put invisible static image controls on the image that corresponds to them.

Therefore, I only return NULL_BRUSH in the WM_CTLCOLORSTATIC handler as follows:

 case WM_CTLCOLORSTATIC: return (LRESULT)( (HBRUSH)GetStockObject(NULL_BRUSH) ); 

I am working on Windows XP using the MS Visual Studio C++ 2008 Express Edition and the pure Win32 API .

One note : since Express VS does not have one , the resource editor, resource file and resource header were created using ResEdit from here: http://www.resedit.net/ .

Problem:

When I resize the window, the static controls flicker slightly.

MY EFFORTS TO SOLVE THE PROBLEM:

I processed WM_ERASEBKGND (returned (LRESULT)1 ), and I excluded the CS_VREDRAW and CS_HREDRAW from my window class, so this should not cause flickering.

There is no WS_CLIPCHILDREN style in my window.

EDIT: In response to the comment below, I will explain why this window does not have this style set:

The problem is that part of the desktop image is visible where static controls are installed.

I implemented double buffering for both handlers to avoid flickering.

I used the GDIView tool downloaded here: http://www.nirsoft.net/utils/gdi_handles.html to track the GDI leaks .

Every time I resize the window, GDIView shows +4 in the column for regions, which means that I am leaking regions.

I cannot understand how this is possible, since I do not use APIs that manipulate regions.

To illustrate what I came across, I made a demo application with detailed comments: http://www.filedropper.com/geotermistgrafika

I believe this is a more efficient way and then send the code as it will consume too much space.

Question:

How can I change the code in a demo project to get rid of the flicker?

Is my approach wrong, and if so, which one is right?

Thanks. Best wishes.

+5
source share
1 answer

When resizing the main window, the WM_SIZE handler moves the static child windows.

When the child window is moved, Windows automatically copies the client area of โ€‹โ€‹the child control from the old location to the new location.

The main window will then be repainted into the WM_PAINT handler.

In other words, when the window is resized, all static controls are moved to a new position, and then the rest of the window is redrawn. Lack of synchronization looks like a flicker.

You can avoid this by passing the SWP_NOCOPYBITS flag to SetWindowPos .

+5
source

All Articles