GDI+ text display
void CGdiplusDemoView::OnDraw(CDC* pDC)
{
Graphics g(pDC->m_hDC);
CRect rect;
GetClientRect(rect);
WCHAR string[] = L"Hi, I'm a man who used XT long time ago";
/*
enum FontStyle
{
FontStyleRegular = 0,
FontStyleBold = 1,
FontStyleItalic = 2,
FontStyleBoldItalic = 3,
FontStyleUnderline = 4,
FontStyleStrikeout = 8
};
enum Unit
{
UnitWorld, // 0 -- World coordinate (non-physical unit)
UnitDisplay, // 1 -- Variable -- for PageTransform only
UnitPixel, // 2 -- Each unit is one device pixel.
UnitPoint, // 3 -- Each unit is a printer's point, or 1/72 inch.
UnitInch, // 4 -- Each unit is 1 inch.
UnitDocument, // 5 -- Each unit is 1/300 inch.
UnitMillimeter // 6 -- Each unit is 1 millimeter.
};
*/
// Create font
FontFamily fontFamily(L"Arial");
Font font(&fontFamily, 24, FontStyleBold, UnitPixel);
// Create brush
SolidBrush brush(Color(255, 0, 0, 255));
// Center alignment
StringFormat stringFormat;
stringFormat.SetAlignment(StringAlignmentCenter);
stringFormat.SetLineAlignment(StringAlignmentCenter);
// Display text in the middle of the window
PointF pointF(rect.Width()/2, rect.Height()/2);
g.DrawString(string, (INT)wcslen(string), &font, pointF, &stringFormat, &brush);
// Adjust display quality
g.SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
// Display text int the middle of the rectangle
RectF rectF(300, 20, 200, 100);
g.DrawString(string, (INT)wcslen(string), &font, rectF, &stringFormat, &brush);
Pen pen(Color(255, 255, 0, 0));
g.DrawRectangle(&pen, rectF);
}
댓글 없음:
댓글 쓰기