Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CRichEditCtrl question

Posted on 1998-11-12
4
Medium Priority
?
493 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

879 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