Solved

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

Posted on 1997-06-28
7
364 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

791 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