设为首页 加入收藏

TOP

vc++笔记之绘图程序 (五)
2014-11-23 19:22:48 】 浏览:892
Tags:笔记 绘图 程序
ender, LPARAM lHint = 0L, CObject* pHint =

NULL );

UpdateAllViews带三个参数:pSender指向修改文档的视图。由于该视图已经作了更新,所以不再需要更新。比如,在上面的例子中,OnLButtonUp已经绘制了视图,因此不需要再次更新。如果为NULL,则文档对应的所有视图都被更新。

lHint和pHint包含了更新视图时所需的附加信息。在本例中,其他视图只需要重画当前绘制中的笔划,因此OnLButtonUp把当前笔划指针传给UpdateAllViews函数。该函数调用文档所对应的除pSender外的所有视图的OnUpdate函数,并将lHint和pHint传给OnUpdate函数通知更新附加信息。

OnLButtonUp最后释放对鼠标的控制,这样别的应用程序窗口就可以获得鼠标消息了。

结合上面讲到的知识,读者不难自行理解下面的OnMouseMove函数。

void CDrawView::OnMouseMove(UINT nFlags, CPoint point)

{

// TODO: Add your message handler code here and/or call default

// Mouse movement is interesting in the Scribble application

// only if the user is currently drawing a new stroke by dragging

// the captured mouse.

if (GetCapture() != this)

return; // If this window (view) didn't capture the mouse,

// then the user isn't drawing in this window.

CClientDC dc(this);

// CScrollView changes the viewport origin and mapping mode.

// It's necessary to convert the point from device coordinates

// to logical coordinates, such as are stored in the document.

OnPrepareDC(&dc);

dc.DPtoLP(&point);

m_pStrokeCur->m_pointArray.Add(point);

// Draw a line from the previous detected point in the mouse

// drag to the current point.

CPen* pOldPen = dc.SelectObject(GetDocument()->GetCurrentPen());

dc.MoveTo(m_ptPrev);

dc.LineTo(point);

dc.SelectObject(pOldPen);

m_ptPrev = point;

return;

}

至此,绘图程序的文档、视图全部设计完了,现在编译运行程序。程序启动后,在空白窗口中徒手绘图

首页 上一页 2 3 4 5 6 下一页 尾页 5/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇VC密码框显示字符的终极设置方法 下一篇图形设备接口(学习笔记)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目