INTRODUCTION AND RELEVANT INFORMATION:
I have a complex painting to implement in my main window’s
WM_PAINT
handler.
I have submitted a picture bellow to illustrate it:
http://pbrd.co/18fNYYp[
^]
Main window has static controls, instead of buttons, which have style
SS_NOTIFY
.
When user clicks on them, certain actions occur in program.
The following picture shows where static controls in the main window are:
http://pbrd.co/18fOkya[
^]
Map on the orange panel is an
EMF
file ,top left and right logos are
PNG
files, and other pictures are bitmaps.
In order to implement this task, I have decided to draw the entire picture in
WM_PAINT
, and to put invisible static controls over the images on the picture that correspond them.
Therefore, I only return
NULL_BRUSH
in
WM_CTLCOLORSTATIC
handler like this:
case WM_CTLCOLORSTATIC:
return (LRESULT)( (HBRUSH)GetStockObject(NULL_BRUSH) );
I work on
Windows XP
, using
MS Visual Studio C++ 2008 Express Edition
and
pure Win32 API
.
One note: since Express edition of VS
doesn't have resource editor, resource file and resource header were created using
ResEdit from here:
http://www.resedit.net/[
^]
UPDATE ( UPDATED on December, 5th 2013 ) :
I have added
SWP_NOCOPYBITS
flag to
SetWindowPos
call, in my
WM_SIZE
handler, and performance has greatly improved.
The remaining problems I am facing now are described bellow in the section
PROBLEM, subsection
UPDATE ( UPDATED on December, 5th 2013 ) :
PROBLEM:
When I resize my window, static controls slightly flicker.
UPDATE ( UPDATED on December, 5th 2013 ) :
Although performance is greatly improved with the changes I have made ( described above ), flickering occurs when I resize window from left to right, and it also happens when I resize it from top to bottom.
If I resize from right to left/ bottom to top the following effects occur, respectively:
right/bottom edge seems to "lag behind" in redrawing, comparing to the other parts of the window.
This effect happens even if I remove static controls.
This is the only thing left for me to solve.
MY EFFORTS TO SOLVE THE PROBLEM:
I have handled
WM_ERASEBKGND
(returned
(LRESULT)1
), and I have excluded styles
CS_VREDRAW
and
CS_HREDRAW
from my window class-therefore flickering should not be caused because of this.
My window doesn’t have
WS_CLIPCHILDREN
style, since parts of desktop background are shown where static controls are, after I turn on this style.
I have implemented double buffering for both handlers, in order to avoid flickering.
I have used the tool
GDIView
, downloaded from here:
http://www.nirsoft.net/utils/gdi_handles.html[
^]
to track down
GDI leaks
.
Each time I resize my window,
GDIView
shows +4 in column for regions, which means that I leak regions.
I can’t figure out how is this possible, since I do not use API’s that manipulate with regions.
To illustrate exactly what I am facing with, I have made a demo application , with thorough comments:
http://www.filedropper.com/geotermistgrafika[
^]
I believe that this is more efficient way, then posting code since it will consume too much space.
QUESTION:
How can I modify code in demo project to get rid of flickering?
Is my approach wrong, and if it is, what is the right one?
Thank you. Regards.