Solved

I can't draw text when using CMetaFileDC!!

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
string initialization in java 11 113
lucky13 challenge 11 143
mapAB Challlenge 35 144
Problem to App 4 81
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…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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