views:

1558

answers:

4

Yes, like those pretty buttons on the 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.

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)

+1  A: 

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.

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.

ctacke
A: 

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.

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.

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.

Sebastian Dwornik
Use a comment, not an answer, if one gets voted up/down the order changes and it no longer is clear what the "answer" you posted was to.
ctacke
1. No, if you paint the whole thing you use a transpartency for the "corners"2. Bitmaps can scale, you can also use different ones. You can create a shaped window, but it's way more trouble than it's worth and it still looks "flat". Images are how almost all good-looking UIs work.
ctacke
I forgot about the transparency thing. I'll try it.Now how do I vote for just a "comment" or signal a comment as an accepted answer? Or the whole answer with the comments now get clumped together. :/
Sebastian Dwornik
I'll move the comment up to the answer to make it more detailed.
ctacke
A: 

You can use the RoundRect GDI function to do it on an owner drawn control.

//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.

A: 

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.

Anyone got an example of using this? I've tried CreateBitmap and then render a gradient to it, I can display the bitmap on its own but when I use that in CreatePatternBrush I only get black rendered.

mtopley