<!-- Article image -->
<!-- Add the rest of your HTML here -->
CPolyBtn is a simple
CButton derivative that allows
you to create buttons that aren't rectangles or circles or any other typical
geometric shape; with
CPolyBtn, you specify the button shape by
providing a series of points that define a polygon.
What can it do?
does all of the
normal button stuff: rollovers, bitmaps, tooltips, focus colors, fill colors,
disabled colors, etc..
How can I use it?
You create a button on your dialog, then create a
member variable of type
. You know, the standard
stuff. Then, in your CDialog's
you create a
objects, one for each polygon
point, where the points are arranged in clockwise order
, then assign the
vector to the
determine highlight and shadow colors for each edge, set up the regions and
handle everything else.
const int triEdgeSize = 16;
m_zoomInBtn.SetBMPID(IDB_ZOOM_IN, RGB(255,255,255), IDB_ZOOM_IN_DISABLED,
At this point, you can also add bitmaps, set text positions, etc..
For those of you who demand control,
provides a way for you to specify the colors for each edge manually (normal,
highlight, focused, disabled, etc..). This method takes more work, of course.
But if you need that much control, the option is there.
void SetColors(COLORREF highlight, COLORREF down, COLORREF focus,
COLORREF disabled, COLORREF rollover);
void SetFillColor(COLORREF fillClr);
void SetBMPOffset(int x, int y);
void SetTextOffset(int x, int y);
void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE);
void ActivateTooltip(BOOL bEnable = TRUE);
void AllowHighlightOnGtrNeg45(bool b);
void AllowRollover(bool b);
In general, I'm not crazy about the way the edges are drawn.
Because there's no good way to shrink a polygon, it's hard to draw the button
edge like a normal button where the edges are actually two parallel lines, with
different colors. So, the edges here are always a single pixel wide. Another
example of where this is an issue is in the "focus" rendering: normally, button
focus is indicated by drawing a dashed rectangle inside the border. But, since
there's no simple way to determine what 'inside' means for all arbitrary
doesn't bother; it handles focus by
drawing the edges with the
pen style. (sure,
there are complex ways to find the inside of a polygon, but that's more work
than i wanted to put into this, and i didn't need it anyway).
If you come up with any improvements on this, feel free to
And remember, be excellent to each other.