Solved

Copy and Paste in MFC

Posted on 1998-07-07
4
216 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
  • 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 50 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 83
substring method in java 1 79
Smart Camera scanning and reading information 3 86
zeroMAx challenge 20 76
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now