Yes, like those pretty buttons on the iPhone. ;)
是的,就像iPhone上漂亮的按钮一样。 ;)
I've been searching and reading for days now and everytime I find something that will get me close (like CreateRoundRectRgn), it blows up because Windows Mobile 6 GDI+ doesn't support it.
我一直在搜索和阅读几天,每当我发现一些让我接近的东西(比如CreateRoundRectRgn)时,它会爆炸,因为Windows Mobile 6 GDI +不支持它。
I can do the whole owner draw thing and such. But how do I curve those hard corners and reshape a button? :/
我可以做整个所有者画事物等。但是我如何弯曲那些硬角并重塑一个按钮呢? :/
Note Tools available: Native Win32 only (no MFC)
注意可用工具:仅限本机Win32(无MFC)
That thought has occured to me, but it leaves two issues:
这个想法发生在我身上,但它留下了两个问题:
1) Won't the bitmap with rounded edges still leave the corners of the button visible.
1)带有圆边的位图是否仍然会使按钮的角可见。
2) Bitmaps are great for fixed screen size. But having a variety of resolutions, my goal is to dynamically create the button bitmap in memory at run-time and use it that way.
2)位图非常适合固定屏幕尺寸。但是有各种各样的分辨率,我的目标是在运行时在内存中动态创建按钮位图并以这种方式使用它。
I've got it working with square buttons. Yet I have seen rounded edge buttons used by other software. There must be a way to reshape buttons.
我已经用方形按钮了。但我见过其他软件使用的圆边按钮。必须有一种方法来重塑按钮。
2 个解决方案
#1
2
Getting pretty buttons like that is typically done by doing a complete owner-drawn button and drawing an image that a graphic designer created to it rather than letting GDI do any of the control painting. You simply need an image for "up" and an image for "pressed". You can manually draw in the focus or use yet another image with a ROP mask to draw it on the button as well. To get the nice "rounded" effects, you simply create the image with a background color that you then use as a transparency color.
获得这样漂亮的按钮通常是通过完成所有者绘制的按钮并绘制图形设计者为其创建的图像而不是让GDI进行任何控制绘画来完成的。你只需要一个“up”图像和一个“按下”图像。您可以手动绘制焦点或使用带有ROP蒙版的另一个图像也可以在按钮上绘制它。要获得漂亮的“圆角”效果,只需使用背景颜色创建图像,然后将其用作透明度颜色。
Tee scaling issue is somewhat unique to WinMo, since iPhone really has only one resolution. If you need to target different resolution WinMo devices you can do one of 2 things (which you use depends on the images you're using). Eitehr just draw the image scaled, or include different size versions of the images and decide at runtime which to use based on screen resolution.
Tee扩展问题对于WinMo来说有点独特,因为iPhone实际上只有一个分辨率。如果您需要针对不同分辨率的WinMo设备,您可以执行以下两项操作之一(您使用的内容取决于您正在使用的图像)。 Eitehr只是绘制缩放的图像,或包含不同大小的图像版本,并在运行时根据屏幕分辨率决定使用哪个版本。
#2
1
You can use the RoundRect GDI function to do it on an owner drawn control.
您可以使用RoundRect GDI函数在所有者绘制的控件上执行此操作。
//Set up a brush and pen
HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0));
HPEN pen = CreatePen(PS_SOLID, 1, RGB(0, 255, 0));
//Select it
HGDIOBJ old_brush = SelectObject(hdc, brush);
HGDIOBJ old_pen = SelectObject(hdc, pen);
//Draw your rectangle
RoundRect(hdc, m_rect.left, m_rect.top, m_rect.right, m_rect.bottom, 10, 10);
//restore the old state of your HDC
SelectObject(hdc, old_brush);
SelectObject(hdc, old_pen);
//Clean up
DeleteObject(brush);
DeleteObject(pen);
If you want to do something fancier like filling it with a gradient you can draw your gradient to an off screen buffer and use CreatePatternBrush to draw from it.
如果你想做一些更漂亮的事情,比如用渐变填充它,你可以将渐变绘制到屏幕外缓冲区并使用CreatePatternBrush从中绘制。
#1
2
Getting pretty buttons like that is typically done by doing a complete owner-drawn button and drawing an image that a graphic designer created to it rather than letting GDI do any of the control painting. You simply need an image for "up" and an image for "pressed". You can manually draw in the focus or use yet another image with a ROP mask to draw it on the button as well. To get the nice "rounded" effects, you simply create the image with a background color that you then use as a transparency color.
获得这样漂亮的按钮通常是通过完成所有者绘制的按钮并绘制图形设计者为其创建的图像而不是让GDI进行任何控制绘画来完成的。你只需要一个“up”图像和一个“按下”图像。您可以手动绘制焦点或使用带有ROP蒙版的另一个图像也可以在按钮上绘制它。要获得漂亮的“圆角”效果,只需使用背景颜色创建图像,然后将其用作透明度颜色。
Tee scaling issue is somewhat unique to WinMo, since iPhone really has only one resolution. If you need to target different resolution WinMo devices you can do one of 2 things (which you use depends on the images you're using). Eitehr just draw the image scaled, or include different size versions of the images and decide at runtime which to use based on screen resolution.
Tee扩展问题对于WinMo来说有点独特,因为iPhone实际上只有一个分辨率。如果您需要针对不同分辨率的WinMo设备,您可以执行以下两项操作之一(您使用的内容取决于您正在使用的图像)。 Eitehr只是绘制缩放的图像,或包含不同大小的图像版本,并在运行时根据屏幕分辨率决定使用哪个版本。
#2
1
You can use the RoundRect GDI function to do it on an owner drawn control.
您可以使用RoundRect GDI函数在所有者绘制的控件上执行此操作。
//Set up a brush and pen
HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0));
HPEN pen = CreatePen(PS_SOLID, 1, RGB(0, 255, 0));
//Select it
HGDIOBJ old_brush = SelectObject(hdc, brush);
HGDIOBJ old_pen = SelectObject(hdc, pen);
//Draw your rectangle
RoundRect(hdc, m_rect.left, m_rect.top, m_rect.right, m_rect.bottom, 10, 10);
//restore the old state of your HDC
SelectObject(hdc, old_brush);
SelectObject(hdc, old_pen);
//Clean up
DeleteObject(brush);
DeleteObject(pen);
If you want to do something fancier like filling it with a gradient you can draw your gradient to an off screen buffer and use CreatePatternBrush to draw from it.
如果你想做一些更漂亮的事情,比如用渐变填充它,你可以将渐变绘制到屏幕外缓冲区并使用CreatePatternBrush从中绘制。