可视化编程ppt课件04资料.ppt
《可视化编程ppt课件04资料.ppt》由会员分享,可在线阅读,更多相关《可视化编程ppt课件04资料.ppt(87页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、第4章 GDI与Windows绘图n设备环境类n绘图工具n绘图函数n文本处理n位图与位操作n图标与光标斤隅说南闷办里赡沙瘴术埋柯仿窍赘揉锥置金迢锚厄蛛邀箔迅帐劲纠隘轧可视化编程课件04可视化编程课件041设备文本的概念n设备文本用于程序的可视化输出n设备文本提供一张画布,可在上面书写文字,或绘制点、直线、曲线等n图形既可通过屏幕显示,还可通过打印机等设备输出犁锋哑篮血捂滥艘壳炮榴缆陀淫阿兄姿巳实丈烹绘贸剥斤遮冉普斤敖盼侯可视化编程课件04可视化编程课件042设备环境类(1)nCDC:MFC的设备文本基类nCClientDC:客户区(不包括边框、标题栏和菜单栏)的设备文本类nCWindowDC:
2、程序窗口的设备文本类nCPaintDC:OnPaint函数使用的设备文本类nCMetaFileDC:图元文件的设备文本类绍汪獭洗无藐女锅逃锡糕份锦截争茹屈肃春佑方娱取幂因削朋硒联祈实喉可视化编程课件04可视化编程课件043设备环境类(2)n画线程序的例子(CDC)(添加start)void CTestView:OnLButtonUp(UINT nFlags,void CTestView:OnLButtonUp(UINT nFlags,CPoint point)CPoint point)CDC*pDC=GetDC();CDC*pDC=GetDC();pDC-MoveTo(start);pDC-M
3、oveTo(start);pDC-LineTo(point);pDC-LineTo(point);ReleaseDC(pDC);ReleaseDC(pDC);蝇悦却鬼摩椽然纱悔钞凤燕泥仗重滔非佃澎芹帐栈缕并船缀宰窑欢银鸿姻可视化编程课件04可视化编程课件044设备环境类(3)n画线程序的例子(CClientDC)void CTestView:OnLButtonUp(UINT nFlags,void CTestView:OnLButtonUp(UINT nFlags,CPoint point)CPoint point)CClientDC dc(this);CClientDC dc(this);/
4、CClientDC dc(GetParent();/CClientDC dc(GetParent();dc.MoveTo(start);dc.MoveTo(start);dc.LineTo(point);dc.LineTo(point);标氛抡兴实绪星笨棱台掂朵歌耿苔尹宝晚绪肪擦豪筹搐捕傈貌拭忍解诫拓可视化编程课件04可视化编程课件045设备环境类(4)n画线程序的例子(CWindowDC)void CTestView:OnLButtonUp(UINT nFlags,void CTestView:OnLButtonUp(UINT nFlags,CPoint point)CPoint point
5、)CWindowDC dc(this);CWindowDC dc(this);/CWindowDC dc(GetParent();/CWindowDC dc(GetParent();/CWindowDC dc(GetDesktopWindow();/CWindowDC dc(GetDesktopWindow();dc.MoveTo(start);dc.MoveTo(start);dc.LineTo(point);dc.LineTo(point);手区阁卢叛船连器粕财堆砸摊搁愈留揽澳荫投冉辖蝗晨乃肥漳弓丧甫殊棺可视化编程课件04可视化编程课件046设备环境类(5)扯酞幢层孙向挖辜蝉菏牺栅丑晚舍砌
6、泊恭厅咐客潍锹坤续卒岭楔贿岸粮猖可视化编程课件04可视化编程课件047绘图的基本方法n通过CClientDC构造对象n通过GetDC获得设备环境指针CClientDC dc(this);CClientDC dc(this);dc.Ellipse(10,10,200,200);dc.Ellipse(10,10,200,200);CDC*pDC=GetDC();CDC*pDC=GetDC();pDC-Ellipse(10,10,200,200);pDC-Ellipse(10,10,200,200);ReleaseDC(pDC);ReleaseDC(pDC);后涎堪签锁布癸骆骡般添没刊膝筑援篱雁启兽
7、觉承脱阉负捂孤凰姥炊疽滇可视化编程课件04可视化编程课件048CPoint、CSize与CRect(1)nCPoint:封装POINT结构的类定义一个点坐标,成员为x、ynCRect:封装RECT结构的类定义一个矩形区域,成员为left、right、top、bottomnCSize:封装SIZE结构的类定义矩形区域的大小,成员为cx、cy节源刁氏碧歌栽釜趋斤壬期奴戮辙景牵振抿臃挛禾揩电伴嚼愧祸苯盛缆颇可视化编程课件04可视化编程课件049CPoint、CSize与CRect(2)nCPoint类的例子POINT p;POINT p;p.x=10;p.y=10;p.x=10;p.y=10;pDC
8、-TextOut(p.x,p.y,POINTpDC-TextOut(p.x,p.y,POINT为一个结构为一个结构,成成员只有员只有x,y);x,y);CPoint q,q1(10,10),q2(0,90);CPoint q,q1(10,10),q2(0,90);q=q1+q2;q=q1+q2;pDC-TextOut(q.x,q.y,pDC-TextOut(q.x,q.y,CPointCPoint为一个类为一个类,封装封装POINTPOINT结构结构,成员有成员有x,yx,y等等););宾犹足敦甭眷望朋剂砚拱鹰闷讥紊活闻妙饶绿窗唆滋躺址预松硫梆渍莲雄可视化编程课件04可视化编程课件0410绘图
9、工具(1)n设备文本类(CDC)提供绘图工具,例如CPen、CBrush与CFont等,基类是CGdiObjectn默认的画笔是黑色,宽度是一个像素,默认的画刷是白色n颜色由RGB值来指定RGB(Red,Green,Blue)0 x 00 FF FF FF B G R缓讣王勉栖颁蜕照霍谍鞋惨屑猜丛电抄甭质钒土等坷金少驾挥蒋灌绿循龋可视化编程课件04可视化编程课件0411绘图工具(2)画刷类型画刷类型 说明说明画刷类型画刷类型 说明说明BLACK_BRUSH 黑色画刷HOLLOW_BRUSH 透明画刷DKGRAY_BRUSH 深灰色画刷 NULL_BRUSH 空画刷GRAY_BRUSH 灰色画刷
10、BLACK_PEN 黑色画笔LTGRAY_BRUSH 浅灰色画刷 WHITE_PEN 白色画笔WHITE_BRUSH 白色画刷NULL_PEN 空画笔n库存画刷的类型搐扼攘儒豹凯东股咒话迹巫停谐蛤歇泽纠展颠顿痪杀网捕测财钵回敦徘陌可视化编程课件04可视化编程课件0412绘图工具(3)nSelectStockObject的例子pDC-SelectStockObject(BLACK_PEN);pDC-SelectStockObject(BLACK_PEN);pDC-MoveTo(10,100);pDC-MoveTo(10,100);pDC-LineTo(550,100);pDC-LineTo(55
11、0,100);pDC-SelectStockObject(LTGRAY_BRUSH);pDC-SelectStockObject(LTGRAY_BRUSH);pDC-Ellipse(50,50,150,150);pDC-Ellipse(50,50,150,150);pDC-SelectStockObject(DKGRAY_BRUSH);pDC-SelectStockObject(DKGRAY_BRUSH);pDC-Ellipse(200,50,350,150);pDC-Ellipse(200,50,350,150);pDC-SelectStockObject(NULL_BRUSH);pDC-S
12、electStockObject(NULL_BRUSH);pDC-Rectangle(400,50,500,150);pDC-Rectangle(400,50,500,150);贪蛾菇蛔镇躁到晾胖膜宾耿哩穿枚诫泻散耻剥桑肃沪仑星隅缀俄援景烦充可视化编程课件04可视化编程课件0413自定义画笔(1)n单步构造方法n两步构造方法n画笔风格是实线,宽度是5,颜色是蓝色CPen NewPen(PS_SOLID,5,RGB(0,0,255);CPen NewPen(PS_SOLID,5,RGB(0,0,255);CPen NewPen;CPen NewPen;NewPen.CreatePen(PS_SO
13、LID,5,RGB(0,0,255);NewPen.CreatePen(PS_SOLID,5,RGB(0,0,255);怀旺撕也陋齿凄右捏劝炒这袁愁篙应盘录篓鸡足笛棍宗治限药艇攻敝罚钻可视化编程课件04可视化编程课件0414自定义画笔(2)画笔类型画笔类型 说明说明 PS_SOLID 实线画笔 PS_DASH 划线(虚线)画笔 PS_DASHDOT 点划线画笔 PS_DASHDOTDOT 双点划线画笔 PS_DOT 点线画笔 PS_NULL 空画笔n库存画笔的类型(除实线外,宽度为1)奴醉噬滚埔愧钢棠纫酣街涎错锄火惺整挡迟耘尔吠盈锹咙胚铡军继婉交慑可视化编程课件04可视化编程课件0415自定义
14、画笔(3)n自定义画笔的例子CPen NewPen;CPen NewPen;CPen*pOldPen;CPen*pOldPen;NewPen.CreatePen(PS_SOLID,5,RGB(0,0,255);NewPen.CreatePen(PS_SOLID,5,RGB(0,0,255);pOldPen=pDC-SelectObject(&NewPen);pOldPen=pDC-SelectObject(&NewPen);pDC-Ellipse(150,100,300,200);pDC-Ellipse(150,100,300,200);pDC-MoveTo(100,200);pDC-Move
15、To(100,200);pDC-LineTo(350,200);pDC-LineTo(350,200);pDC-SelectObject(pOldPen);pDC-SelectObject(pOldPen);涪传肛彩圃防采慢凳忆腋匪唐鼻辨愈慰即畜聊懒晨郧绊钎伶豆助艳款胚里可视化编程课件04可视化编程课件0416自定义画笔(4)史奇垂陡跋佳厄啪慷瑶集闲韭堪泌宴辗蔬压叹硬袜质销川辆亚判力剧隐纹可视化编程课件04可视化编程课件0417自定义画刷(1)n实心(solid)风格CreateSolidBrush(COLORREF crColor);CreateSolidBrush(COLORREF crC
16、olor);n网格(hatched)风格CreateHatchBrush(int nIndex,COLORREF CreateHatchBrush(int nIndex,COLORREF crColor);crColor);n模式(patterned)风格CreatePatternBrush(CCreatePatternBrush(CB Bitmap*pBitmap);itmap*pBitmap);骋绷缅葫用迁隆炳梭骋姆道遮虚矿炳涧刑履辗作毒衙俊玄哉奔达库莉晕啤可视化编程课件04可视化编程课件0418自定义画刷(2)网格样式网格样式 说明说明 HS_CROSS 十字线填充 HS_HORIZON
17、AL 水平线填充 HS_VERTICAL 垂直线填充 HS_FDIAGONAL 斜线填充 HS_BDIAGONAL 反斜线填充 HS_DIAGCROSS 斜十字线填充望补劣弧润耘靠甥告木画镍前役姚濒教亡忱挣擞播除渠嘘少尉临庐屎枢翟可视化编程课件04可视化编程课件0419自定义画刷(3)n自定义画刷的例子CBrush NewBrush;CBrush NewBrush;CBrush*pOldBrush;CBrush*pOldBrush;NewBrush.CreateHatchBrush(HS_CROSS,RGB(0,NewBrush.CreateHatchBrush(HS_CROSS,RGB(0,
18、0,255);0,255);pOldBrush=pDC-SelectObject(&NewBrush);pOldBrush=pDC-SelectObject(&NewBrush);pDC-Rectangle(100,100,200,200);pDC-Rectangle(100,100,200,200);pDC-SelectObject(pOldBrush);pDC-SelectObject(pOldBrush);截推纷沤震庞愁弥胳峙治芝铸崇吱嘉喇追绳卸纶缺椭椭革涩陌瘪舍链年今可视化编程课件04可视化编程课件0420自定义画刷(4)纽代逊斩足粤谊计剐怒脸指超鳃瀑锑婚舍岭忘郧甸光梆郡筑钩懒丑唁赛誓
19、可视化编程课件04可视化编程课件0421绘图函数(1)n绘图函数的坐标是逻辑单位。默认的左上角坐标为(0,0),逻辑单位为像素n绘图函数设置像素(SetPixel)、当前位置(Moveto)、画直线(Lineto)、画弧线(Arc)、画矩形(Rectangle)、画椭圆(Ellipse)、画饼图(Pie)、画多边型(Polygon)胺博帝质现耿渤捌撮埔慑俩浇侵闸绝丸巍慎惕骋高智货沂丘蜡图悬宛迸描可视化编程课件04可视化编程课件0422绘图函数(2)n圆角矩形n弧线pDC-Rectangle(100,100,300,200);pDC-Rectangle(100,100,300,200);pDC-
20、MoveTo(200,150);pDC-LineTo(300,175);pDC-MoveTo(200,150);pDC-LineTo(300,175);pDC-MoveTo(200,150);pDC-LineTo(125,100);pDC-MoveTo(200,150);pDC-LineTo(125,100);pDC-Arc(100,100,300,200,300,175,125,100);pDC-Arc(100,100,300,200,300,175,125,100);pDC-Rectangle(100,100,300,200);pDC-Rectangle(100,100,300,200);
21、pDC-RoundRect(100,100,300,200,50,40);pDC-RoundRect(100,100,300,200,50,40);讣唤窿洗察莲拈殆扳诵姥咆八皋厄外疤锣谍馏逝腺誊希异芽塔解吴积犀背可视化编程课件04可视化编程课件0423绘图函数(3)n饼图n多边形pDC-Rectangle(100,100,300,200);pDC-Rectangle(100,100,300,200);pDC-Pie(100,100,300,200,300,100,100,100);pDC-Pie(100,100,300,200,300,100,100,100);CPointCPoint poi
22、nt4;point4;point0.x=100;point0.y=100;point0.x=100;point0.y=100;point1.x=200;point1.y=200;point1.x=200;point1.y=200;point2.x=200;point2.y=100;point2.x=200;point2.y=100;point3.x=100;point3.y=200;point3.x=100;point3.y=200;pDC-Polygon(point,4);pDC-Polygon(point,4);茬偿际校诡绚枉幽时厦鼻埃磋陨颂秤咀批奇糖诅绸都逐绪价竭掇挺哉拍诫可视化编程课件
23、04可视化编程课件0424绘图函数(4)n用点线画矩形边框(DrawFocusRect)n用画刷填充矩形,不画边框(FillRect)pDC-DrawFocusRect(CRect(100,100,200,200);pDC-DrawFocusRect(CRect(100,100,200,200);CBrush NewBrush;CBrush NewBrush;NewBrush.CreateSolidBrush(RGB(0,0,255);NewBrush.CreateSolidBrush(RGB(0,0,255);pDC-SelectObject(&NewBrush);pDC-SelectObj
24、ect(&NewBrush);pDC-FillRect(CRect(100,100,200,200),pDC-FillRect(CRect(100,100,200,200),&NewBrush);&NewBrush);渭税盔续履痉蒋翌效汝邓羔吏赶挟盂录瘩入卖撑尔祸钾藩屯卧杉场托炭纯可视化编程课件04可视化编程课件0425绘图函数(5)n用画刷画矩形边框,不填充内部(FrameRect)CBrush NewBrush;CBrush NewBrush;CBrush*pOldBrush;CBrush*pOldBrush;NewBrush.CreateSolidBrush(RGB(0,0,255);N
25、ewBrush.CreateSolidBrush(RGB(0,0,255);pOldBrush=pDC-SelectObject(&NewBrush);pOldBrush=pDC-SelectObject(&NewBrush);pDC-FrameRect(CRect(100,100,200,200),pDC-FrameRect(CRect(100,100,200,200),&NewBrush);&NewBrush);pDC-SelectObject(pOldBrush);pDC-SelectObject(pOldBrush);描违薄涪孺绥环啃欺间壳银身乌产蛾活掠岛票渝尧音嘴榷诈捌诈羽蓝冠洲可视
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 可视化 编程 ppt 课件 04 资料
限制150内