新手求助:如何在对话框中创建直角坐标系
新手求助:如何在对话框中创建直角坐标系,详细的步骤,本人是新手。
/* * 绘制坐标轴(x,y) MM_TEXT */ void CSpaceDlg::DrawAXis(CDC& dc) { CRect rectClient; GetClientRect(rectClient); // 坐标轴长度 INT nXLength = rectClient.Width() - 20; INT nYLength = rectClient.Height() - 20; INT nxUnit = 10; // 单位 INT nyUnitHeidht = 5; /* 绘制横轴 */ dc.MoveTo(0, 0); dc.LineTo(nXLength, 0); /* 绘制X箭头 */ dc.MoveTo(nXLength, 0); dc.LineTo(nXLength - 5, - 5); dc.MoveTo(nXLength, 0); dc.LineTo(nXLength - 5, 5); /* 绘制X轴刻度 */ for (int i = 0; i < nXLength / nxUnit; ++i) { dc.MoveTo(i * nxUnit, 0); dc.LineTo(i * nxUnit, -nyUnitHeidht); } /* 绘制纵轴 */ dc.MoveTo(0, 0); dc.LineTo(0, -nYLength); /* 绘制Y箭头 */ dc.MoveTo(0, -nYLength); dc.LineTo(-5, -nYLength + 5); dc.MoveTo(0, -nYLength); dc.LineTo(5, -nYLength + 5); /* 绘制Y轴刻度 */ for (i = 0; i < nYLength / nxUnit; ++i) { dc.MoveTo(0, -i * nxUnit); dc.LineTo(nyUnitHeidht, -i * nxUnit); } }
void CSpaceDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); } else { CRect rect; GetClientRect(&rect); CPaintDC dc(this); /*--------------------------------------*/ /* 绘制坐标系 */ /*--------------------------------------*/ // 设置坐标系原点 POINT pntOrg = {15, rect.Height() - 15}; dc.SetViewportOrg(pntOrg); DrawAXis(dc); CDialog::OnPaint(); } }