您好,欢迎访问三七文档
#includewindows.h#includeiostreamusingnamespacestd;classCShape{public:virtualvoidDraw()=0;//g当前活动窗口};classCLine:publicCShape{virtualvoidDraw(){HWNDhwnd=::GetForegroundWindow();//画布,画室HDChdc=::GetWindowDC(hwnd);//,工具,笔,颜料等,哪一个画布上的信息HPENnewpen,*oldpen;//新的笔,和老的笔保留newpen=::CreatePen(4,3,RGB(255,0,0));//笔的样式,实心,宽度,颜色oldpen=(HPEN*)SelectObject(hdc,newpen);MoveToEx(hdc,50,50,0);LineTo(hdc,500,300);SelectObject(hdc,&newpen);::ReleaseDC(hwnd,hdc);}};classCCir:publicCShape{public:virtualvoidDraw(){HWNDhwnd=::GetForegroundWindow();//画布,画室HDChdc=::GetWindowDC(hwnd);//,工具,笔,颜料等,哪一个画布上的信息HPENnewpen,*oldpen;//新的笔,和老的笔保留newpen=::CreatePen(PS_SOLID(0),2,RGB(255,0,0));//笔的样式,实心,宽度,颜色oldpen=(HPEN*)SelectObject(hdc,newpen);//MoveToEx(hdc,50,50,0);//LineTo(hdc,200,200);//画直线::Arc(hdc,100,100,400,300,700,800,400,400);SelectObject(hdc,&newpen);::ReleaseDC(hwnd,hdc);}};classCRect:publicCShape{public:virtualvoidDraw(){HWNDhwnd=::GetForegroundWindow();//画布,画室HDChdc=::GetWindowDC(hwnd);//,工具,笔,颜料等,哪一个画布上的信息HPENnewpen,*oldpen;//新的笔,和老的笔保留newpen=::CreatePen(PS_SOLID(0),2,RGB(255,0,0));//笔的样式,实心,宽度,颜色oldpen=(HPEN*)SelectObject(hdc,newpen);//MoveToEx(hdc,50,50,0);//LineTo(hdc,200,200);//画直线//::Arc(hdc,100,100,400,300,700,800,400,400);::Rectangle(hdc,100,200,300,400);SelectObject(hdc,&newpen);::ReleaseDC(hwnd,hdc);}};intmain(){system(color9f);CShape*p=0;//多态,用基类指针来调用子类的对象中的不同的函数。。。。CLinel;p=&l;p-Draw();CCirc;p=&c;p-Draw();CRectr;p=&r;p-Draw();return0;}*/
本文标题:运用C语言编程画图
链接地址:https://www.777doc.com/doc-5269708 .html