我已经把一个RichEdit中的内容显示到View里了,但总是在字体大小不对。
例如,如果RichEdit为CSize(200,60),我显示的区域可能就是CSize(240,80),我不明白是为什么,显示的也是那些内容,就是不知道为什么所占的区域就是要比控件所占的区域大。
望各位高手能多多指点。
我的信箱是[email protected]

解决方案 »

  1.   

    CRichEditCtrl::FormatRange下面的代码来自 MSDN
    ------------------------
    Example// The pointer to my rich edit control.
    extern CRichEditCtrl* pmyRichEditCtrl;
    // A pointer to a printer DC.
    extern CDC* pMyPrinterDC;FORMATRANGE fr;// Get the page width and height from the printer.
    long lPageWidth = ::MulDiv(pMyPrinterDC->GetDeviceCaps(PHYSICALWIDTH),
        1440, pMyPrinterDC->GetDeviceCaps(LOGPIXELSX));
    long lPageHeight = ::MulDiv(pMyPrinterDC->GetDeviceCaps(PHYSICALHEIGHT),
        1440, pMyPrinterDC->GetDeviceCaps(LOGPIXELSY));
    CRect rcPage(0, 0, lPageWidth, lPageHeight);// Format the text and render it to the printer.
    fr.hdc = pMyPrinterDC->m_hDC;
    fr.hdcTarget = pMyPrinterDC->m_hDC;
    fr.rc = rcPage;
    fr.rcPage = rcPage;
    fr.chrg.cpMin = 0;
    fr.chrg.cpMax = -1;
    pmyRichEditCtrl->FormatRange(&fr, TRUE);// Update the display with the new formatting.
    RECT rcClient;
    pmyRichEditCtrl->GetClientRect(&rcClient);
    pmyRichEditCtrl->DisplayBand(&rcClient);