|
|
【答案】应助回帖
★ ★ 御剑江湖: 金币+2, 谢谢 2012-06-30 18:45:24 jjdg: 编辑内容 2012-07-03 00:48 jjdg: 编辑内容 2012-07-03 00:49
示例代码:
//在CFormView视图中的GroupBox控件中画经度、纬度、高程变化走势图
void CvrpView:: DrawCordTrend()
{
CWnd* pWnd;
CString strFlag,str;
CRect rect;
CDC* pDC;
CPen pen,*pOldPen,pen2;
//画高程、经度、纬度变化走势图的画笔
CPen penAlti,penLong,penLati;
//画(无差分)高程、经度、纬度变化走势图的画笔
CPen penNAlti,penNLong,penNLati;
CBrush brush,*pOldBrush;
POINT ptOrig;
COLORREF crRef;
int i,iXNum,iYNum,iXStep,iYStep;
long iXCenter,iYCenter;
double dAltiMax,dAltiMin,dLongMax,dLongMin,dLatiMax,dLatiMin;
pWnd = (CStatic*)GetDlgItem( IDC_STATIC_TREND );
pWnd->Invalidate( );
pWnd->GetWindowRect(& rect );
pWnd->ScreenToClient(&rect);
rect.left += 18;//10
rect.top += 17; //15
rect.right -= 18;//10
rect.bottom -= 12; //10
ptOrig.x = rect.left;
ptOrig.y = ( rect.bottom + rect.top ) / 2 ;
iXCenter = ( rect.left + rect.right ) / 2 ;
iYCenter = ( rect.bottom + rect.top ) / 2 ;
pDC = pWnd->GetDC();
//背景透明
pDC->SetBkMode( TRANSPARENT );
//通用笔,灰白色
pen2.CreatePen(PS_SOLID,2,RGB(128,128,128) );
pen.CreatePen(PS_SOLID,1,RGB(0,126,0) );
//画高程曲线的笔
penAlti.CreatePen(PS_SOLID,2,RGB(255,0,0) );
//画经度曲线的笔
//penLong.CreatePen(PS_SOLID,2,RGB(0,255,0) );
penLong.CreatePen(PS_SOLID,2,RGB(200,200,0) );
//画纬度曲线的笔
penLati.CreatePen(PS_SOLID,2,RGB(0,0,255) );
//画(无差分)高程曲线的笔
penNAlti.CreatePen(PS_DOT,1,RGB(255,0,0) );
//画(无差分)经度曲线的笔
//penNLong.CreatePen(PS_DOT,1,RGB(0,255,0) );
penNLong.CreatePen(PS_DOT,1,RGB(200,200,0) );
//画(无差分)纬度曲线的笔
penNLati.CreatePen(PS_DOT,1,RGB(0,0,255) );
pOldPen = pDC->SelectObject(&pen2);
//刷子
brush.CreateSolidBrush( RGB( 255,255,255) );
pOldBrush = pDC->SelectObject( &brush);
pDC->FillRect( &rect,&brush );
//画边框
pDC->MoveTo( rect.left,rect.top );
pDC->LineTo( rect.left,rect.bottom );
pDC->LineTo( rect.right,rect.bottom );
pDC->LineTo( rect.right,rect.top );
pDC->LineTo( rect.left,rect.top );
//画X、Y轴
pDC->MoveTo( rect.left , ( rect.bottom + rect.top ) / 2 );
pDC->LineTo( rect.right, ( rect.bottom + rect.top ) / 2 );
pDC->TextOut( rect.left - 16,( rect.bottom + rect.top ) / 2 - 8 ,"00" );
pDC->TextOut( rect.right + 6 ,( rect.bottom + rect.top ) / 2 - 8 ,"X" );
pDC->TextOut( rect.right - 10 ,rect.bottom - 3 ,"108" ); //68
pDC->MoveTo( ( rect.left + rect.right ) / 2 , rect.top );
pDC->LineTo( ( rect.left + rect.right ) / 2 , rect.bottom );
pDC->TextOut( rect.left - 16,rect.top - 4 ,"26" ); //+8,14
pDC->TextOut( rect.left - 16 ,rect.bottom - 4 ,"-26" ); //-10,-8,-14
pDC->TextOut( ( rect.left + rect.right ) / 2 - 9,rect.bottom - 3 ,"54" ); //34
//画轴上的箭头
pDC->MoveTo( rect.right,( rect.bottom + rect.top ) / 2 );
pDC->LineTo( rect.right - 6,( rect.bottom + rect.top ) / 2 - 6 );
pDC->MoveTo( rect.right,( rect.bottom + rect.top ) / 2 );
pDC->LineTo( rect.right - 6,( rect.bottom + rect.top ) / 2 + 6 );
pDC->MoveTo( ( rect.left + rect.right ) / 2,rect.top );
pDC->LineTo( ( rect.left + rect.right ) / 2 - 6 ,rect.top + 6 );
pDC->TextOut( ( rect.left + rect.right ) / 2 + 9,rect.top ,"Y" ); //34
pDC->MoveTo( ( rect.left + rect.right ) / 2,rect.top );
pDC->LineTo( ( rect.left + rect.right ) / 2 + 6 ,rect.top + 6 );
//画一个点,第一象限45度角
pDC->SelectObject(&penNLati);
pDC->MoveTo( ( rect.left + rect.right ) / 2 , ( rect.bottom + rect.top ) / 2 );
pDC->LineTo(( rect.left + rect.right ) / 2 +(rect.right-rect.left)/2,( rect.bottom + rect.top ) / 2+( rect.top - rect.bottom ) / 2 );
pDC->MoveTo( ( rect.left + rect.right ) / 2 +(rect.right-rect.left)/4 ,( rect.bottom + rect.top ) / 2+( rect.top - rect.bottom ) / 4 );
pDC->TextOut(( rect.left + rect.right ) / 2 +(rect.right-rect.left)/4 ,( rect.bottom + rect.top ) / 2+( rect.top - rect.bottom ) / 4,"1(45)" );
pDC->SelectObject(&pen);
iXNum = 48;//32
iYNum = 25;//8,14
iXStep = ( rect.right - rect.left ) / ( 2 * iXNum );
iYStep = ( rect.bottom - rect.top ) / ( 2 * iYNum );
//画横轴栅格线
for ( i = 1;i < ( iYNum + 1 ); i ++)
{
pDC->MoveTo( rect.left, iYCenter - i * iYStep );
pDC->LineTo( rect.right, iYCenter - i * iYStep );
pDC->MoveTo( rect.left, iYCenter + i * iYStep );
pDC->LineTo( rect.right, iYCenter + i * iYStep );
}
//画纵轴栅格线
for ( i = 1;i < ( iXNum + 6 ); i ++) //12
{
pDC->MoveTo( iXCenter - i * iXStep, rect.top );
pDC->LineTo( iXCenter - i * iXStep, rect.bottom );
if ( !( i % 18 ) ) //17
{
str.Format("%02d",i);
//pDC->TextOut( iXCenter - i * iXStep - 8,rect.bottom - 3 ,str);
pDC->TextOut( i * iXStep - 4,rect.bottom - 3 ,str);
str.Format("%02d",( 108 - i ) );
pDC->TextOut( rect.right - i * iXStep - 6,rect.bottom - 3 ,str);
}
pDC->MoveTo( iXCenter + i * iXStep, rect.top );
pDC->LineTo( iXCenter + i * iXStep, rect.bottom );
}
.................
//恢复系统原来的画笔
pDC->SelectObject( pOldPen );
pDC->SelectObject( pOldBrush );
ReleaseDC( pDC );
pDC = NULL;
}
[ Last edited by jjdg on 2012-7-3 at 00:49 ] |
|