rt

解决方案 »

  1.   


    CDC* pDC = NULL;
    pDC = GetDC();
    ASSERT( pDC != NULL );
    CSize szText;
    szText = pDC->GetWindowExt( "Hello@!" );
    int nTextHeight = szText.cx;
    int nTextWidth  = szText.cy;//OK, Now you get you want !
      

  2.   

    pDC->GetWindowExt( "Hello@!" );
    是什么意思?
    另外如果我想先知道到size,后输出文本,可不可以?
      

  3.   

    GetWindowExt--------
    Retrieves the x- and y-extents of the window associated with the device context.
      

  4.   

    我想先知道到size,后输出文本,可不可以?
    象这样还得剪切.
      

  5.   

    CDC函数
    BOOL GetTextMetrics( LPTEXTMETRIC lpMetrics ) const;
      

  6.   

    CDC函数
    BOOL GetTextMetrics( LPTEXTMETRIC lpMetrics ) const;
      

  7.   

    typedef struct tagTEXTMETRIC {  /* tm */
        int  tmHeight;
        int  tmAscent;
        int  tmDescent;
        int  tmInternalLeading;
        int  tmExternalLeading;
        int  tmAveCharWidth;
        int  tmMaxCharWidth;
        int  tmWeight;
        BYTE tmItalic;
        BYTE tmUnderlined;
        BYTE tmStruckOut;
        BYTE tmFirstChar;
        BYTE tmLastChar;
        BYTE tmDefaultChar;
        BYTE tmBreakChar;
        BYTE tmPitchAndFamily;
        BYTE tmCharSet;
        int  tmOverhang;
        int  tmDigitizedAspectX;
        int  tmDigitizedAspectY;
    } TEXTMETRIC;在该结构里包含了很多有关字体的信息
      

  8.   

    GetTextExtentPoint32(hdc,szText,lstrlen(szText),&size);
    其中size.cx ,size.cy 即所求.
      

  9.   

    为什么我使用
    GetWindowText(hMemDC,m_text.GetWindowText(),lstrlen(m_text.GetWindowText()),mysize);时出错呢?
    error C2661 'GetWindowTestA':no overloader function takes 0 parameters.
      

  10.   

    我写的是GetTextExtentPoint32(hMemDC,m_text.GetWindowText(),lstrlen(m_text.GetWindowText()),mysize);出错.
      

  11.   

    对不起,是GetTextExtentPoint32(hMemDC,m_text.GetWindowText(),lstrlen(m_text.GetWindowText()),mysize);出的错.
      

  12.   

    GetTextExtentPoint(HDC hdc,
                       LPCTSTR lpstring,//你的字符串
                       int cbstring,//字符串的长度
                        LPSIZE lpsize)//结果
     应该可以,结果放在lpsize中。
      

  13.   

    你们都错了:)用win32 API DrawText(), 最后一个参数用DT_CALCRECT, 将不输出文字,而是返回字符串的长度和高度(像素),好好看看MSDN吧。