新建 MFC 项目,图片控件 ID 设置为 IDC_DRAW。
添加开始按钮,ID 设置为 IDC_START。
//.cpp
<pre name="code" class="cpp">void CMFC_DRAWDlg::frame_draw()
{
CRect rect;
CDC * pDC;
CWnd * pwnd;
pwnd = GetDlgItem(IDC_DRAW);
pDC = pwnd->GetDC();
pwnd->GetWindowRect(&rect);
int x = rect.right - rect.left;
int y = rect.bottom - rect.top;
pDC->MoveTo(40, y-40);
pDC->LineTo(x-20, y-40);
pDC->LineTo(x-25, y-35);
pDC->MoveTo(x-20, y-40);
pDC->LineTo(x-25, y-45);
pDC->MoveTo(40, y-40);
pDC->LineTo(40, 20);
pDC->LineTo(35, 25);
pDC->MoveTo(40, 20);
pDC->LineTo(45, 25);
// X-axis paint
for(int i=40; i<x-40; i+=5)
{
pDC->MoveTo(i, y-40);
pDC->LineTo(i, y-35);
if(!((i-40)%50))
{
pDC->LineTo(i, y-30);
CString str;
str.Format("%d", (i-40)*4);
pDC->SetTextColor(RGB(255, 0, 0));
pDC->TextOutA(i-5, y-25, str);
}
}
// Y-axis paint
int k = 0;
for(int i=