孙鑫VC++Lession4

本节课,孙老师讲解了用VC的写的一个画图的编程案例 工程名称:Draw (MFC) 通过这个案例,我的感觉就是,不仅仅知道了几个画图的函数,和一些画图的方法,更重要的是,这堂课,向我们展示了MFC如何处理消息映射。 因为View 是覆盖在了MainFrame上,所以,我们在捕获鼠标左键的消息的时候,都是捕获到了view上的消息,而不是MainFrame上消息响应。所以,我们在要分清楚我们呢 。 下面的这几个函数是在这个案例中所用到的。 HDC GetDC(   HWND hWnd   // handle to a window ); 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 );   BOOL LineTo(   HDC hdc,    // device context handle   int nXEnd,  // x-coordinate of line's ending point   int nYEnd   // y-coordinate of line's ending point );   int ReleaseDC(   HWND hWnd,  // handle to window   HDC hDC     // handle to device context );   以上的用的是平台SDK 不过在MFC中提供了CDC的类,这个类中,封装好了很多DC的操作 现在代码变成了     CDC *pDC=GetDC();     pDC->MoveTo(m_ptOld);     pDC->LineTo(point);     ReleaseDC(pDC); 当然还有另外一种方法是用CClientDC这种方式 CClientDC::CClientDC  CClientDC( CWnd* pWnd ); throw( CResourceException ); 代码变成了     CClientDC cdc(this);     cdc.MoveTo(m_ptOld);     cdc.LineTo(point); 另一个类是CWindowDC The CWindowDC class is derived from CDC. It calls the Windows functions GetWindowDC at construction time and ReleaseDC at destruction time. 这个DC和前面的DC是有所不同的,他有一个优点就是可以访问客户区和非客户区。 这里有个函数,可以获得windows桌面的句柄 CWnd::GetDesktopWindow  static CWnd* PASCAL GetDesktopWindow( ); Return Value Identifies the Windows desktop window. This pointer may be temporary and should not be stored for later use. 后面的就是CPen,CBrush的介绍。不过我觉得没什么大的难度,等用到的时候在去看一看。现在还是来好好的研究下,MFC的消息映射机制,我在网上找了些资料,贴到本文的下一片文章中。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值