Solved

Using GDI+ to draw strings

Posted on 2006-06-12
5
856 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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.

732 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