-
WM_PAINT all wrong
I'm on a similar lead, so I hope I can get help as well as give it. I wanted to intercept the OnPaint message as well. I used PreTranslateMessage and intercepted WM_NCPAINT and WM_PAINT and just returned true. I also setup OnPaint() to insure no painting happens by do nothing. I then checked Spy++ to see what is going on. Several errors happened.
1. Nothing but WM_PAINT with hdc=000000 was sent continously. Thus, some message must be sent to satisfy the messaging. But what???
2. I also additionally use menus and when pressing alt and pulling up the main menu popups, the whole dialog mysteriously got repainted anyways. The interception handlers failed terribly here and there is yet another message somewhere to consider for painting/repainting though Spy++ reveals nothing? My only clue would be RedrawWindow...
So basicly, I want to intercept OnPaint messaging to prevent *any* painting from happening (and luckily be able to manually call the individual control drawing functions whatever they are). Yes, this means custom drawing but that's the way I want to go. It seems to me much easier to just setup a timer event and draw everything yourself, but you already can see how that becomes very troublesome. So if anyone has more tech tips, I would like to hear them on this subject...
As far as your concern, I think ON_PAINT is the *bad* way to go. Why? For one, as you noticed, it can be a resource hog and bother. There are several other ways to go and a lot more efficient.
1. Manually use and intercerpt the afx_msg BOOL OnEraseBckGnd(CDC* pDC) (WM_ON_ERASEBCKGND() ) by manually placing into the class data structures of your class, if using MFC.
2. In OnEraseBckGnd(), tell it to paint the background the way you like (or by default) with the appropiate brush by using custom painting then tell it to call a code to draw your text :)
3. You can also use OnCtlColor to intercept individual control items (addable from ClassWizard). Just check the window handle passed as a paramter to your control handle and instead of returning the brush, return a "HOLLOW_BRUSH" after painting your own background (or the default brush if you like) and then telling it to draw your text by again calling your custom drawing text.
4. This is the *smooth* way to go about it because there are no extra drawings. By intercepting ONPaint, it already draws the default background by Calling the above functions and then you would just be *drawing over* what it drew...
Sorry, no code examples but the above should be a good lead for you. I personally avoid OnPaint because it can become annouying or even unnecessary. As for the rest of your calls if you still preferre OnPaint, you will want to consider WM_NCPAINT also. This is sent when another window overlaps your window and is also usually sent before WM_PAINT. The reason I suggest the above, is that you may get your code right by using OnPaint, but if you repeat similar instances of what you are trying to do (that is use lots of static controls) you will probably get a very *blinking* window when trying to resize, etc. A whole lot more headaches to consider. In the end run, there is no easy way to go about it but hope to find how to intercept the WM_PAINT similar to your question without *any* drawing going on. Also note that the above will not work for all controls because of each controls uniqueness, but works fine for static controls.
Hope the leads help!
Cheers.