Solved

I can't draw text when using CMetaFileDC!!

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
Need a Shell script to start a service checking the port 6 52
How to create frequencies of a variable from SAS dataset? 10 133
Process filename extension 3 194
wordcount challenge 11 132
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.

856 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