大家可以参考我的框架程序,完成后续教程编成,思考if (m_bDrag)中能否将m_bDrag换成m_bClickEmpty?
1.将下面代码添加到学号view.h文件中
bool m_bClickEmpty; //判断是否点击了空白的地方,以实现拖动框选择
CPoint OldEmptyBegin;//点击空白开始的座标
CPoint NowEmptyEnd;//移动时保存座标
2.将下面添加到学号view.cpp文件中void CCellPrg226View::OnMouseMove(UINT nFlags, CPoint point)函数里面(270行)
if (m_bDrag)//思考能否将m_bDrag换成m_bClickEmpty
{
CClientDC dc(this);
CBrush* pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush* POldBrush = dc.SelectObject(pBrush);
int nOldMode = dc.SetROP2(R2_NOTXORPEN);
dc.Rectangle(&CRect(OldEmptyBegin, NowEmptyEnd));
dc.Rectangle(&CRect(OldEmptyBegin, point));
NowEmptyEnd = point;
dc.SelectObject(POldBrush);
dc.SetROP2(nOldMode);
}
3.将下面添加到学号view.cpp文件中void CCellPrg226View::OnLButtonDown(UINT nFlags, CPoint point)函数里面
m_bClickEmpty = true;
OldEmptyBegin = point;
NowEmptyEnd = point;
效果
评论 (0)