Copying to the clipboard - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Copying to the clipboard

I currently have an application that draws to a DC (CDC to be specific) and I need to implement a Copy function. The message handlers, etc. are all in place, however, I can't seem to get things to the ClipBoard. Below is my code. I think it is self-explanatory. The code runs normally but when I try to paste into MS Word, for example, I get an error stating "the instruction at "0x00000017" referenced memory at "0x00000017". The memory could not be "read" followed by "There is not enough memory or disk space to complete the operation."

Any tips are GREATLY appreciated.

-Kirk


COleDataSource dataSource; //object to contain the data
CBitmap *oldBitmap, newBitmap; //bitmaps for the DC
CDC imageDC; //DC to hold the drawings
CClientDC viewDC(this); //clientDC which effectively holds the specifics of the current View

STGMEDIUM *dataContainer; //contains the data passed to the clipboard
dataContainer = new STGMEDIUM;

imageDC.CreateCompatibleDC(&viewDC); //create a DC compatible with the current view
newBitmap.CreateCompatibleBitmap(&imageDC, 500, 500); //create a bitmap

//select in the bitmap in so I can draw on it
oldBitmap = imageDC.SelectObject(&newBitmap);

//execute this view's draw operations
OnDraw(&imageDC);

//get the bitmap out
oldBitmap = imageDC.SelectObject(oldBitmap);
//manipulate the data into the proper format to load onto the clipboard
dataContainer->tymed = TYMED_GDI;
dataContainer->hBitmap = (HBITMAP)(*oldBitmap);
dataSource.CacheData(CF_BITMAP, dataContainer);
dataSource.SetClipboard();

return;

Sign In or Register to comment.