Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dragging graphics with mouse

Posted on 2003-11-19
9
Medium Priority
?
688 Views
Last Modified: 2013-11-20
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)
0
Comment
Question by:JoyBurke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9780158
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.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9780314
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.
0
 

Author Comment

by:JoyBurke
ID: 9780318
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 48

Accepted Solution

by:
AlexFM earned 600 total points
ID: 9780346
And the last point:

DRAWCLI makes full redrawing of dragged object. Another approach is drawing only hatched rectangle during dradding and redraw the full object only when mouse button is released. To do this check out MFC class CRectTracker and MFC sample TRACKER.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9780357
No, ignore all OLE stuff and read only about simple graphic objects like rectangles.
If you need a fast solution, use CRectTracker.
0
 

Author Comment

by:JoyBurke
ID: 9780529
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?
0
 

Author Comment

by:JoyBurke
ID: 9780601
Could you give me a basic pseudocode? (ie: On mouse move, redraw just the rectangle by....)
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9780607
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.
0
 

Author Comment

by:JoyBurke
ID: 9781606
Thanks for all your help and patience!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question