资源描述:
《黄维通之绘图程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、黄维通之绘图程序#include#include#includelongWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam);BOOLInitWindowsClass(HINSTANCEhInstance);BOOLInitWindows(HINSTANCEhInstance,intnCmdShow);HWNDhWndMain;//主函数intWINAPIWinMain(H
2、INSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){MSGMessage;if(!InitWindowsClass(hInstance))returnFALSE;if(!InitWindows(hInstance,nCmdShow))returnFALSE;while(GetMessage(&Message,0,0,0))//消息循环{TranslateMessage(&Message);DispatchMess
3、age(&Message);}returnMessage.wParam;}longWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam){HDChDC;//定义设备环境句柄HBRUSHhBrush;//定义画刷的句柄HPENhPen;//定义画笔的句柄PAINTSTRUCTPtStr;//定义指向包含绘图信息的结构体变量//定义一个POINT数组,包括6个点POINTpoints[6]={{100,212},{70,227},{70,2
4、50},{130,250},{130,227},{100,212}};switch(iMessage)//处理消息{caseWM_PAINT://处理绘图消息hDC=BeginPaint(hWnd,&PtStr);hPen=(HPEN)GetStockObject(NULL_PEN);//获取系统定义的空画笔SelectObject(hDC,hPen);//选择画笔hBrush=(HBRUSH)GetStockObject(BLACK_BRUSH);//获取系统定义的画刷SelectObject(
5、hDC,hBrush);//选择画刷LineTo(hDC,50,50);//画线DeleteObject(hPen);//删除画笔hPen=CreatePen(PS_SOLID,2,RGB(255,0,0));//创建画笔SelectObject(hDC,hPen);//选择画笔//画一个三角形LineTo(hDC,100,137);LineTo(hDC,50,50);Polyline(hDC,points,6);//画一个五边形Arc(hDC,63,137,138,212,100,137,100
6、,137);//画一个圆Pie(hDC,213,137,288,212,240,137,260,137);//画一个圆饼Rectangle(hDC,213,212,287,250);//画一个长方形RoundRect(hDC,213,100,287,137,20,20);//画一个圆角长方形DeleteObject(hPen);//删除画笔DeleteObject(hBrush);//删除画刷EndPaint(hWnd,&PtStr);//结束绘图return0;caseWM_DESTROY://
7、结束应用程序PostQuitMessage(0);return0;default://其他消息处理程序return(DefWindowProc(hWnd,iMessage,wParam,lParam));}}BOOLInitWindows(HINSTANCEhInstance,intnCmdShow)//初始化窗口{HWNDhWnd;hWnd=CreateWindow("WinFill",//生成窗口"填充示例程序",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_U
8、SEDEFAULT,0,NULL,NULL,hInstance,NULL);if(!hWnd)returnFALSE;hWndMain=hWnd;ShowWindow(hWnd,nCmdShow);//显示窗口UpdateWindow(hWnd);returnTRUE;}BOOLInitWindowsClass(HINSTANCEhInstance)//定义窗口类{WNDCLASSWndClass;WndClass.cbClsExtra=0;WndClass.cbWndExtra=