问题
I am trying to create my own Native win32 C++ Checkbox that can have a transparent background. The idea is to make the window/widget look exactly like the Windows XP style checkbox except that it can have a transparent background.
My Problem: When I draw the tick for my textbox, the 'tick' line looks pixelated and jagged - see my picture below for how it looks. It does not look smooth like the actual checkbox tick.
The left checkbox is mine, the right is the default windows one I am trying to replicate:

How can I make my tick smooth and not pixelated. What is a Win32 GDI function I could use to draw the tick. Should I use a bitmap image instead of drawing the tick in GDI? Currently I use PolylineTo() to draw the tick. Maybe I should use PolylineToEx()?
Any advice would be greatly appreciated.
Code for drawing the tick(this code is in WM_PAINT):
HGDIOBJ hPen = CreatePen(PS_SOLID, 2, RGB(45,45,45)); //ExtCreatePen(PS_COSMETIC, dwPenStyle[i], 1, &lb, 0, NULL);
HGDIOBJ hPenOld = SelectObject(hdc, hPen);
POINT tickPnts[3] = {{3,((height-CHECK_RECTH)/2)+6}, {5,((height-CHECK_RECTH)/2)+9}, {9,((height-CHECK_RECTH)/2)+2}};
MoveToEx(hdc, tickPnts[0].x, tickPnts[0].y, NULL);
PolylineTo(hdc, tickPnts, 3);
SelectObject(hdc, hPenOld);
DeleteObject(hPen);
回答1:
Windows uses the Marlett font to render checkbox ticks, the window frame buttons and other scalable UI elements. You can render the font with anti-aliasing to get smooth edges.
(This certainly used to be true anyway; I don't know for sure that the new window frame buttons in Windows 7 use the font, but the font still exists.)
GDI doesn't do any anti-aliasing, which is why your lines look jagged.
回答2:
The standard checkbox can be transparent. See this page for an example:
http://us.generation-nt.com/answer/transparent-background-color-checkbox-help-27571202.html
In Winforms you just set the background color as Transparent
.
来源:https://stackoverflow.com/questions/11011684/drawing-polyline-results-in-pixelated-line