CClientDC drawing over child controls.

Hey guys,

I have a desire to draw gradient rectangles over the regions of child controls under certain situations such as when the user enters invalid data. Basically, I'm implementing a more visual and less annoying means of doing DDV.

My problem currently is that I can not actually draw over the regions of child controls. My clip rectangle for the DC excludes these regions. I've been trying to use the ::ExtSelectClipRgn and related Win32 functions to achieve the effect of temporarily adding in the region of the child control into the region associated with the parent (CMFCPropertyPage derived class) DC so I can do my drawing. Anyone have any suggestions ?

Personally,  I would prefer to avoid the transparent window idea. It just seems more trouble that should be needed to do what I want. The mouse event issues ect.
twgoodmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JohnGabyCommented:
Are you trying to paint your rectangle during the processing of the WM_PAINT message, or external to that.  Note that the child window (is it an edit control?) will receive it's own paint message, and wipe out any painting that you do.  If all you are doing is looking for a visual indication that something is wrong, you might consider just changing the background of the edit control to another color.
0
twgoodmanAuthor Commented:
Potential painting (highlighting) of the control needs to occur during OnPaint, and during calls connected to DoDataExchange. The OnPaint updating is just to handle the user moving the window around where controls would be hidden.

The goal of this effort is that its generic. Any control that has potential to become "invalid" in some regard I would like to highlight (Edit, combobox, grid, ect) More importantly, if other controls are added down the road (custom or otherwise) I dont want to have to concern myself with making sure I overwrite methods in every class. As of this moment, I have the core framework to do just that. I even draw "outlines" around each kind of control.  The outline of course is because I grab the rect of the control in question and inflate it. The inflated part is within my valid clipping region so it paints correctly. I would prefer to be able to highlight the entire control in a semi-transparent" color that I can potentially even add "glowing" effects on when I have more time.

Is there a way that you know of the insert another region into the current clipping region ? I was looking as the API ExtSelectClipRgn() but not sure if im using it correctly.
0
JohnGabyCommented:
The problem is that after you receive your OnPaint message in your parent window, the control in question will receive an OnPaint and even if you somehow painted into it's window, it would wipe out whatever you did.  What you would need to do is intercept the OnPaint message for the child and paint your rectangle after it finished it's painting.  Unfortunately,  I am afraid that I cannot think of a generic way to do that short of creating another window which sits on top of the control (which you said you didn't want to do).

Perhaps someone else has an idea.  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeAThonCommented:

See this article: "  A Validating Edit Control" at http://www.flounder.com/validating_edit_control.htm 

In general, you should derive a class for each control that interests you, and then in the derived class you should handle the reflected WM_CTLCOLOR message (using the ON_WM_CTLCOLOR_REFLECT() macro).  In the handler, set the background color (and text color if desired) and return a handle to the brush you want the background drawn in.

The technique works well for solid colored backgrounds.  If you want gradients,  then your derived class probably needs to handle WM_ERASEBKGND too.

Regardless of your approach, and as indicated by JohnGaby, you probably should not be doing any drawing in the dialog class.  All drawing should probably be done in the derived control class.   If you draw in the dialog class, then any drawing done there will probabl; be undone by the control itself, when it receives its own WM_PAINT message.

Good luck.
0
twgoodmanAuthor Commented:
I understand that normally all painting "should" be done by the control in question itself, I was trying to pull something off that would make the remainder of my current task alot simpler. Especially, since down the road there are likely going to be different controls being placed on the property pages (dialogs). I appreciated the feedback though.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.