Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

copy cwgraph to clipboard

A few months a go I found an example code for copying a cwgraph to the clipboard - It worked perfectly.
Since then I upgraded to ComponentWorks V6.0 and the code stopped working. I keep getting the following message : "Unable to set clipboard data", Any Idea why?

I attached a copy of the code

Thank you in advance
0 Kudos
Message 1 of 5
(3,684 Views)
The problem is that before Measurement Studio 6.0 the ControlImage method returned a metafile. ControlImage was updated in Measurement Studio 6.0 to return an enhanced metafile. Here's a short snippet that shows how to copy the enhanced metafile that's returned from ControlImage to the clipboard.

// Assuming that the class has a m_graph member that is a CNiGraph
CNiPicture pic = m_graph.ControlImage();

::OpenClipboard(NULL);
::EmptyClipboard();
::SetClipboardData(
CF_ENHMETAFILE,
::CopyEnhMetaFile(reinterpret_cast(pic.Handle), NULL)
);
::CloseClipboard();

Hope this helps.

- Elton
Message 2 of 5
(3,684 Views)
Hi,

I tried using this code . but I don't know what cnipictire is and CopyEnhMetaFile is not avalable for use.

Is this all the code I need for copying the graph?
0 Kudos
Message 3 of 5
(3,684 Views)
Are you using Measurement Studio for Visual C++ or are you using the wrappers that MFC automatically generates for CWGraph? If it's the former, CNiPicture is in the Common component, so every project that uses the Measurement Studio libraries for Visual C++ should have access to this class. If it's the latter, you may want to look into using the Measurement Studio libraries for Visual C++ since they were designed to be used natively in C++. If you don't want to change your code, though, you should be able to use the CPicture class and GetHandle() methods that you were using before instead of CNiPicture and the Handle property that were used in the example above.

CopyEnyMetaFile is a Win32 GDI function that's been around since Windows 95. Y
ou should be able to use it as long as you've #include'd windows.h and are linking to gdi32.lib.

- Elton
0 Kudos
Message 4 of 5
(3,684 Views)
I do not use wrapper class and am using cwui.ocx in ATL environment. The code below did send the image to the clipboard, however, axis/legend fonts are overlapped. Any suggestions to correct this problem? Thanks!

OLE_HANDLE oleHandle;
IPicturePtr pPicture;

IPictureDispPtr pPictureDisp = m_pCWGraph->ControlImage();
pPictureDisp->QueryInterface(IID_IPicture, (LPVOID*)&pPicture);
pPicture->get_Handle(&oleHandle);

::OpenClipboard(NULL);
::EmptyClipboard();
::SetClipboardData(CF_ENHMETAFILE, ::CopyEnhMetaFile(reinterpret_cast(oleHandle), NULL));
::CloseClipboard();
0 Kudos
Message 5 of 5
(3,684 Views)