How to move cirlce in MFC?
-
Hey how can i move CClientDC object in client window using mouse ? i did it but it show last cicle on screen. If i do Invalidate to TRUE it moves the circle but did'nt show properly in Dialog box. if((nFlags & MK_LBUTTON)==MK_LBUTTON) { CClientDC obj(this); x=(point.x)-50; y=(point.y)-50; obj.Ellipse(x,y,x+100,y+100); } Invalidate(FALSE); So what should i do ???
Regards: Xohaib Shirani
-
Hey how can i move CClientDC object in client window using mouse ? i did it but it show last cicle on screen. If i do Invalidate to TRUE it moves the circle but did'nt show properly in Dialog box. if((nFlags & MK_LBUTTON)==MK_LBUTTON) { CClientDC obj(this); x=(point.x)-50; y=(point.y)-50; obj.Ellipse(x,y,x+100,y+100); } Invalidate(FALSE); So what should i do ???
Regards: Xohaib Shirani
You've to put the drawing stuff inside the
WM_PAINT
handler. Then you'll ask for an update (outside of the above handler) whenever appropriate (for instance using a timer if you need to move continuosly). :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
You've to put the drawing stuff inside the
WM_PAINT
handler. Then you'll ask for an update (outside of the above handler) whenever appropriate (for instance using a timer if you need to move continuosly). :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeCPaintDC obj(this); x=(point.x)-50; y=(point.y)-50; obj.Ellipse(x,y,x+100,y+100); it didn't work.And i also tried this by defining CPaintDC obj in OnPaint fucntion x=(point.x)-50; y=(point.y)-50; CDC *ptr=CDialog::GetDC(); ptr->Ellipse(x,y,x+100,y+100); these both are not working.
Regards: Xohaib Shirani
-
CPaintDC obj(this); x=(point.x)-50; y=(point.y)-50; obj.Ellipse(x,y,x+100,y+100); it didn't work.And i also tried this by defining CPaintDC obj in OnPaint fucntion x=(point.x)-50; y=(point.y)-50; CDC *ptr=CDialog::GetDC(); ptr->Ellipse(x,y,x+100,y+100); these both are not working.
Regards: Xohaib Shirani
What do you mean with: "doesn't work"? Please detail. :) BTW you have to use
CPaintDC dc(this);
inside theOnPaint
handler.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
What do you mean with: "doesn't work"? Please detail. :) BTW you have to use
CPaintDC dc(this);
inside theOnPaint
handler.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Yes dear i add CPaintDC obj(this); but it doesn't work properly. It leave the last effect of circle mean it moves the circle but the some effects of circle remain on the screen.
Regards: Xohaib Shirani
Shirani wrote:
It leave the last effect of circle mean it moves the circle but the some effects of circle remain on the screen.
:confused: Do you properly invalidate the painting area?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Shirani wrote:
It leave the last effect of circle mean it moves the circle but the some effects of circle remain on the screen.
:confused: Do you properly invalidate the painting area?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
yes if i invalidate the painting area it hides the circle after moving it, You can check it by urself.
Regards: Xohaib Shirani
I made a test, and, of course ;P , it works well.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
yes if i invalidate the painting area it hides the circle after moving it, You can check it by urself.
Regards: Xohaib Shirani
Where you are calling Invalidate, is it after painting in the OnPaint Handler? And are you still drawing in the move handler? In the Move Handler just update the position to member variable and invalidate the client region, invalidate will cause the paint to happen, And in your OnPaint Handler draw the ellipse, don't call invalidate in OnPaint Handler. If you are not painting the background by overriding the OnEraseBkgnd method, then also previous ellipse remains on the DC.
-
Where you are calling Invalidate, is it after painting in the OnPaint Handler? And are you still drawing in the move handler? In the Move Handler just update the position to member variable and invalidate the client region, invalidate will cause the paint to happen, And in your OnPaint Handler draw the ellipse, don't call invalidate in OnPaint Handler. If you are not painting the background by overriding the OnEraseBkgnd method, then also previous ellipse remains on the DC.