Solved

I can't draw text when using CMetaFileDC!!

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 63
Folder Comparison 12 52
Smart Camera scanning and reading information 3 86
sumHeights  challenge 17 60
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

17 Experts available now in Live!

Get 1:1 Help Now