DrawText上下左右居中输出文字

来源:互联网 发布:dnf强行交易软件 编辑:程序博客网 时间:2024/04/30 12:15

CView OnDraw:设置字体,设置背景色,设置输出文字颜色,居中输出

// TODO: add draw code for native data hereCDocument* pDoc = GetDocument();CPaintDC* dc = (CPaintDC*)pDC;CRect rect;CBrush brush;brush.CreateSolidBrush(RGB(150,150,150));this->GetClientRect(&rect);dc->FillRect(&rect, &brush);brush.DeleteObject();CFont font;font.CreateFont(50, // nHeight0, // nWidth0, // nEscapement0, // nOrientationFW_NORMAL, // nWeightFALSE, // bItalicFALSE, // bUnderline0, // cStrikeOutANSI_CHARSET, // nCharSetOUT_DEFAULT_PRECIS, // nOutPrecisionCLIP_DEFAULT_PRECIS, // nClipPrecisionDEFAULT_QUALITY, // nQualityDEFAULT_PITCH | FF_SWISS,_T("Arial") // nPitchAndFamily Arial); pDC->SelectObject(&font);SetBkColor(pDC->m_hDC, RGB(150,150,150));//SetBkMode(pDC->m_hDC, TRANSPARENT);SetTextColor(pDC->m_hDC, RGB(255,0,0)); CString tout = "No Video!\nNo webcam or only one webcam!";CRect temp = rect;int height = pDC->DrawText(tout, temp, DT_CENTER | DT_WORDBREAK | DT_EDITCONTROL | DT_CALCRECT);rect.DeflateRect(0, (rect.Height() - height)/2);// change rect    pDC->DrawText(tout, rect, DT_CENTER | DT_WORDBREAK | DT_EDITCONTROL);



0 0
原创粉丝点击