Solved

I can't draw text when using CMetaFileDC!!

Posted on 1998-11-19
3
861 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
[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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 59
matchUp  challenge 6 82
scoreUp challenge 14 74
Annoying "thing" blocks my view 4 146
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Suggested Courses

752 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