CStatic自定义控件
我正在尝试在 vc++
中创建自定义 CStatic
控件,但遇到了一些问题。
我最初只是使用具有 SS_BLACKRECT
样式的 CStatic
控件。 这对这种情况很有好处,直到我需要根据需要在控件上显示图像。
我弄清楚了将图像实际绘制到控件上背后的所有逻辑,但我似乎无法弄清楚如何在不干扰其他事情的情况下做到这一点。
基本上,我希望该控件在大多数情况下都可以用作具有 SS_BLACKRECT
样式的普通 CStatic
功能。
然后我需要能够调用一个方法,使其在控件上绘制图像。 我正在使用 GDI 进行绘图,并在 OnPaint() 方法和 DrawItem() 方法中尝试过,但没有成功。 我可以让它在 OnPaint()
中绘制,但是当我调用基础 CStatic::OnPaint()
时,它会在我的图像上绘制。
我需要能够让它像平常一样绘制,但然后只需在上面放置一个图像即可。 当我尝试在 DrawItem()
方法中执行此操作时,我遇到了问题,因为显然它不是使用 SS_BLACKRECT
样式进行绘制,而是等待我像它一样绘制控件应该。
我想我正在寻找的是三件事之一。 一种在基本 OnPaint()
方法完成后使用 GDI
进行绘制的方法。 一种让控件绘制默认的 SS_BLACKRECT 样式,然后绘制 OWNERDRAW 图像的方法。 或者模仿 SS_BLACKRECT
绘图的代码。
最后一个可能是最简单的,但我只是不知道绘制像默认 DrawItem 这样的 CStatic
控件所需的所有设置。
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 afterwards. Or the code to mimic the drawing of SS_BLACKRECT
.
The last one might be the easiest but I just don't know all the things I need to set up to draw a CStatic
control like the default DrawItem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在
OnPaint()
处理程序中调用Default()
。然后,根据您是否要绘制图像,您可以在标准
CStatic
控件的顶部进行绘制。Try calling
Default()
in yourOnPaint()
handler.Then, depending on whether you're drawing your image, you can then draw over the top of the standard
CStatic
control.这里有一些想法:
如果
CStatic::OnPaint()
在您的图像上绘制,则尝试先调用它,然后再绘制您的图像。否则,从我对 SS_BLACKRECT 的了解来看,您应该能够通过调用 CDC::FillSolidRect() 传递通过 GetClientRect() 获得的控件矩形来复制它的绘图。 并使用
GetSysColor(COLOR_WINDOWFRAME)
返回的颜色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 throughGetClientRect()
and using the color returned byGetSysColor(COLOR_WINDOWFRAME)