Solved

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

Posted on 1997-06-28
7
358 Views
Last Modified: 2013-12-26
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
Comment
Question by:zeeuw
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:md041797
ID: 1299315
Try this:

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


0
 

Author Comment

by:zeeuw
ID: 1299316
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
 
LVL 4

Expert Comment

by:md041797
ID: 1299317
Use dc.CloseEnh, not dc.Close.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:zeeuw
ID: 1299318
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
 

Author Comment

by:zeeuw
ID: 1299319
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
 

Author Comment

by:zeeuw
ID: 1299320
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
 
LVL 4

Accepted Solution

by:
md041797 earned 100 total points
ID: 1299321
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSLT 5 42
RSS Feed Validation 2 59
Examples of Web API, REST web services and SOA 7 187
Having Returning  Anonymous Function Access Global Function 7 81
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 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

12 Experts available now in Live!

Get 1:1 Help Now