发送第5章图形和文本输出.ppt
文本预览下载声明
第5章 图形和文本输出 Windows操作系统通过图形设备接口(graphic device interface, 简称GDI)管理Windows 程序的所有图形输出。 GDI 函数及设备描述表的使用: 见下例 输出设备及范围:视图 画线 private: CPoint m_Point1; CDrawView::CDrawView() { // TODO: add construction code here m_Point1=0; //pln } 画线 void CDrawView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_Point1 =point; CView::OnLButtonDown(nFlags, point); } 画线 void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default HDC hdc; hdc=::GetDC(m_hWnd); ::MoveToEx(hdc, m_Point1.x, m_Point1.y,NULL); ::LineTo(hdc,point.x,point.y); ::ReleaseDC(m_hWnd,hdc); CView::OnLButtonUp(nFlags, point); } The MoveToEx function updates the current position to the specified point and optionally returns the previous position. BOOL MoveToEx( HDC hdc, // handle to device context int X, // x-coordinate of new current position int Y, // y-coordinate of new current position LPPOINT lpPoint // pointer to old current position ); Parameters hdc Handle to a device context. X Specifies the x-coordinate of the new position, in logical units. Y Specifies the y-coordinate of the new position, in logical units. lpPoint Pointer to a POINT structure in which the previous current position is stored. If this parameter is a NULL pointer, the previous position is not returned. CDC 设备描述表(Device Context ,DC), 定义了一系列图形对象及其属性。 如:画刷的样式、颜色 画笔的样式、宽度和颜色 字体的名称、宽度、高度等。 MFC提供了CDC类支持图形输出和文本输出。 与窗口相关的操作封装在CWnd中, 与作图有关的操作 封装在CDC类中。 CDC中封装了一些成员函数和设备上下文一起工作,比如画线或者作图的一些函数。 Data Members m_hDC 保存了和我们CDC对象相关的一个DC的句柄。 CDC中的作图函数中的参数就不再需要设备上下文的句柄了。原理同CWnd的封装。 CWnd::GetDC CWnd类的成员函数 GetDC CDC* GetDC( ); //获取窗口客户区的设备上下文 CDC类的作图函数 CDC::MoveTo? CPoint MoveTo( int x, int y ); CPoint MoveTo( POINT point ); 画线 void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CDC *pDC=GetDC(); pDC-M
显示全部