views:

390

answers:

2

I am trying to create a custom CStatic control in vc++ and have a few problems. I originally was just using a CStatic control with the SS_BLACKRECT style. This was good for the situation until I needed to display an image over the control on demand. I figured out all the logistics behind actually drawing the image onto the control but I cant seem to figure out how to do so without interfering with other things. Basically I want the control to function as a normal CStatic with the SS_BLACKRECT style most of the time. Then I need to be able to call a method that will cause it to draw an image over the control instead. I am doing the drawing using GDI and have tried it both in the OnPaint method and the DrawItem method without success. I can get it to draw in the OnPaint but when I call the base CStatic::OnPaint() it draws over my image. I need to be able to allow it to draw like normal but then just throw an image in on top. When I tried to do it in the DrawItem method I had a problem because obviously it was not drawing using the SS_BLACKRECT style but waiting for me to draw the control like its supposed to. I guess what I think I'm looking for is one of three things. A way to draw using GDI after the base OnPaint method finishes. A way to have the control draw the default SS_BLACKRECT style and then OWNERDRAW the image aftterwards. Or the code to mimic the drawing of SS_BLACKRECT. The last one might be the eaisiest but I just don't know all the things I need to set up to draw a CStatic control like the default DrawItem.

A: 

Here's a couple ideas:

If CStatic::OnPaint() draws over your image, then try calling it first and drawing your image afterwards.

Otherwise, from what little I've seen of SS_BLACKRECT, you should be able to replicate it's drawing simply be calling CDC::FillSolidRect() passing the rectangle of your control obtained through GetClientRect() and using the color returned by GetSysColor(COLOR_WINDOWFRAME)

TheUndeadFish
+1  A: 

Try calling Default() in your OnPaint() handler.

Then, depending on whether you're drawing your image, you can then draw over the top of the standard CStatic control.

Alan