?
Solved

Copy and Paste in MFC

Posted on 1998-07-07
4
Medium Priority
?
224 Views
Last Modified: 2013-11-19
I used the clipboard assistant in the projects/contols menu. This generated some code using the open
    clipboard(),Setclipboard() etc functions. I need to copy the entire client space which happens to be
    graph into clipboard. This copies the stuff onto the clipboard but I am not able to paste it elsewhere like
    windows paint or elsewhere. Actually I am not able to access the clipboard data so I am not sure if this
    even copies it to the clipboard. What do I do???
0
Comment
Question by:sram
[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
  • 2
  • 2
4 Comments
 

Expert Comment

by:bfwizard
ID: 1318818
what kind of data is your graph....is it a bit map or just data in the document?
0
 

Author Comment

by:sram
ID: 1318819
It is data coming from a data aquisition board which is plotted on the client space using OnDraw(), by updating the client space using the OnTimer() function.
0
 

Author Comment

by:sram
ID: 1318820
It is data coming from a data aquisition board which is plotted on the client space using OnDraw(), by updating the client space using the OnTimer() function.
0
 

Accepted Solution

by:
bfwizard earned 200 total points
ID: 1318821
well...this is a long answer and if you need more detailed info leave a comment here.  The basic thing to do is make sure you selected the custom clipboard format when you created it with components.  

.first the a little backround.  The clip board acts like a file in which you can serilize to and from.  A good example I will use is say selecting numbers from the screen...this should translate fine to your problem. So in the client area we have the numbers on the screen:
3 4 5
we know where they are exist on the screen and we know what they look like.
in the document our data might be where the number is and its value.  Maybe two lists
llist1={3,4,5} //the values
llist2={{2,3},{4,3},{6,3}}//for the locations

now say I select the number 4 on the screen. and I cut it.
first the function IsSelected is called....you have to decide if it is selcted or not
the next thing that happens is OnEditCut is called (note you wont have to change this at all)  this calls DoCutCopyPaste which does the work.  What you have to do is cut the the numbers 3 and 5 and there locations off the lists in the document.  The numbers 3 and 5 should be placed on some hold lists.  so you have got:

llist1={4} //the values in the document
llist2={{4,3}}//for the locations

Templist1={3,5} //the values in a temp list
Templist2={{2,3},{6,3}}//for the locations in a temp list

this should be done in some function that you call before any other functions are called in
DoCutCopyPaste.  The rest of the code in this function is fine...don't change it...just add a  function that breaks things up into lists before all the other things are called.
what happens in the rest of the code in this function is the clipboard serelizes anything in the document...which in our case in the two llists with just the 3.  The hold list is not touched.  then the function deletecontents is called which wipes all the data out of the document...so the llists become empty....so the result is 3 is saved on the clipboard, but wiped from memory.  Note copy calls this function as well and if everthing works for cut it should work for copy as well (you shouldn't have to change a thing)....so when you copy your function gets called just like in when you cut...they break up the two lists to four list saveing only the 3 in the document and the other number on the hold list...the document gets serilized so the number 3 is saved...again the hold list is not touched.  But deletecontents is not called!!!  so the result is the 3 is serlized on the clip board and not errased from the document...and you still have the other two hold lists.

After both the cut and copy operations...the OnUpdate function is called and must be overriden.  What you should do here is get your data from the document...on a cut there will be none...on a copy there will be the 3.
and merge the holdlists into the lists in the document:

after a cut
llist1={}
llist2={{}} //both empty lists

hlist1={2,5}
hlist2={{3,5},{5,5}

you need to have the result be

llist1={2,5}
llist2={{3,5},{5,5}

///makes sure your hold lists are empty

now you have all the data minus the 3 in your document...so your ondraw or whatever can do its thing

with copy its the same only the llist will have the 3 in it and the hold list must be merged onto the documents list...

good...

now on a paste operation your function in the DoCutCopyPaste just needs to put everthing
on the hold list...that way when OnUpdate gets called the number 3 gets serilized back...and your document will have the list from off the clipboard...now you just merge the hold lists into the document data....and you've got it.  Another thing to keep in mind is where you paste...maybe where the user last clicked in the window...with that info you just need to change the 3 location.  then ondraw does its thing when all the data is back into the document

You should end up with a bare bones that looks like these functions:

void CCutterView::OnUpdateEditCopyCut(CCmdUI* pCmdUI)
 ...........this you wont have to touch

void CCutterView::OnUpdateEditPaste(CCmdUI* pCmdUI)
.....this you wont have to touch

void CCutterView::OnEditCopy()
..this you wont have to touch

void CCutterView::OnEditCut()
.this you wont have to touch

void CCutterView::OnEditPaste()
.this you wont have to touch

BOOL CCutterView::IsSelected()
..this you will have to add to
somehow you must decide if your graph is selected or not..just return TRUE if it is FALSE otherwise.



void CCutterView::DoCutCopyPaste(CArchive &ar, BOOL bCut)
..add your function here to chop up the list...it needs to be the very first function called

then finally you need to override OnUpdate which gets called after everything.


long answer...




0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

800 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