has
asked on
I cant get the font correct ?
I have a CWnd drived window that has a
pointer to a CComboBox m_pCBox.
and a CFont* pointer m_pFont.
in construction, I get it as:
CDC* pCBoxpDC = m_pCBox->GetDC();
m_pFont = pCBoxpDC->GetCurrentFont() ;
m_pCBox->ReleaseDC(pCBoxpD C);
and use it in the windows paint as:
void CNewWnd::OnPaint()
{
CPaintDC dc(this);
dc.SetBkMode(TRANSPARENT);
CRect rc;
GetClientRect(rc);
CFont* pFont = dc.SelectObject(m_pFont);
dc.DrawText(_T("text"), rc, DT_LEFT);
dc.SelectObject(pFont);
}
But text shows bold (darker and ticker
than the combo text)
pointer to a CComboBox m_pCBox.
and a CFont* pointer m_pFont.
in construction, I get it as:
CDC* pCBoxpDC = m_pCBox->GetDC();
m_pFont = pCBoxpDC->GetCurrentFont()
m_pCBox->ReleaseDC(pCBoxpD
and use it in the windows paint as:
void CNewWnd::OnPaint()
{
CPaintDC dc(this);
dc.SetBkMode(TRANSPARENT);
CRect rc;
GetClientRect(rc);
CFont* pFont = dc.SelectObject(m_pFont);
dc.DrawText(_T("text"), rc, DT_LEFT);
dc.SelectObject(pFont);
}
But text shows bold (darker and ticker
than the combo text)
The CFont* returned by CDC::GetCurrentFont may be a temporary object, meaning that you can't use it out of scope of a message. Try moving the code into the OnPaint.
ASKER
no luck with this
OnPaint()
{
CDC* pCBoxpDC = m_pCBox->GetDC();
CPaintDC dc(this); // device context for painting
dc.SetBkMode(TRANSPARENT);
CRect rc;
GetClientRect(rc);
CFont* pFont = dc.SelectObject(pCBoxpDC-> GetCurrent Font());
dc.DrawText(m_tip, rc, DT_LEFT);
dc.SelectObject(pFont);
m_pCBox->ReleaseDC(pCBoxpD C);
}
OnPaint()
{
CDC* pCBoxpDC = m_pCBox->GetDC();
CPaintDC dc(this); // device context for painting
dc.SetBkMode(TRANSPARENT);
CRect rc;
GetClientRect(rc);
CFont* pFont = dc.SelectObject(pCBoxpDC->
dc.DrawText(m_tip, rc, DT_LEFT);
dc.SelectObject(pFont);
m_pCBox->ReleaseDC(pCBoxpD
}
Does CDC::GetCurrentFont return non-NULL? If so, get the font information with CFont::GetLogFont. Then, create your own font object with theLOGFONT structure returned.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>it restore original font(system font) after it finished drawing.
liaobin is on the right track. I feel that I was stupid.
liaobin is on the right track. I feel that I was stupid.
ASKER
Are you telling me that there is a
GetFont() of CDC, or ?? how do I
solve the problem then ??
GetFont() of CDC, or ?? how do I
solve the problem then ??
GetFont is a member function of CWnd.
ASKER
Thanks to both of you.
ASKER
text font is very different.