请教一个MFC画图形的问题

DwyaneCV 2013-12-10 09:57:38
class CMemDC : public CDC
{
private:
CBitmap m_bitmap; // 实际的bitmap
CBitmap* m_pOldBitmap; // 原先在CMemDC中的位图
CDC* m_pDC; // 保存从构造函数中传来的CDC
CRect m_rect; // 画的矩形区域
BOOL m_bMemDC; // 如果CDC是一个内存DC,则为TRUE

public:

CMemDC(CDC* pDC) : CDC()//构造函数
{
ASSERT(pDC != NULL);//初始化
m_pDC = pDC;//初始化
m_pOldBitmap = NULL;//初始化
m_bMemDC = !pDC->IsPrinting();//判断是否是一个内存DC
if (m_bMemDC) // 创建一个内存DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
}
else // 这不是一个内存DC,我们只拷贝相关的DC部分以备打印
{
m_bPrinting = pDC->m_bPrinting;
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}

这段代码定义的是一个内存DC类,这段代码中,rect并没有给出具体的区域,比如一个控件窗口的区域,或者(50,50,300,300)等,那这段代码只定义了这么个抽象的rect,如何知道在哪里去绘图啊???
...全文
123 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sd__q 2013-12-10
  • 打赏
  • 举报
回复
引用 5 楼 dwyaneyywade 的回复:
[quote=引用 4 楼 sd__q 的回复:] [quote=引用 3 楼 dwyaneyywade 的回复:] [quote=引用 1 楼 sd__q 的回复:] pDC->GetClipBox(&m_rect);这句话把m_rect初始化了
但是它并没有给出具体的区域啊[/quote] The GetClipBox function retrieves the dimensions of the tightest bounding rectangle that can be drawn around the current visible area on the device. The visible area is defined by the current clipping region or clip path, as well as any overlapping windows. 传入的是Rect指针,看该函数的功能 [/quote] 你看我新附加的代码,我觉得ShapeDCRegion就是传给m_rect的。在new一个MemDC时,传给CMemdc的pDC中,把 ShapeDCRegion也传出去了。你觉得是这样吗[/quote]ShapeDCRegion是放到pDc中传入的,而m_rect是根据pdc的函数获取的,你这样理解也可以。。
DwyaneCV 2013-12-10
  • 打赏
  • 举报
回复
引用 4 楼 sd__q 的回复:
[quote=引用 3 楼 dwyaneyywade 的回复:] [quote=引用 1 楼 sd__q 的回复:] pDC->GetClipBox(&m_rect);这句话把m_rect初始化了
但是它并没有给出具体的区域啊[/quote] The GetClipBox function retrieves the dimensions of the tightest bounding rectangle that can be drawn around the current visible area on the device. The visible area is defined by the current clipping region or clip path, as well as any overlapping windows. 传入的是Rect指针,看该函数的功能 [/quote] 你看我新附加的代码,我觉得ShapeDCRegion就是传给m_rect的。在new一个MemDC时,传给CMemdc的pDC中,把 ShapeDCRegion也传出去了。你觉得是这样吗
sd__q 2013-12-10
  • 打赏
  • 举报
回复
引用 3 楼 dwyaneyywade 的回复:
[quote=引用 1 楼 sd__q 的回复:] pDC->GetClipBox(&m_rect);这句话把m_rect初始化了
但是它并没有给出具体的区域啊[/quote] The GetClipBox function retrieves the dimensions of the tightest bounding rectangle that can be drawn around the current visible area on the device. The visible area is defined by the current clipping region or clip path, as well as any overlapping windows. 传入的是Rect指针,看该函数的功能
DwyaneCV 2013-12-10
  • 打赏
  • 举报
回复
引用 1 楼 sd__q 的回复:
pDC->GetClipBox(&m_rect);这句话把m_rect初始化了
但是它并没有给出具体的区域啊
DwyaneCV 2013-12-10
  • 打赏
  • 举报
回复
补充一段代码 void CFluxStatic::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here CDC* pDC = &dc; int erg = pDC->SelectClipRgn(&ShapeDCRegion);//选择剪切区域,绘图限制区域 CRect rect; GetClientRect(&rect);//获得客户区域 int nSavedDC = pDC->SaveDC();//此处保存的DC仅有剪切区域 if(brushInitalized == false)//初始化设备 { CBitmap bmp; CMemDC * memDC = new CMemDC(pDC);//new 一个内存DC RECT clipRect; memDC->GetClipBox(&clipRect);//获取剪切区域 if(clipRect.right - clipRect.left > 1) { bmp.CreateCompatibleBitmap(memDC,plot,TGSize.cy); CBitmap *pOld = memDC->SelectObject(&bmp);//内存DC有关 CSize bmps = bmp.GetBitmapDimension(); double factor = 255.0 / (float)TGSize.cy; //设置像素 BYTE r,g,b; for(int x = 0; x<TGSize.cy; x++) { g = (BYTE)(255-factor*x); r = (BYTE)(factor*x); b = (BYTE)64; memDC->SetPixelV(0,x,RGB(r,g,b)); memDC->SetPixelV(1,x,RGB(r,g,b)); } memDC->SelectObject(pOld); colorbrush.CreatePatternBrush(&bmp); brushInitalized = true; } }
sd__q 2013-12-10
  • 打赏
  • 举报
回复
pDC->GetClipBox(&m_rect);这句话把m_rect初始化了

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧