-
March 21st, 2005, 04:10 AM
#1
SetFont vs ListCtrl
i'm trying set different font to listctrl
(to keep it's row height independent to small-large fonts settings)
but
i found when i in OnCreate set the same font as actualy is selected
than in DrawItem i receive absolutely different one
(tahoma/400-weight from OnCreate changes to system/700 in DrawiItem)
(also my change in DrawItem - see down - has no influence)
any ideas what i'm doing wrong?
any good example for me (to keep my old DrawItem code)?
thanks
(i'm using some tricks from
http://www.codeproject.com/listctrl/changerowheight.asp
but seems my OnSetFont and MeasureItem have no infulence to my problem)
CMyListCtrl::OnCreate
{
if(CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
LOGFONT olf;
GetFont()->GetLogFont(&olf);
CFont NewFont;
if(NewFont.CreateFontIndirect(&olf))
{
LOGFONT nlf;
NewFont.GetLogFont(&nlf);
m_pOldFont = GetFont();
SetFont(&NewFont);
}
}
CNemAttributesListCtrl:: DrawItem
{
CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
CFont *pOldFont = pDC->SelectObject(GetFont());
LOGFONT olf;
//here will be ret==0: int ret = GetFont()->GetLogFont(&olf);
pDC->GetCurrentFont()->GetLogFont(&olf);
...
}
p.s.
i want to keep headerctrl height too
but with
CHeaderCtrl* pHeaderCtrl = GetHeaderCtrl();
pHeaderCtrl->SetFont(&NewFont);
into listctrl OnCreate is h-ctrl's size ok but text inside is bit down
(= it seems text left-bottom position does not change with SetFond)
Last edited by real name; March 21st, 2005 at 04:22 AM.
-
March 21st, 2005, 04:30 AM
#2
Re: SetFont vs ListCtrl
CMyListCtrl::OnCreate
{
if(CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
LOGFONT olf;
GetFont()->GetLogFont(&olf);
CFont NewFont;
if(NewFont.CreateFontIndirect(&olf))
{
LOGFONT nlf;
NewFont.GetLogFont(&nlf);
m_pOldFont = GetFont();
SetFont(&NewFont);
}
}
This question has been asked zillions of times. Same error, same behaviour. You cannot use a local font variable to set the font of a control. When OnCreate() returns the NewFont goes out of scope, so obviously the font you sent is not used. Make NewFont a member of the class, so it won't go out of scope, until the object is destroyed.
Please read this FAQ.
-
March 21st, 2005, 04:34 AM
#3
Re: SetFont vs ListCtrl
in first moment surprised because i was looking at
_AFXWIN_INLINE CFont::~CFont()
{ }
so it seems it must stay
will try and react again soon
-
March 21st, 2005, 04:40 AM
#4
Re: SetFont vs ListCtrl
aha
_AFXWIN_INLINE CGdiObject::~CGdiObject()
{ DeleteObject(); }
my shame
thanks cilu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|