利用设备描述符画图

// TODO: 在此添加消息处理程序代码和/或调用默认值
    //利用window object 操作设备上下文HDC 画图
  HDC hdc;
 hdc=::GetDC(m_hWnd);
 MoveToEx(hdc,cpoint.x,cpoint.y,NULL);
 LineTo(hdc,point.x,point.y);
 ::ReleaseDC(m_hWnd,hdc);
 CDialog::OnLButtonUp(nFlags, point);

 //mfc封装cdc利用CDC操作


 CDC* cdc=CWnd::GetDC();
 cdc->MoveTo(cpoint.x,cpoint.y);
 cdc->LineTo(point.x,point.y);
 CWnd::ReleaseDC(cdc);

 //利用cdc的实现类 CClientDC 构造生成dc 析构注销dc

 CClientDC cdc(this); //如果多窗口 GetParent() 获取frame 画图到工具栏
 cdc.MoveTo(cpoint.x,cpoint.y);
 cdc.LineTo(point.x,point.y);

 //利用cdc的实现类 CClientDC 构造生成dc 析构注销dc

 CWindowDC cdc(this); //如果多窗口 getParent() 获取frame 画图到菜单栏
 cdc.MoveTo(cpoint.x,cpoint.y);
 cdc.LineTo(point.x,point.y);

 //画到整个windows
 CWindowDC cdc(GetDesktopWindow()); //如果多窗口 getParent() 获取frame 画图到菜单栏
 cdc.MoveTo(cpoint);
 cdc.LineTo(point);

 

 

//利用画笔改变颜色大小
 CPen pen(PS_DASHDOT,10,RGB(255,0,0));
 CClientDC dc(this);
 dc.SelectObject(&pen);
 dc.MoveTo(cpoint);
 dc.LineTo(point);

 //利用画刷 话方形

    CClientDC dc(this);
 CBrush brush(RGB(255,0,0));
 dc.FillRect(CRect(cpoint,point),&brush);

 // 画矩形
    CClientDC dc(this);
 dc.Rectangle(CRect(cpoint,point));

 //获取透明画刷
 CClientDC dc(this);
 dc.Rectangle(CRect(cpoint,point));
 CBrush *brush=CBrush::FromHandle((HBRUSH)::GetStockObject(NULL_BRUSH));
 //替换掉新的画刷后 返回旧的画刷
 CBrush *oldbrush=dc.SelectObject(brush);
 dc.Rectangle(CRect(cpoint,point));
 dc.SelectObject(oldbrush);

posted @ 2010-08-07 10:47  饺子吃遍天  阅读(98)  评论(0编辑  收藏  举报