这个是看别人的代码得到的,不是我写的。
void CHhDlg::OnOK() { //先得到屏幕的长宽: int ScreenWidth = ::GetSystemMetrics(SM_CXSCREEN); int ScreenHeight = ::GetSystemMetrics(SM_CYSCREEN); HDC hDC = ::GetDC(0); //得到“画布(Canvas)” CDC* ScreenCanvas = new CDC(); ScreenCanvas->m_hDC = hDC; //设置画布的画笔(Pen) CPen pen(1, 10, RGB(255,0,0)); CPen* oldpen; oldpen=ScreenCanvas->SelectObject(&pen); //ScreenCanvas->Pen->Color = clRed; //画笔的颜色为红色(Red) //ScreenCanvas->Pen->Width = 10; //画笔的粗细 //开始画叉啦,需要画两笔,这是第一笔:左上到右下 ScreenCanvas->MoveTo(0,0); //把画笔移到(Move to)坐标0,0处,即屏幕最左上角 ScreenCanvas->LineTo(ScreenWidth,ScreenHeight); //从当前位置画一条线(Line to)到屏幕的右下角。
//第二笔:右上到左下: ScreenCanvas->MoveTo(ScreenWidth,0); ScreenCanvas->LineTo(0,ScreenHeight);
ScreenCanvas->SelectObject(oldpen); //释放“画布”: ScreenCanvas->m_hDC = 0; delete ScreenCanvas; ::ReleaseDC(0,hDC);
//CDialog::OnOK(); }
|