Solved

Using GDI+ to draw strings

Posted on 2006-06-12
5
838 Views
Last Modified: 2008-02-01
Hi all,

  I need to use the DrawString method in GDI+ but when I am unable to create a Font object.  I've created an activeX control that creates a Font object just fine but when I try to use it in a dialog application it will not let me.  The method of implimentation I've been using is:

Font font(fontFamily, etc, etc);

  I'm sure there is some initialization I need to perform but I have no idea.  If someone could somewhat detailed information on how to create the font and any other useful tips for using DrawString I would appreciate it.
0
Comment
Question by:alexatsearidge
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16890924
How are you initializeing the Font? E.g.

FontFamily fontFamily(L"Arial");
Font font(&fontFamily, 16, FontStyleRegular, UnitPixel);

should work fine. See e.g. http://msdn.microsoft.com/library/en-us/gdicpp/GDIPlus/usingGDIPlus/usingtextandfonts.asp ("Using Text and Fonts"), you'll also find sample code there. Regarding the title of your Q, see http://msdn.microsoft.com/library/en-us/gdicpp/GDIPlus/usingGDIPlus/usingtextandfonts/drawingtext.asp ("Drawing Text "):

FontFamily  fontFamily(L"Times New Roman");
Font        font(&fontFamily, 24, FontStyleRegular, UnitPixel);
PointF      pointF(30.0f, 10.0f);
SolidBrush  solidBrush(Color(255, 0, 0, 255));

graphics.DrawString(L"Hello", -1, &font, pointF, &solidBrush);
0
 

Author Comment

by:alexatsearidge
ID: 16895021
That is the exact format I am using but one compile error I get is "Font is an ambiguous symbol".  I'm not at my developement machine at the moment but once I get a chance I'll check the exact errors.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 16895095
>>"Font is an ambiguous symbol"

GDI+ has its own namespace 'Gdiplus', so you should either use it like

using namespace Gdiplus;

or explicitly refer to it like

Gdiplus::FontFamily fontFamily(L"Arial");
Gdiplus::Font font(&fontFamily, 16, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);

or

Gdiplus::FontFamily  fontFamily(L"Times New Roman");
Gdiplus::Font        font(&fontFamily, 24, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
Gdiplus::PointF      pointF(30.0f, 10.0f);
Gdiplus::SolidBrush  solidBrush(Gdiplus::Color(255, 0, 0, 255));

respectively.
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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

895 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

12 Experts available now in Live!

Get 1:1 Help Now