MFC static text怎么添加下划线?   
添加:HBRUSH CTabDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
可以设置字体和颜色,但不知道怎么添加下划线。

解决方案 »

  1.   

    HBRUSH CStaticLink::CtlColor(CDC* pDC, UINT nCtlColor)
    {
        ASSERT(nCtlColor == CTLCOLOR_STATIC);
        DWORD dwStyle = GetStyle();
        
        HBRUSH hbr = NULL;
        if ((dwStyle & 0xFF) <= SS_RIGHT) {
            // this is a text control: set up font and colors
            if (!(HFONT)m_font) {
                // first time init: create font
                LOGFONT lf;
                GetFont()->GetObject(sizeof(lf), &lf);
                lf.lfUnderline = TRUE;//具有下划线的文字
                m_font.CreateFontIndirect(&lf);
            }        // use underline font and visited/unvisited colors
            pDC->SelectObject(&m_font);
            pDC->SetTextColor(m_color);        pDC->SetBkMode(TRANSPARENT);        // return hollow brush to preserve parent background color
            hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH);    }
        return hbr;
    }
      

  2.   

    我是这样写的,怎么添加下划线呢??
    HBRUSH CStrategy::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO:  在此更改 DC 的任何属性
    switch(pWnd->GetDlgCtrlID()) 

    case IDC_STATIC1: //设置静态static 标签背景透明
    pDC->SetBkMode(TRANSPARENT); 
    pDC->SetTextColor(RGB(255,0,0)); 
    return (HBRUSH)GetStockObject(HOLLOW_BRUSH); 
    case IDC_IDC_STATIC2:
    pDC->SetBkMode(TRANSPARENT); 
    pDC->SetTextColor(RGB(255,0,0)); 
    return (HBRUSH)GetStockObject(HOLLOW_BRUSH); 
    default: 
    break;
    } // TODO:  如果默认的不是所需画笔,则返回另一个画笔
    return hbr;
    }
      

  3.   

    自绘static,然后设置字体为带下划线就OK了。
      

  4.   


    CFont * f;  
    f = new CFont;  
    f->CreateFont(16, // nHeight  
    0, // nWidth  
    0, // nEscapement  
    0, // nOrientation  
    FW_BOLD, // nWeight  
    TRUE, // bItalic  
    TRUE, // bUnderline  
    0, // cStrikeOut  
    ANSI_CHARSET, // nCharSet  
    OUT_DEFAULT_PRECIS, // nOutPrecision  
    CLIP_DEFAULT_PRECIS, // nClipPrecision  
    DEFAULT_QUALITY, // nQuality  
    DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily  
    _T("Arial")); // lpszFac  
    CEdit *pCombox= (CEdit *)GetDlgItem(IDC_EDIT1);
    pCombox->SetFont(f);//具体设置f 对象参数值
    试试这个,CEdit改成你的static text
      

  5.   

    CStatic static;LOGFONT lf;
    GetLogFont(&lf);
    lf.lfUnderline = TRUE;static.SetFont(lf);
      

  6.   

    自绘CStatic,创建带下划线的字体,然后SetFont