C++程序设计chapter4方案.ppt

第4章 GDI及windows绘图 第4章 GDI及Windows绘图 Huang Weitong 缺省方式下的坐标系统 SelectObject(hDC,hBrush); //选择画刷 Ellipse(hDC,150,50,200,150); //绘制椭圆 hBrush=(HBRUSH)GetStockObject(HOLLOW_BRUSH); //虚画刷 SelectObject(hDC,hBrush); //选择画刷 Pie(hDC,250,50,300,100,250,50,300,50); //绘制饼形 EndPaint(hWnd,PtStr); //结束绘图 return 0; case WM_DESTROY: //结束应用程序 PostQuitMessage(0); return 0; default: //其他消息处理程序 return(DefWindowProc(hWnd,iMessage,wParam,lParam)) ; } } BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)//初始化窗口 { HWND hWnd; hWnd=CreateWindow(WinFill, //生成窗口 填充示例程序, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if(!hWnd) return FALSE; hWndMain=hWnd; ShowWindow(hWnd,nCmdShow); //显示窗口 UpdateWindow(hWnd); return TRUE; } BOOL InitWindowsClass(HINSTANCE hInstance) //定义窗口类 { WNDCLASS WndClass; WndClass.cbClsExtra=0; WndClass.cbWndExtra=0; WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH)); WndClass.hCursor=LoadCursor(NULL,IDC_ARROW); WndClass.hIcon=LoadIcon(NULL,END); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=WndProc; WndClass.lpszClassName=WinFill; WndClass.lpszMenuName=NULL; WndClass.style=CS_HREDRAW|CS_VREDRAW; return RegisterClass(WndClass); } 例: 应用画笔和画刷等工具绘制如图所示的图形 1… #includewindows.h 2… #includestdlib.h 3… #includestring.h 4… long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam); 5… BOOL InitWindowsClass(HINSTANCE hInstance); 6… BOOL InitWindows(HINSTANCE hInstance,int nCmdShow); 7… HWND hWndMain; //主函数 8… int WINAPI W inMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) 9… { MSG Message; 10… if(!InitWindowsClass(hInstance)) return FALSE; 11… if(!InitWindows(hInstance,nCmdShow)) return FALSE; 12… while(GetMessage(Message,0,0,0)) //消息循环 13… { TranslateMessage(Message); 14… DispatchMessage(Message); } 15… return Message

文档评论(0)

1亿VIP精品文档

相关文档