如何访问预定义的GDI对象

来源:互联网 发布:js时间戳转24小时日期 编辑:程序博客网 时间:2024/05/01 08:53

可以通过调用CDC:: SlectStockObject使用Windows的几个预定义的对象,诸如刷子、笔以及字体。下例使用了Windows预定义的笔和刷子GDI对象在视窗中画一个椭圆。

//Draw ellipse using stock black pen and gray brush.void CSampleView:: OnDraw (CDC* pDC){ //Determine size of view. CRect rcView GetClientRect (rcView) //Use stock black pen and stock gray brush to draw ellipse. pDC->SelectStockObject (BLACK_PEN) pDC->SelectStockObject (GRAY_BRUSH) //Draw the ellipse. pDC->Ellipse (reView)}也可以调用新的SDK函数GetSysColorBrush获取一个系统颜色刷子,下例用背景色在视窗中画一个椭圆:void CsampleView:: OnDraw (CDC* pDC){ //Determine size of view. CRect rcView GetClientRect (rcView) //Use background color for tooltips brush. CBrush * pOrgBrush=pDC->SelectObject ( CBrush ::FromHandle( ::GetSysColorBrush (COLOR_INFOBK))) //Draw the ellipse. pDC->Ellipse (rcView) //Restore original brush. pDC->SelectObject (pOrgBrush)}