Alvaro Palma
2004-09-30 17:05:17 UTC
Is it possible to rotate text in a simple way inside a CDC object?
I added the next code in OnPaint for a CWnd object, but the text
still appears "normal". I tried setting the lfEscapament and lfOrientation
to 1, 9, 90, etc (both simultaneously), but nothing worked.
void CMyWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
....
CFont *pOldFont,*pCurFont,*pNewFont;
pNewFont = new CFont();
// Load the present font from the DC
pCurFont = dc.GetCurrentFont();
// Just change the orientation
LOGFONT logFont;
pCurFont->GetLogFont(&logFont);
logFont.lfEscapement = 90; // Rotate it 90 degrees
logFont.lfOrientation = 90;
// Create a new font using the current font properties, except the changed
orientation
BOOL b = pNewFont->CreateFontIndirect(&logFont);
// Put this new font
pOldFont = dc.SelectObject(pNewFont);
CString szText = "Text Rotated in 90 degrees";
dc.TextOut(100,100,szText);
// Restore the original font
dc.SelectObject(pOldFont);
delete pNewFont;
}
Thanks a lot for your attention
I added the next code in OnPaint for a CWnd object, but the text
still appears "normal". I tried setting the lfEscapament and lfOrientation
to 1, 9, 90, etc (both simultaneously), but nothing worked.
void CMyWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
....
CFont *pOldFont,*pCurFont,*pNewFont;
pNewFont = new CFont();
// Load the present font from the DC
pCurFont = dc.GetCurrentFont();
// Just change the orientation
LOGFONT logFont;
pCurFont->GetLogFont(&logFont);
logFont.lfEscapement = 90; // Rotate it 90 degrees
logFont.lfOrientation = 90;
// Create a new font using the current font properties, except the changed
orientation
BOOL b = pNewFont->CreateFontIndirect(&logFont);
// Put this new font
pOldFont = dc.SelectObject(pNewFont);
CString szText = "Text Rotated in 90 degrees";
dc.TextOut(100,100,szText);
// Restore the original font
dc.SelectObject(pOldFont);
delete pNewFont;
}
Thanks a lot for your attention