CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    May 2000
    Location
    Southern Germany
    Posts
    213

    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;
    }

    }





  2. #17
    Join Date
    Oct 1999
    Location
    Broomfield, CO
    Posts
    3,382

    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.


  3. #18
    Join Date
    May 2000
    Location
    Southern Germany
    Posts
    213

    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.



  4. #19
    Join Date
    Oct 1999
    Location
    Broomfield, CO
    Posts
    3,382

    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."


Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured