-
September 28th, 2000, 07:37 AM
#16
Re: What is wrong with my code?
I have tried the following code in my OnCustomDraw function.
The cells with the WingDing font have their text marked with a flag "<WD>" which I drop before drawing the text.
I have 3 problems with the code:
1. The Wingding columns flicker constantly except for the first column.
2. The Wingding font doesn't convert the 'ü' character. This should be a checkmark.
3. The "<WD>" flag is not dropped.
I appreciate any help.
void CReportListCtrl::OnCustomDraw(NMHDR *pNMHDR, LRESULT *pResult)
{
bool bWD = false;
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
CDC dc;
if (!m_font_created)
{
// need to create the wing ding font
LOGFONT lf ;
GetFont()->GetLogFont(&lf) ; // get current font settings
m_OldFont.CreateFontIndirect(&lf);
strcpy(lf.lfFaceName, "WingDings") ; // switch to wing dings
lf.lfCharSet = SYMBOL_CHARSET;
m_WingDing.CreateFontIndirect(&lf) ;
m_font_created = true ;
}
int iCol = lplvcd->iSubItem;
int iRow = lplvcd->nmcd.dwItemSpec;
CString CellText = GetItemText(iRow, iCol);
if (CellText.Find("<WD>",0) == 0)
{
CellText.Right(CellText.GetLength() - 4);
SetItemText(iRow, iCol, CellText);
bWD = true;
}
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW; // ask for subitem notifications.
break;
case CDDS_ITEMPREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW; // ask for subitem notifications.
break;
case CDDS_ITEMPREPAINT|CDDS_SUBITEM: // recd when CDRF_NOTIFYSUBITEMDRAW is returned in
{ // response to CDDS_ITEMPREPAINT.
*pResult = CDRF_DODEFAULT;
if (bWD)
{
dc.Attach(lplvcd->nmcd.hdc);
dc.SelectObject(m_WingDing);
dc.Detach();
*pResult = CDRF_NEWFONT;
}
else
{
dc.Attach(lplvcd->nmcd.hdc);
dc.SelectObject(m_OldFont);
dc.Detach();
*pResult = CDRF_DODEFAULT;
}
break;
}
default:// it wasn't a notification that was interesting to us.
*pResult = CDRF_DODEFAULT;
}
}
-
October 2nd, 2000, 10:28 AM
#17
Re: What is wrong with my code?
I suspect it has something to do with the calling of SetItemText inside the drawing routine. The control already knows what it has to draw by the time it gets to your custom draw code, so your changing of the text probably causes a redraw.
-
October 4th, 2000, 09:39 AM
#18
Re: What is wrong with my code?
I eliminated the problem of the "ü","ä" and "ö" characters not being converted to Wingdings by not specifying "Wingdings" as the font name, only the charset as WM_CHARSET. This may be because my keyboard is German and the layout is different.
I still have a problem with this code, however:
CString CellText = GetItemText(iRow, iCol);
if (CellText.Find("<WD>",0) == 0)
{
CellText.Right(CellText.GetLength() - 4);
SetItemText(iRow, iCol, CellText);
bWD = true;
}
It switches to Wingdings, but doesn't drop the "<WD>" flag.
If I shouldn't call SetItemText within this function, then what is my alternative?
I have solved the problem without using the <WD> flag, and my function works, so it is not too important (other than for my own knowledge.)
Thank you for the tip about using CustomDraw. It was much more practical in this case than DrawItem.
-
October 4th, 2000, 02:48 PM
#19
Re: What is wrong with my code?
>> If I shouldn't call SetItemText within this function, then what is my alternative?
>> I have solved the problem without using the <WD> flag, and my function works...
Sounds like you answered your own question. My reply would have been, "Find some way to indicate the need to do the WingDing font without prepending <WD> to the item text."
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
|