Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dialog box that should have a custom image as a background.

I do not have the whole image as a bitmap or any other format, so I have to draw it from scratch.

I use an icon ( male in the left bottom of the screenshot) , one EMF file (the map on the screenshot below), and the rest consists of a green gradient brush, light gray hatched brush, and text - all being drawn using GDI. The result of my drawing looks like this (the screen shot includes the controls too):
http://pbrd.co/1m0fQpq[^]

The problem I face manifests when I move the dialog box to the left and then move it back to its original position. The artifacts happening are illustrated at the bottom of the picture in the next screenshot:
http://pasteboard.co/2L0HMJBK.bmp[^]

The dialog box is the modeless one, and I draw the entire image in WM_CTLCOLORDIALOG returning NULL_BRUSH afterwards.

Here is the relevant code snippet for the WM_CTLCOLORDIALOG handler ( note that I draw directly on the DC, there is no double buffering. The reason for it is that this was a quick test code things went wrong quickly):
http://pastebin.com/MKfUeH0N[^]

To make this even more complete, I submit the drawFooter function and its helper functions:
http://pastebin.com/nbxQMW0u[^]

Visual Styles are enabled - this might matter, I do not know.

I did not handle WM_ERASEBKGND nor WM_SIZE or WM_MOVE ( dialog box can not be resized. ). I have tried but it did not help ( returning TRUE for WM_ERASEBKGND, and InvalidateRect for WM_SIZE and WM_MOVE ). I have found nothing on the internet to help me.

Question: How to change my code to fix the error I face?
Posted
Updated 14-Jan-14 5:29am
v2
Comments
nv3 14-Jan-14 11:29am    
It appears to me that if the dialog should have an image as background, you should draw that in WM_ERASEBKGND and not in WM_CTLCOLORDLG.
AlwaysLearningNewStuff 14-Jan-14 11:34am    
I have tried that too, but the effect remains. I have also tried to do it like it was a normal window-returning TRUE in WM_ERASEBKGND and moving all the painting code in WM_PAINT but that did not help either-the effect is the same.

1 solution

The solution:
http://stackoverflow.com/questions/21117252/dialog-box-improperly-repaints-its-background/21117466#21117466[^]

To sum it up shortly:

The problem has been solved by simply switching the order of the vertexes in my GradientTriangle helper function-to be precise I have switched indexes of second and third vertex.

EDIT:

I have also deleted WM_CTLCOLORDIALOG code and moved my drawing code into WM_ERASEBKGND as member nv3 suggested.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900