Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CRichEditCtrl question

Posted on 1998-11-12
4
Medium Priority
?
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 600 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

688 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