Solved

I can't draw text when using CMetaFileDC!!

Posted on 1998-11-19
3
848 Views
Last Modified: 2013-11-20
This is a part of my program but it doesn't work. When I try to draw text by using 'TextOut', it gives a weird result. ( Very Big "Be" instead of "Bye") Do you know why it happens?

void CTestEmfView::OnLButtonDown(UINT nFlags, CPoint point)
{
      CMetaFileDC *pobjDC = new CMetaFileDC();
      CFileDialog dialog (FALSE, "emf", NULL,
      OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
      "Enhanced meta File(*.emf) | *.emf;||",  NULL);
      if ( dialog.DoModal() == IDOK )
      {
            pobjDC->CreateEnhanced(GetDC(), dialog.GetFileName(), NULL, NULL);
            OnPrepareDC(pobjDC);
            pobjDC->TextOut(0, 0, "Bye");
            HENHMETAFILE hpDC = pobjDC->CloseEnhanced();
            DeleteEnhMetaFile(hpDC);
      }
      CView::OnLButtonDown(nFlags, point);
}
0
Comment
Question by:minha
3 Comments
 
LVL 12

Expert Comment

by:migel
ID: 1325014
Hi!
Can you create font and select them into the Metafile DC?
0
 

Author Comment

by:minha
ID: 1325015
Of course, I tried it..(Created Font and selected it. )  but, it doesn't work. So, that's the problem.
I tried this code with visual c++ 6.0 also, and it worked. The difference between my visual c++ 5.0 and 6.0 is I installed visual c++ 5.0 by CD-Rom install Type.. I don't know why it happens.
0
 
LVL 1

Accepted Solution

by:
sudhirbrat earned 50 total points
ID: 1325016
If u give lpBounds as NULL, the graphics device interface (GDI) computes the dimensions of the smallest rectangle that can enclose the picture drawn by the application.

So set ur client dc as your attribute dc to the metafile dc.


void CTestEmfView::OnLButtonDown(UINT nFlags, CPoint point)
{
      CClientDC dc(this);
    CMetaFileDC *pobjDC = new CMetaFileDC();
    CFileDialog dialog (FALSE, "emf", NULL,
            OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
            "Enhanced meta File(*.emf) | *.emf;||",  NULL);
    if ( dialog.DoModal() == IDOK )
    {
            pobjDC->CreateEnhanced(&dc, dialog.GetFileName(), NULL, NULL);

            pobjDC->SetAttribDC(dc.GetSafeHdc());

            OnPrepareDC(pobjDC);
            pobjDC->TextOut(0, 0, "Bye");
            HENHMETAFILE hpDC = pobjDC->CloseEnhanced();

            pobjDC->ReleaseAttribDC();

            DeleteEnhMetaFile(hpDC);
    }
    CView::OnLButtonDown(nFlags, point);
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 48
iSeries DB2 Query 2 90
method notes when mouse over in eclipse 5 82
changeXy challenge 13 67
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…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

18 Experts available now in Live!

Get 1:1 Help Now