Home > Software engineering >  How do you drag the elements in the graphic interface?
How do you drag the elements in the graphic interface?

Time:09-21

His drawing of a simple interface, as there is one small square,
With a save the position of each element the rect structure, color, etc.,
Now want to enable him to drag, now is the time to according to LButtonDown and mousemove click on the location of the record,
Move when redrawwindow messages sent,
When OnPaint with double buffer in the memory dc, because move have to remember is
Fall in the mouse position, the current mouse position, the state of the mouse, which coordinates, etc., should be displayed in the current calculation
But the results with the expected difference is very big, don't know where is,
This kind of situation have a better solution? To track the mouse drag
Interface elements of subclassing, the pictures together,
A CRectTracker is doing this?

CodePudding user response:

Space inheritance CRectTracker see, this class is permitted to move, you realize remember the mouse coordinates, remember to do turn screen coordinates window coordinates,,

CodePudding user response:

1 in the derived class processing without LButtonDown
2 make sure position
3 do not use redrawwindow, this is the updated synchronously, with Invalidate (); Paint can accumulate the invalid area (not always)!
 
//CMyStatic message handlers
Void CMyStatic: : onm ouseMove (UINT nFlags, CPoint point)
{
//TODO: Add your message handler code here and/or call the default
The static CPoint ptLast;
//
If (MK_LBUTTON==nFlags)
{
CRect rc;
GetWindowRect (& amp; Rc);
The ScreenToClient (& amp; Rc);
MapWindowPoints (GetParent (), & amp; Rc);
MoveWindow (rc) left + point. X-ray ptLast. (x), rc. The top + point. Y - ptLast. (y), rc. The Width (), rc, Height ());
}
The else
{
PtLast=point;
CStatic: onm ouseMove (nFlags, point);
}
Invalidate ().
}

CodePudding user response:

Use OPenGL to do it, it's much more convenient than you,

CodePudding user response:

According to your idea to do,
Drag the display after drawing is wrong, there should be no conversion coordinates,
Converts the coordinates of the mouse into the coordinates of the relative window,
MouseMove, of course, there is a mouse in the LButtonDown coordinates, you can break point and see if it's relative to the window,

CodePudding user response:

Thinking is correct, it is calculated out of the question, https://download.csdn.net/download/hhhh63/7710711, have a look at the help,

CodePudding user response:

https://www.codeproject.com/search.aspx? Q=CRectTracker& Sbo=kw& X=0 & amp; Y=0
  • Related