在CRectView中加入如下代码:void CRectView::OnLButtonDown(UINT nFlags, CPoint point)
{
CRectTracker temp;
temp.TrackRubberBand(this,point,TRUE);
temp.m_rect.NormalizeRect();
CView::OnLButtonDown(nFlags, point);
}//上面这段代码可以实现这样的功能:按下鼠标,随着鼠标的移动画虚线框矩形。但是,当鼠标左键弹起时,虚线框就没了,我想要鼠标弹起时,虚线框仍然在。于是,我在void CRectView::OnLButtonUp(UINT nFlags, CPoint point)中添加如下代码:void CRectView::OnLButtonUp(UINT nFlags, CPoint point)
{
CRectTracker rect;
rect.m_rect.SetRect(PtBegin.x,PtBegin.y,point.x,point.y);
rect.Draw(pDC);
}为什么按上面做了后,鼠标弹起时仍然没有虚线框???
{
CRectTracker temp;
temp.TrackRubberBand(this,point,TRUE);
temp.m_rect.NormalizeRect();
CView::OnLButtonDown(nFlags, point);
}//上面这段代码可以实现这样的功能:按下鼠标,随着鼠标的移动画虚线框矩形。但是,当鼠标左键弹起时,虚线框就没了,我想要鼠标弹起时,虚线框仍然在。于是,我在void CRectView::OnLButtonUp(UINT nFlags, CPoint point)中添加如下代码:void CRectView::OnLButtonUp(UINT nFlags, CPoint point)
{
CRectTracker rect;
rect.m_rect.SetRect(PtBegin.x,PtBegin.y,point.x,point.y);
rect.Draw(pDC);
}为什么按上面做了后,鼠标弹起时仍然没有虚线框???
解决方案 »
- VC,如何用ctrl+tab实现两个按钮的切换?
- 关于WSAAsyncSelect的hWnd
- 求算法实现问题
- 菜鸟问题, vc7的bug? 有的继承类调试时看不到成员参数。
- 如何使某个控件获得焦点时在鼠标的下面显示提示信息
- 公告!封杀shangroad (shangroad)oldforest(老式森林)
- BSTR问题
- 请教对话框关闭后,能否使mainframe的OnCreateClient执行??
- OpenGL中绘制飞行器,模型驱动的方法
- 关于edit组件的两个问题。(在线等待,马上给分)
- 能开发出金山词霸界面和快播界面,现在能找到工作吗??
- 薪水报价贴!兄弟们都进来报报价,走过路过不要错过
{
// TODO: Add your message handler code here and/or call default CRectTracker temp;
temp.TrackRubberBand(this,point,TRUE);
temp.m_rect.NormalizeRect();
m_rect.SetRect(temp.m_rect.TopLeft(), temp.m_rect.BottomRight());
InvalidateRect(m_rect, TRUE);
CView::OnLButtonDown(nFlags, point);
}
void CRectView::OnDraw(CDC* pDC)
{
CCRectDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here CPen pen(PS_DOT, 0, RGB(128, 0, 0));
HPEN hOldPen = (HPEN)pDC->SelectObject(pen);
pDC->Rectangle(m_rect); pDC->SelectObject(hOldPen);
pen.DeleteObject();
}
其实如果你在LButtonDown、LButtonUp这两个消息响应函数中分别插入一个AfxMessageBox,你就会发现,当你按下鼠标的时候LButtonDown响应了,可是如果你松掉鼠标时,却没有响应LButtonUp(其实MouseMove也没有响应),这是因为在你拖动“橡皮带”的时候,函数仍处于LButtonDown函数中,一直到你松掉鼠标,LButtonDown中的TrackRubberBand才结束,所以在你在按住鼠标左键的时候,不管你怎么拖动,你都还在TrackRubberBand里,也就是LButtonDown里,MouseMove一直都没有响应,LButtonUp也一直都得不到响应~~~~
我的代码是这样的,话说自己研究这个2天了,才发现解决方法~~~唉~~CRectTracker RectTracker(CRect(0,0,0,0),CRectTracker::resizeOutside|CRectTracker::dottedLine);
RectTracker.TrackRubberBand(this,CurPoint,1);
::GetCursorPos(&CurPoint);
::ScreenToClient(m_hWnd,&CurPoint);
TrackerRect = CRect(OldPoint.x,OldPoint.y,CurPoint.x,CurPoint.y);
RectTracker.m_rect = CRect(OldPoint.x,OldPoint.y,CurPoint.x,CurPoint.y);
RectTracker.Draw(pdc);
void Ctest5View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//Ctest5Doc* pDC = (Ctest5Doc*)AfxGetMainWnd();
//AfxMessageBox(TEXT("Donw")); OldPoint = point;
RectTracker(CRect(0,0,0,0),CRectTracker::resizeOutside|CRectTracker::dottedLine);
RectTracker.TrackRubberBand(this,CurPoint,1);
::GetCursorPos(&CurPoint);
::ScreenToClient(m_hWnd,&CurPoint);
TrackerRect = CRect(OldPoint.x,OldPoint.y,CurPoint.x,CurPoint.y);
RectTracker.m_rect = CRect(OldPoint.x,OldPoint.y,CurPoint.x,CurPoint.y);
RectTracker.Draw(pdc);
pdc = GetDC();
CView::OnLButtonDown(nFlags, point);
}