回 帖 发 新 帖 刷新版面

主题:[原创]VC中 CDC的使用不需要定义对象?

我在看一个视频教程
上面教了一种方法,画线的方法
很简单
鼠标左击是响应消息获得第一个点
松开时获得第二点
然后画直线


具体代码实现的时候  为什么没有定义CDC的对象?

上代码



void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default

    CDC *pDC=GetDC();          //这里直接定义指针,不需要类的对象?
    pDC->MoveTo(m_ptOrigin);   //m_ptOrigin 是第一个点的坐标类Point
    pDC->LineTo(point);        // point是第二个点的坐标
    ReleaseDC(pDC);            //

回复列表 (共3个回复)

沙发

GetDC();    是个CWnd 类的成员函数,看一下返回类型就就知道返回CDC* 指针;
Identifies the device context for the CWnd client area if successful;
从 CWnd 客户区范围标识一个设备上下文,如果成功的话,// CWnd 客户区就是CView 视! 也即获得视类的DC!
MSDN 解释如下:

CWnd::GetDC 
CDC* GetDC( );

Return Value

Identifies the device context for the CWnd client area if successful; otherwise, the return value is NULL. The pointer may be temporary and should not be stored for later use.

Remarks

Retrieves a pointer to a common, class, or private device context for the client area depending on the class style specified for the CWnd. For common device contexts, GetDC assigns default attributes to the context each time it is retrieved. For class and private contexts, GetDC leaves the previously assigned attributes unchanged. The device context can be used in subsequent graphics device interface (GDI) functions to draw in the client area.

板凳


我明白了
获得DC的方法是getdc

3 楼

你好.我是全职网赚工作者.
如果你有时间有电脑.
想在网络上创业.请联系我..
项目绝对真实.详情QQ空间资料
加盟请联系摩客元亨 QQ908889846
2010年,中国网民突破了4亿,
网络游戏玩家超过了3亿,
互联网即将进入全民网游的时代

我来回复

您尚未登录,请登录后再回复。点此登录或注册