在网上查了查,可以通过
pDC->DrawText(str,&rectstr,DT_LEFT |DT_CALCRECT);
pDC->DrawText(str,rectstr,DT_LEFT);
来获取文本的矩形面积。
但是这是在OnDraw函数里。
滚动条的设定是在OnInitialUpdate函数里。如何去改变滚动条参数?

解决方案 »

  1.   

    先算出需要大小 GetTextExtentPoint ,再调用 SetScrollRange ,参数查看msdn
      

  2.   

    初学MFC。还是有不懂的地方,请问:BOOL GetTextExtentPoint(
      HDC hdc,           // handle to DC
      LPCTSTR lpString,  // text string
      int cbString,      // number of characters in string
      LPSIZE lpSize      // string size
    );这不是获取STRING的大小的吗?这里需要知道的是STRING的高度?怎么弄?BOOL SetScrollRange(
      HWND hWnd,    // handle to window
      int nBar,     // scroll bar
      int nMinPos,  // minimum scrolling position
      int nMaxPos,  // maximum scrolling position
      BOOL bRedraw  // redraw flag
    );这里的nBar是滚动条吧?如何获得他的对象呢?
    最大位置和最小位置就是滚动条的范围吗?
      

  3.   


    void CTest1View::OnDraw(CDC* pDC)
    {
    CTest1Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    pDC->DrawText(str,&rectstr,DT_LEFT |DT_CALCRECT);
    pDC->DrawText(str,rectstr,DT_LEFT);
    }void CTest1View::OnFileOpen() 
    {
    // TODO: Add your command handler code here
    CFileDialog dlg(TRUE);
    if(IDOK==dlg.DoModal())
    {
    CFile file(dlg.GetFileName(),CFile::modeRead);
    DWORD len=file.GetLength();
    char *pbuf;
    pbuf=new char[len];
    pbuf[len]=0;
    file.Read(pbuf,len);
    file.Close();
    str=pbuf;
    }
    //UpdateWindow();
    SetScrollRange (SB_VERT,0,rectstr.bottom );
    Invalidate();
    }依然无法实现滚动条改变的功能
      

  4.   


    void CTest1View::OnDraw(CDC* pDC)
    {
    CTest1Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    pDC->DrawText(str,&rectstr,DT_LEFT |DT_CALCRECT);
    pDC->DrawText(str,rectstr,DT_LEFT);
    }void CTest1View::OnFileOpen() 
    {
    // TODO: Add your command handler code here
    CFileDialog dlg(TRUE);
    if(IDOK==dlg.DoModal())
    {
    CFile file(dlg.GetFileName(),CFile::modeRead);
    DWORD len=file.GetLength();
    char *pbuf;
    pbuf=new char[len];
    pbuf[len]=0;
    file.Read(pbuf,len);
    file.Close();
    str=pbuf;
    }
    //UpdateWindow();
    SetScrollRange (SB_VERT,0,rectstr.bottom );
    Invalidate();
    }