当前位置: 代码迷 >> VC >> 在单文挡里的CMainFrm类里为什么不能画线?解决方法
  详细解决方案

在单文挡里的CMainFrm类里为什么不能画线?解决方法

热度:1841   发布时间:2013-02-25 00:00:00.0
在单文挡里的CMainFrm类里为什么不能画线?
我做了一个Draw单文挡工程,在DrawView类里可以画线,而在CMainFrm类里却不能画线;我取了父窗口指针啊。
void   CMainFrame::OnLButtonDown(UINT   nFlags,   CPoint   point)  
{
//   TODO:   Add   your   message   handler   code   here   and/or   call   default
m_ptOrigin=point;
CFrameWnd::OnLButtonDown(nFlags,   point);
}

void   CMainFrame::OnLButtonUp(UINT   nFlags,   CPoint   point)  
{
//   TODO:   Add   your   message   handler   code   here   and/or   call   default
/*1 HDC   hdc;
hdc=::GetDC(m_hWnd);
MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,NULL);
LineTo(hdc,point.x,point.y);
::ReleaseDC(m_hWnd,hdc);
*/

/*2 CDC*   pdc;
pdc=GetDC();
pdc-> MoveTo(m_ptOrigin);
pdc-> LineTo(point);
ReleaseDC(pdc);
*/
/*3 //CClientDC   dc(this);
CClientDC   dc(GetParent());
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
*/

//4 CWindowDC   dc(this);
CWindowDC   dc(GetParent());
//     CWindowDC   dc(GetDesktopWindow());
        dc.MoveTo(m_ptOrigin);
dc.LineTo(point);

CFrameWnd::OnLButtonUp(nFlags,   point);
}
请朋友帮助啊!
谢谢!

------解决方案--------------------------------------------------------
哦,那框架类还有父窗口么?在框架类里用GetParent()得到的是什么啊?
还有,你把函数写在OnLButtonUp中,因为view类覆盖在框架类上,鼠标
的点击也是在view上,点不到框架类上,因此函数可能不会被执行到。
  相关解决方案