Solved

CRichEditCtrl question

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

11 Experts available now in Live!

Get 1:1 Help Now