Solved

Using GDI+ to draw strings

Posted on 2006-06-12
5
848 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

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