Link to home
Start Free TrialLog in
Avatar of JoyBurke
JoyBurke

asked on

Dragging graphics with mouse

I've created a scrollview in which graphic boxes, lines, charts,  etc. are drawn on the screen. I've been drawing them by overriding the OnDraw of the view and passing the pDC to various object classes I've created to draw the objects.

Now I'm trying to add some functionality by allowing the user to click and drag the objects. I'm thinking that redrawing every time the mouse moves (using the windows message) will cause major flicker and is a bad idea. I need the objects (and a mouse popup) to follow the cursor.

My question is, what would be the best technique to allow users to drag drawn objects? Should I just invalidate a portion of the window and re-draw?

(note: point value higher since I need the solution quickly. probably not very difficult)
Avatar of AlexFM
AlexFM

Check out MFC sample DRAWCLI. It shows how to do this and redraws the screen by optimal way using memory DC and minimizing the clipping area. It has all you need to drag graphic objects except automatic scrolling during dragging. I will try also to find the sample which shows automatic scrolling.
About automatic scrolling:

http://www.microsoft.com/msj/0898/wicked0898.aspx

This sample implements automatic scrolling by timer in tree control, but you can get an idea how to do this in scroll view.
Avatar of JoyBurke

ASKER

That example uses OleDataObjects. Do I need to learn to use OleObjects to do this?

Previously I had CObjects stored in a list. They are created only for the view and don't need to be saved or have extensive capability.

The example is helpful, but I'm having a hard time picking through it to find what I need to use.
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No, ignore all OLE stuff and read only about simple graphic objects like rectangles.
If you need a fast solution, use CRectTracker.
I'm a beginner and having a hard time picking through all these examples.

what is a hatched rectangle and how does it get drawn?
Could you give me a basic pseudocode? (ie: On mouse move, redraw just the rectangle by....)
This is a thin dotted rectangle which is moved with the mouse showing current position of the object. When user releases mouse, object itself is redrawn on the new place. Build the TRACKER sample and see how it works. CRectTracker class handles all implementation details. This is really fast solution.
Thanks for all your help and patience!