在窗体中显示的文本需要根据文本的大小显示窗体

解决方案 »

  1.   

    size_t strlen( const char *string );
    BOOL GetCharWidth(
      HDC hdc,         // handle to DC
      UINT iFirstChar, // first character in range
      UINT iLastChar,  // last character in range
      LPINT lpBuffer   // buffer for widths
    );
    DWORD GetFileSize(
      HANDLE hFile,           // handle to file
      LPDWORD lpFileSizeHigh  // high-order word of file size
    );
      

  2.   

    FILE *fp;
    fp = fopen("你的文本的全路径","r");
    int n = 0;
    while(!feof(fp))
    {
        fgetc(fp);
        n++;
    }
    rewind(fp);
    fclose(fp);
    return n-1;//n-1为文本大小
      

  3.   

    不明白你的意思,如果直接取得文本的大小,可以这样:
    int nFileLength;
    CFile file;
    CFileException e;
    if(!file.open(filePath,CFile::modeRead,&e)
    {
    //错误处理
    }
    nFileLength=file.GetLength;
      

  4.   

    CFile file;
    int i=file.GetLengh();
      

  5.   

    最近正在做这种程序
    CRect CDrawText::Count_Size(CString aqie)
    {CMainFrame *pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd;
    CGraphView *pView=(CGraphView *)pMain->GetActiveView();
    CDC* pDC =pView->GetDC();
    CFont font;
    LOGFONT m_logfonttemp;
    m_logfonttemp=m_logfont;
    m_logfonttemp.lfHeight=CountHeight(m_logfonttemp.lfHeight);
    font.CreateFontIndirect(&m_logfonttemp);
    CFont *pFont=pDC->SelectObject(&font);//字体要和Draw中子体一杨
    pDC->SetMapMode(MM_HIMETRIC);
    CString tempString;
    CString string;
    CString findstring("\n" );
    CSize haha;
    CSize TotalSize = CSize(0,0); CRect aa = Size_Of_Text;
    int hang = 0,j = 0,line = 0,lie = 0;
    string = aqie;
    if(!string.IsEmpty())
    {
    line = string.GetLength();
    j = string.Find( findstring);
    while(j != -1)
    {hang = j;
    tempString = string.Left( j );
    string = string.Right( line-j-1 );
    line = line-j-1;
    j = string.Find( findstring );
    if(hang<j) hang = j;
    lie++;
    haha = pDC->GetTextExtent(tempString);
    TotalSize = AddToMySize(TotalSize,haha);
    }
    if((j == -1)&&(lie == 0))
    {haha = pDC->GetTextExtent(string);
    Size_Of_Text = CRect(aa.TopLeft(),haha);
    }
    else if((j == -1)&&(lie != 0))
    {haha = pDC->GetTextExtent(string);
    TotalSize = AddToMySize(TotalSize,haha);
    Size_Of_Text = CRect(aa.TopLeft(),TotalSize);
    }
    }
    else{
    Size_Of_Text = CRect(0,0,0,0);
    }
    pDC->SelectObject(pFont);
    font.DeleteObject();

    pView->ReleaseDC(pDC);//释放DC资源
    return Size_Of_Text;

    }CSize CDrawText::AddToMySize(CSize total, CSize add)
    {CSize T1;
    T1 = total;
    if(T1.cx<add.cx)
    T1.cx = add.cx;
    T1.cy += add.cy+1;
    return T1; }
    可得到文本区域的大小