Solved

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

Posted on 1997-06-28
7
351 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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…

758 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

23 Experts available now in Live!

Get 1:1 Help Now