MFC绘制矩形
4个回答
展开全部
在MFC中画矩形Visual Studio 2008
//首先创建一个MFC工程,名为:Rectangle,在界面上放置一个picture control的控件,其关联变量为:m_showRectangle。
//然后添加鼠标事件,OnLButtonDown,OnLButtonUp,OnMouseMove
//BOOL lButtonDownNotUp=FALSE;
//CPoint regionLeftTopTemp;
//CPoint regionRightBottomTemp;
void CRectangleDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
lButtonDownNotUp = TRUE;
RECT rect;
m_showRectangle. GetClientRect( &rect ) ;
if( (point. x<rect. right) && (point. x>rect. left) && (point. y<rect. bottom) && (point. y>rect. top) )
{
regionLeftTopTemp = point;
}
CDialog::OnLButtonDown(nFlags, point);
}
void CRectangleDlg::OnMouseMove(UINT nFlags, CPoint point)
{
RECT rect;
m_showRectangle. GetClientRect( &rect );
if( ( point.x<rect.right ) && ( point.x>rect.left ) && ( point.y<rect.bottom ) && ( point.y>rect.top ) )
{
if( ( lButtonDownNotUp == TRUE )
{
regionRightBottomTemp = point;
CDC * pDC = m_showRectangle. GetWindowDC ();
pDC -> Rectangle( CRect( regionLeftTopTemp, regionRightBottomTemp ) ) ;
}
}
CDialog::OnMouseMove(nFlags, point);
}
void CRectangleDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
lButtonDownNotUp=FALSE;
CDialog::OnLButtonUp(nFlags, point);
}
//首先创建一个MFC工程,名为:Rectangle,在界面上放置一个picture control的控件,其关联变量为:m_showRectangle。
//然后添加鼠标事件,OnLButtonDown,OnLButtonUp,OnMouseMove
//BOOL lButtonDownNotUp=FALSE;
//CPoint regionLeftTopTemp;
//CPoint regionRightBottomTemp;
void CRectangleDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
lButtonDownNotUp = TRUE;
RECT rect;
m_showRectangle. GetClientRect( &rect ) ;
if( (point. x<rect. right) && (point. x>rect. left) && (point. y<rect. bottom) && (point. y>rect. top) )
{
regionLeftTopTemp = point;
}
CDialog::OnLButtonDown(nFlags, point);
}
void CRectangleDlg::OnMouseMove(UINT nFlags, CPoint point)
{
RECT rect;
m_showRectangle. GetClientRect( &rect );
if( ( point.x<rect.right ) && ( point.x>rect.left ) && ( point.y<rect.bottom ) && ( point.y>rect.top ) )
{
if( ( lButtonDownNotUp == TRUE )
{
regionRightBottomTemp = point;
CDC * pDC = m_showRectangle. GetWindowDC ();
pDC -> Rectangle( CRect( regionLeftTopTemp, regionRightBottomTemp ) ) ;
}
}
CDialog::OnMouseMove(nFlags, point);
}
void CRectangleDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
lButtonDownNotUp=FALSE;
CDialog::OnLButtonUp(nFlags, point);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Rectangle (
Coordinates upperLeft,
Coordinates lowerRight
)
Rectangle (
int left,
int top,
int right,
int bottom
)
在view类的OnDraw函数里添加
pDc->Rectangle(); 参数如上
Coordinates upperLeft,
Coordinates lowerRight
)
Rectangle (
int left,
int top,
int right,
int bottom
)
在view类的OnDraw函数里添加
pDc->Rectangle(); 参数如上
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用4下moveto lineto就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
rect 也行 brush 也行的 要代码 留言
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询