How to create round rectangular buttons in WM6?

Yes, such pretty buttons on iPhone.;)

I've searched and read for days and every time I find something that closes me (like CreateRoundRectRgn) it blows up because Windows Mobile 6 GDI + doesn't support it.

I can make the whole host draw a thing and the like. But how do I draw those hard corners and change the button?: /

Note. Available tools: Native Win32 only (no MFC)


This thought happened to me, but it leaves two problems:

1) Will the bitmap with rounded edges leave visible corners of the button.

2) Bitmaps are great for fixed screen sizes. But with multiple resolutions, my goal is to dynamically create button bitmaps in memory at runtime and use them that way.

I have a work with square buttons. However, I've seen rounded buttons used by other software. There should be a way to change the buttons.

0


source to share


2 answers


Obtaining such simple buttons is usually accomplished by creating a complete owner-drawn button and drawing an image created for him by a graphic designer, instead of letting GDI do some kind of control picture. You just need an image for "up" and an image for "clicked". You can manually draw the focus, or use another ROP mask image to paint it on the button. To get nice "rounded" effects, you simply create an image with a background color, which is then used as the transparency color.



The tee scaling issue is somewhat unique to WinMo as the iPhone really only has one resolution. If you need to tweak different WinMo devices with resolution, you can do one of two things (which you use depends on the images you use). Eitehr simply draws a scalable image or includes different versions of the images and decides at runtime which are used based on screen resolution.

+2


source


You can use the RoundRect GDI function to do this on an owner managed.

//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 a little more interesting, like filling it with a gradient, you can paint your gradient into an off-screen buffer and use CreatePatternBrush to paint from it.

+1


source







All Articles