获取分组框线的主题属性
我的目标是绘制一个不是矩形而是切掉角的组框。我的意思并不是只剪掉边角,而是有一条连续的闭合路径,其中边角是“缩进的”。我希望它与当前主题的颜色/风格相匹配。
我注意到在 Windows XP 上,组框有 1 像素的灰线,但在 Windows 7 上,通过在白线旁边设置一条灰线(内部的白线,除了底部的白线之外)创建 3D 效果灰线)。
您可以使用如下方式获取组框文本标签的颜色:
COLORREF cref;
GetThemeColor(hTheme, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &cref);
因此,我试图弄清楚如何获取组框中使用的线条的颜色和/或属性,然后(我希望)能够通过单独绘制我想要的形状的每一块来绘制我想要的与组框样式相匹配的线条。我不确定使用什么属性来描述线条,或者函数 line DrawRect 是否会使用合适的笔绘制 3D 效果。有没有办法设置笔来绘制这些 3D 效果(2 色平行线)?
谢谢。
My goal is to draw a Group Box that is not rectangular but instead has the corners cut away. I do not mean just clipping the corners, but rather have a continuous closed path where the corners are "indented." I want this to match the colors/style of the current theme.
I noticed on Windows XP that the Group Box has 1-pixel gray lines, but on Windows 7 there is a 3D effect created by having a gray line next to a white line (the white line on the interior except on the bottom where it's below the gray line).
You can get the color of the text label of a Group Box using something like this:
COLORREF cref;
GetThemeColor(hTheme, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &cref);
So, I'm trying to figure out how to get the color(s) and/or properties of the lines used in a Group Box, then (I hope to) be able to draw the lines I want matching the Group Box style by separately drawing each piece of the shape I want. I'm not sure what properties are used to describe the lines or if functions line DrawRect will draw the 3D effect with a suitable Pen. Is there a way to set a Pen to draw these 3D effects (2-shade parallel lines)?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我总是对分组框感到意外的是,它们实际上是一种按钮风格。 (BS_GROUPBOX)。
主题组框(XP 及更高版本,经典模式关闭)使用 VSCLASS_BUTTON 中的主题部分 BP_GROUPBOX。您可以使用常用的主题 API 来获取和绘制。如果您的组框需要文本,您可以使用 DrawThemeText。
也有用于绘制非主题组框的 API(例如 DrawEdge),但我不记得详细信息,而且您不太可能需要它们。
像往常一样,我会指出,重现控件的行为总是比您想象的要困难。
马丁
The thing I always find unexpected about groupboxes is that they are really a style of buttons. (BS_GROUPBOX).
Themed groupboxes (XP and later with classic mode off) use theme part BP_GROUPBOX in VSCLASS_BUTTON. You can use the usual theme APIs to get and draw. If your Group box needs text you can use DrawThemeText.
There are APIs for drawing non-themed group boxes too (e.g. DrawEdge), but I don't remember the details and it's unlikely that you need them.
As usual, I will point out that reproducing the behaviour of controls is always harder than you think it is going to be.
Martyn