Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

Copying a DC's content onto clipboard in OWL win 32

In OWL 5.0 the TDC class has some win32 features like BeginPath, EndPath, FillPath etc. There also is a TMetaFileDC class which can be used to paint on. The normal DC functions are properly put on it. I can then use the TMetaFilePict class to simply copy it to the clipboard as a windows metafile. But the win32 features are ignored (which is mentioned in the manuals also). They don't mention how to
get it to the clipboard properly though.

Thanks in Advance,

Wout de Zeeuw
0
zeeuw
Asked:
zeeuw
  • 4
  • 3
1 Solution
 
md041797Commented:
Try this:

Make a TMetaFileDC fdc and fill it.  Then open the clipboard, call SetClipboardData (CF_DSPENHMETAFILE, fdc.CloseEnh()); and close it.


0
 
zeeuwAuthor Commented:
I tried the following, which didn't work:

TMetaFileDC            dc;
TClipboard            Clipboard(*this);

      Paint(dc, true, TRect());
   Clipboard.OpenClipboard(*this);
      if (!Clipboard.SetClipboardData(CF_DSPENHMETAFILE, dc.Close()))
            MessageBox("Error", "Message", MB_OK);
   Clipboard.CloseClipboard();

The SetClipboardData function returns false, and also dc.IsEnhanced() returns false. I find this DC stuff very complicated, perhaps someone can give me a working example of how to copy to a clipboard when having the Paint function available and using win32 features.

Thanks in advance,

Wout de Zeeuw
0
 
md041797Commented:
Use dc.CloseEnh, not dc.Close.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
zeeuwAuthor Commented:
Thanks for the quick reply, I tried using the CloseEnh() member function too, but it didn't work:

TMetaFileDC            dc;
TClipboard            Clipboard(*this);

      if (!dc.IsEnhanced())
         MessageBox("dc is not enhanced", "Message", MB_OK);
      Paint(dc, true, TRect());
   Clipboard.OpenClipboard(*this);
      if (!Clipboard.SetClipboardData(CF_DSPENHMETAFILE, dc.CloseEnh()))
            MessageBox("Error", "Message", MB_OK);
   Clipboard.CloseClipboard();

When executing I see that the dc is not enhanced. There is some constructor TMetaFileDC which takes another dc as an argument which would result in a win32 Metafile, but I don't know how that would work. Perhaps you see the error in my code?

Thanks for looking at it,

Wout de Zeeuw
0
 
zeeuwAuthor Commented:
Just an addition on my last note. I don't get any errors when I run this piece of code, the SetClipboardData doesn't return false or anything, but nothing appears on the clipboard. I also tried

TClientDC            cdc(*this);
TMetaFileDC            dc(cdc);
TClipboard            Clipboard(*this);

In which the dc is enhanced, but this didn't copy anything to the clipboard either. So I suspect I'm doing something stupid with the constructing of the dc's.

Wout de Zeeuw

0
 
zeeuwAuthor Commented:
Hello again,

Almost solved... the copying works now, except that the colors don't get copied properly:

TMetaFileDC            dc(CreateEnhMetaFile(0, 0, 0, "App Title\0Title\0\0"));
TClipboard            Clipboard(*this);

      if (!dc.IsEnhanced())
         MessageBox("dc is not enhanced", "Message", MB_OK);
      Paint(dc, true, TRect());
   Clipboard.EmptyClipboard();
      if (!Clipboard.SetClipboardData(CF_ENHMETAFILE, dc.CloseEnh()))
            MessageBox("Error copying to clipboard", "Message", MB_OK);

So just another define for the enhanced metafile thing. Thanks for the CloseEnh() tip, I'd still like to give you half the points for it :-)

Wout

0
 
md041797Commented:
I don't have a clue why the colors don't work, but here's an answer if you want to give me points.

Thanks.


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now