如题、作一个大小需要根据显示的文字内容而改变的对话框、
文字是一个CStatic控件、可能是英文、中文等有多种情况
85+10*5.5:主要是这里、85是除CStatic外的合适长度、5.5是自己测试过来的大约一个字符的长度、
一个中文按两个字符的长度算、但实际显示上长度计算还是不准、请问有什么更科学的方法?------------------------------------------------------------
m_dlgTip = new FDlgTooltip(this);
m_dlgTip->setValue(_T("1234567890"));
m_dlgTip->Create(IDD_DIALOG_TIP, theApp.m_pMainWnd);
m_dlgTip->SetWindowPos(theApp.m_pMainWnd,pos.x-5,pos.y-5,85+10*5.5,60,0);
m_dlgTip->ShowWindow(SW_SHOW);

解决方案 »

  1.   

    好像GetTextMetrics(好像是这么写的,记不太清了)可以得到文本的文字数据。
      

  2.   

    看看MSDN中CDC类的Text Functions,找适合你的函数。
      

  3.   

    GetTextExtent,计算前要选把你屏幕字体选进设备描述表
      

  4.   

    GetTextExtent
    GetTextExtent
    GetTextExtent
    GetTextExtent
    GetTextExtent
    GetTextExtent
    GetTextExtent
    GetTextExtent
    GetTextExtent
    这个函数搞定你的问题
      

  5.   

    GetTextExtentPoint32 (hdc, szText, lstrlen (szText), &size) ;
      

  6.   

    OK--结贴
    CDC* hdc = new CDC(); // 设备描述表句柄
    hdc->CreateCompatibleDC(NULL);
    hdc->SelectObject(GetListCtrl().GetFont());
    CSize size1 = hdc->GetTextExtent(type);
    CSize size2 = hdc->GetTextExtent(src);
    CSize size3 = hdc->GetTextExtent(dest);
    delete(hdc);