We help IT Professionals succeed at work.
Get Started

C++ in VS2008, using GDI+ DrawString

Last Modified: 2013-12-14
Hi Experts,

I'm new to C++ and finding most things a lot harder than vb.net.

I have a clock duration in variable tDuration of type clock_t and I’ve build a plain win32 application and created a hdcWindow that I’m drawing to using GDI+.

                   clock_t tDuration = clock() - tStart;
              Font drawFont(L"Arial", 16);
              RectF layoutRect(0.0f, 0.0f, 200.0f, 50.0f);
              StringFormat format;
              SolidBrush drawBrush( Color::Black );

                  graphics.DrawString(tDuration, 11, &drawFont, layoutRect, &format, &drawBrush);

I get an error when this code runs because the graphics.DrawString wants to convert the tDuration (see error below).  

So can someone give me some code that shows me how to get the variable tDuration into a string format that DrawString can use?

Error      1      error C2664: 'Gdiplus::Status Gdiplus::Graphics::DrawString(const WCHAR *,INT,const Gdiplus::Font *,const Gdiplus::RectF &,const Gdiplus::StringFormat *,const Gdiplus::Brush *)' : cannot convert parameter 1 from 'clock_t' to 'const WCHAR *'

Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE