孙鑫VC++Lession4

来源:互联网 发布:网络连接只有宽带连接 编辑:程序博客网 时间:2024/06/05 05:45
本节课,孙老师讲解了用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);另一个类是CWindowDCThe 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 ValueIdentifies the Windows desktop window. This pointer may be temporary and should not be stored for later use.后面的就是CPen,CBrush的介绍。不过我觉得没什么大的难度,等用到的时候在去看一看。现在还是来好好的研究下,MFC的消息映射机制,我在网上找了些资料,贴到本文的下一片文章中。