Solved

Using GDI+ to draw strings

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 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

20 Experts available now in Live!

Get 1:1 Help Now