Home > Software engineering >  With the cycle of death after drawing frame no response
With the cycle of death after drawing frame no response

Time:11-03

Request click menu options after using the mouse to draw a rectangle
I want to wait for the mouse give a starting point and end point after drawing, but drawing when using infinite loop control box would have been no response
How to solve it
//get the mouse start 
Void CtxxView: : OnLButtonDown (UINT nFlags, CPoint point)
{
//TODO: add the message handler code and/or invoke the default
This - & gt; SetCapture ();//to capture the mouse
The StartPoint=point;
The EndPoint=point;
LButtonDown=true;
The CView: : OnLButtonDown (nFlags, point);
}
//get the mouse at the end of the
Void CtxxView: : OnLButtonUp (UINT nFlags, CPoint point)
{
//TODO: add the message handler code and/or invoke the default
ReleaseCapture ();//release the mouse
The EndPoint=point;
LButtonUp=true;
The CView: : OnLButtonUp (nFlags, point);
}


Void CtxxView: : OnDrawRetectangle ()
{
//TODO: add the command handler code
LButtonDown=LButtonUp=false;
While (1)
{
If (LButtonDown==true & amp; & LButtonUp==true)
break;
}
The CDC * pDC=this - & gt; GetDC ();
DDALine (pDC, the StartPoint. X, the StartPoint. Y, the EndPoint. X, the StartPoint. J y, RGB (255, 0, 0));
DDALine (pDC, EndPoint. X, the StartPoint. Y, the EndPoint. X, the EndPoint. The y, RGB (255, 0, 0));
DDALine (pDC, EndPoint. X, the EndPoint. Y, the StartPoint. X, the EndPoint. The y, RGB (255, 0, 0));
DDALine (pDC, the StartPoint. X, the EndPoint. Y, the StartPoint. X, the StartPoint. J y, RGB (255, 0, 0));


}

CodePudding user response:

Should use a member variable in OnDrawRetectangle note click the map options, rather than write an infinite loop,
OnLButtonDown OnLButtonUp, record the start and end, respectively, and then to draw a rectangle in the OnLButtonUp,

Simple point so to try to modify:
 
//get the mouse start
Void CtxxView: : OnLButtonDown (UINT nFlags, CPoint point)
{
//TODO: add the message handler code and/or invoke the default
This - & gt; SetCapture ();//to capture the mouse
The StartPoint=point;
The EndPoint=point;
LButtonDown=true;
The CView: : OnLButtonDown (nFlags, point);
}
//get the mouse at the end of the
Void CtxxView: : OnLButtonUp (UINT nFlags, CPoint point)
{
//TODO: add the message handler code and/or invoke the default
ReleaseCapture ();//release the mouse
The EndPoint=point;
LButtonUp=true;
The CView: : OnLButtonUp (nFlags, point);

If (m_action==ActionDrawRect) {
//draw a rectangle
The CDC * pDC=this - & gt; GetDC ();
DDALine (pDC, the StartPoint. X, the StartPoint. Y, the EndPoint. X, the StartPoint. J y, RGB (255, 0, 0));
DDALine (pDC, EndPoint. X, the StartPoint. Y, the EndPoint. X, the EndPoint. The y, RGB (255, 0, 0));
DDALine (pDC, EndPoint. X, the EndPoint. Y, the StartPoint. X, the EndPoint. The y, RGB (255, 0, 0));
DDALine (pDC, the StartPoint. X, the EndPoint. Y, the StartPoint. X, the StartPoint. J y, RGB (255, 0, 0));
}
}

Void CtxxView: : OnDrawRetectangle ()
{
M_action=ActionDrawRect;//if defines the enumeration values ActionDrawRect menu options, what kind of behavior, using m_action to record the
}
  • Related