DrawText 第一次是计算的矩形 第二次才开始画

CString strCar;
 strCar.Format(_T("ID:%s \n單位名稱:%s \n經度:%d \n緯度:%d \n速度:%d"),pci->gpsno,pci->carno,pci->pos.lon,pci->pos.lat,pci->pos.speed);
 //CString strCarNo;
 //strCarNo.Format(_T("單位名稱:%s \n"),pci->carno);
 //CString strLongt;
 //strLongt.Format(_T("經度:%d \n"),pci->pos.lon);
 //CString strLat;
 //strLat.Format(_T("緯度:%d \n"),pci->pos.lat);
 //CString strSpeed;
 //strSpeed.Format(_T("速度:%d"),pci->pos.speed);
 //SIZE sz;
 //::GetTextExtentPoint32(hdc,strCar,strCar.GetLength(),&sz);
 CRect rcText;
 int nHeight = ::DrawText (hdc,strCar,strCar.GetLength(), &rcText, DT_CALCRECT| DT_NOPREFIX);
 int nWidth = rcText.Width ();
 rcText.SetRect(0,0,nWidth,nHeight);
 rcText.OffsetRect(pt);
 rcText.OffsetRect(-rcText.Width()*0.5,-rcText.Height()-20);
 //CRect rcText(pt.x - 60,pt.y - sz.cy*5 - 15,pt.x + 60,pt.y-14);
 CRect rcBack(rcText);
 rcBack.InflateRect(2,2);
 ::Rectangle(hdc,rcBack.left,rcBack.top,rcBack.right,rcBack.bottom);
 ::DrawText(hdc,strCar,strCar.GetLength(),rcText,DT_LEFT|DT_NOCLIP);

posted @ 2011-08-11 15:35  银翼的魔术师  阅读(250)  评论(0编辑  收藏  举报