void CTyuiDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if ((nFlags&MK_LBUTTON)==MK_LBUTTON)
{
CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(256,256,256));
dc.SelectObject(&pen);
dc.Ellipse(m_x,m_y,point.x,point.y);
// dc.Rectangle(10,10,point.x,point.y);
}
CDialog::OnMouseMove(nFlags, point);
}
void CTyuiDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_x=point.x;
m_y=point.y;
CDialog::OnLButtonDown(nFlags, point);
}
void CTyuiDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.Ellipse(m_x,m_y,point.x,point.y) ;
// dc.Rectangle(m_x,m_y,point.x,point.y);
CDialog::OnLButtonUp(nFlags, point);
}
按下鼠标左键,光标位置被m_x,m_y记录,然后随鼠标画圆或椭圆,我只想模拟“画图程序”中的做法,但是,随着鼠标画了一大堆圆,我只想要最后一个。我想用RGB(256,256,256)画透明的圆,在OnLButtonUp画一个黑色的圆,没成功。
问问“怎么擦除不想要的圆”
{
// TODO: Add your message handler code here and/or call default
if ((nFlags&MK_LBUTTON)==MK_LBUTTON)
{
CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(256,256,256));
dc.SelectObject(&pen);
dc.Ellipse(m_x,m_y,point.x,point.y);
// dc.Rectangle(10,10,point.x,point.y);
}
CDialog::OnMouseMove(nFlags, point);
}
void CTyuiDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_x=point.x;
m_y=point.y;
CDialog::OnLButtonDown(nFlags, point);
}
void CTyuiDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.Ellipse(m_x,m_y,point.x,point.y) ;
// dc.Rectangle(m_x,m_y,point.x,point.y);
CDialog::OnLButtonUp(nFlags, point);
}
按下鼠标左键,光标位置被m_x,m_y记录,然后随鼠标画圆或椭圆,我只想模拟“画图程序”中的做法,但是,随着鼠标画了一大堆圆,我只想要最后一个。我想用RGB(256,256,256)画透明的圆,在OnLButtonUp画一个黑色的圆,没成功。
问问“怎么擦除不想要的圆”
{
// TODO: Add your message handler code here and/or call default
if ((nFlags&MK_LBUTTON)==MK_LBUTTON)
{
dc.Ellipse(m_x,m_y,point.x,point.y);
// dc.Rectangle(10,10,point.x,point.y);
}CDialog::OnMouseMove(nFlags, point);
}
void CTyuiDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_x=point.x;
m_y=point.y;
CDialog::OnLButtonDown(nFlags, point);
}void CTyuiDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_x2 = point.x;
m_y2 = point.y
Invalidate();
CDialog::OnLButtonUp(nFlags, point);
}void CTyuiDlg::OnPaint()
{
CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(256,256,256));
dc.SelectObject(&pen);
dc.Ellipse(m_x,m_y,m_x2,m_y2) ;
}
void CTyuiDlg::OnPaint()
{
CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(256,256,256));
dc.SelectObject(&pen);
int Radius = int(sqr((m_x2-m_x)*(m_x2-m_x)+(m_y2-m_y)*(m_y2-m_y)));
dc.Ellipse(m_x-Radius,m_y-Radius,m_x+Radius,m_y+Radius) ;
}
(2)每次在新的位置画时,先在原来的位置画一下。(XOR模式下画了以后,再画一次就擦除了)。没人回答是因为很多人不用VC++/MFC了,我就是其中一个
LZ的问题是鼠标拖动中绘制,就是那种橡皮筋矩形,如果放到OnPaint中,鼠标一动就要Invalidate,会造成屏幕闪烁。
最好画完了存到内存对象以后,再Invalidate(),从OnPaint中画。