[win32]Custom Control Painting

Started by
2 comments, last by jwezorek 14 years, 1 month ago
Im trying to paint common windows controls in a custom manner. To do this I sub class the control, and then do the new painting in the WM_PAINT case. But this only seems to work when the control doesnt having focus. When you click on the control, such as a TextBox, you get the normal view, ie the whitebox with a flashing cursor. And even more frustrating, this look stays even when the control loses focus. What is the correct way to do custom painting for controls under win32? I've noticed a few of the controls have OWNERDRAW tags you can set, but not all. And how do you go about painting different looks when the control is in different states, such as a scrollbar being dragged, or the little traingles being clicked?
Advertisement
Briefly if the control supports an owner drawn style you should use that, and if it doesn't, you're out of luck.

I mean you can try to do it. For an edit control you'd have to handle at least WM_ERASEBKGND, WM_PAINT, WM_NCPAINT (probably), then probably WM_SETFOCUS and WM_KILLFOCUS to take care of the problem you're talking about, and maybe WM_CHAR to update the text. But, that said, it will be painful and probably will never quite work. The problem is how Win32 controls paint themselves isn't really documented in specifics so to handle everything requires a lot of experimenting.

If you want to skin your entire application with custom looking controls, you are better off writing your own controls from scratch if you want a project or using a third-party widget library.
But with the editTextBox control, I do handle the WM_PAINT message. Isnt that what gets handled even when the editTextBox has focus? Whats getting called to paint the white box with the flashing cursor? Why is that being drawn, once thew control is clicked, and not the code I have implemented in WM_PAINT ?
Quote:Original post by maya18222
But with the editTextBox control, I do handle the WM_PAINT message. Isnt that what gets handled even when the editTextBox has focus? Whats getting called to paint the white box with the flashing cursor? Why is that being drawn, once thew control is clicked, and not the code I have implemented in WM_PAINT ?


The implementation of the edit control must be painting outside of WM_PAINT. All you need to paint into a window is an HDC; the implementation can be calling GetDC() and paint in any message handler. The flashing cursor, maybe, is getting painted in a WM_TIMER handler or something. I don't know, and that's the point: this stuff isn't documented.

This topic is closed to new replies.

Advertisement