Solved

CRichEditCtrl question

Posted on 1998-11-12
4
472 Views
Last Modified: 2013-11-20
I need to make a CRichEditCtrl to print into a metafile dc.
I've already tried this way:

// 'dc' is the client DC
CMetaFileDC cMetaDC;
cMetaDC.CreateEnhanced(&dc, NULL, NULL, NULL);
cRTFControl.SendMessage(WM_PRINT,(WPARAM)&cMetaDC,
                        PRF_CLIENT);
hMetaFile=cMetaDC.CloseEnhanced(&dc);

But the rich text control didn't print anything ...
A few tips what i've already tried:
- Print it to a bitmap (Memory DC, selecting bitmap in it).
  This works.
- Instead of passing 'NULL' as 'lpBounds' for
  'CreateEnhanced', i've tried to pass the valid bounds
  (in HIMETRIC units). Didn't work.

I assume that maybe this is caused by the fact that a
metafile DC doesn't have an attribute DC (m_hAttribDC).
Is this the problem, and if yes, is there a possibility to
work around this? If no, what can i do? This is really
urgent :)
0
Comment
Question by:snoegler
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 150 total points
ID: 1324578
I've tested the following snippet of code
which does actually splat the text on the
screen. Obviously you'll have to muck about
getting the scaling correct etc. etc
But it may be a start point for you to
get the stuff you really want to working.

void CTestDlg::OnButton()
{
  CClientDC dc(this);
  CMetaFileDC dcMeta;
  dcMeta.Create("tmp.tmp");
  m_edit.SelPrint((long)dcMeta.m_hDC);
  HMETAFILE h = dcMeta.Close();
  dc.PlayMetaFile(h);
  }

Cheers Greg

0
 
LVL 6

Author Comment

by:snoegler
ID: 1324579
Thank you for your answer. The problem is, i am using VC 4.0
 - so SelPrint() isn't available. But i assumed that it would
also send a WM_PRINT message to the control, so i checked my
code again ... and i found the mistake: I posted the
'CMetaFileDC*' instead of 'HDC' as the parameter.

I will award you the points, but do you think you can help me
with another little problem?
When letting the CRichEditCtrl print to the meta file, it erases
its background - and i need to merge some layers into one meta
file. I could hack around this (print all meta files into memory
dcs and merge them then), but it would be nice if you had a good
hint on that.
( Setting the background brush to NULL or SetBkMode(TRANSPARENT)
doesn't help ...)
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 1324580
Could be a problem of different versions but
when I amended my snippet as follows

void CTestDlg::OnButton()
{
  CClientDC dc(this);
  CMetaFileDC dcMeta;
  dcMeta.Create("tmp.tmp");
  dcMeta.SetBkMode(TRANSPARENT);
  m_edit1.SelPrint((long)dcMeta.m_hDC);
  m_edit2.SelPrint((long)dcMeta.m_hDC);
  HMETAFILE h = dcMeta.Close();
  dc.PlayMetaFile(h);
  }

there was no "erasing its background"
the two rich edit strings splatted
right over eachother.

If the richedit controls you are using really do
emit their own META_SETBKMODE records to the metafile
obviating your preparitary work then I'm afraid
writing your own ::EnumMetaFile and EnumMFProc stuff
which ignores those records would be the best approach.

But as I say, check your code again,
you may just be having a bad day.

Cheers Greg
0
 
LVL 6

Author Comment

by:snoegler
ID: 1324581
No, this time i hadn't a bad day :)
I tried EnumEnhMetaFile(), and there was a record which erased
the background. Don't know why, but my solution is a special
playback routine which omits this step.
Thanks for your time :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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