Solved

CRichEditCtrl question

Posted on 1998-11-12
4
464 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fizzArray  challenge 1 83
fix34  challenge 9 121
scoreUp challenge 14 63
Path of Workbook 3 78
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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