Jump to content
Sign in to follow this  
Guest Fabio Miguez

GDI+ text display

Recommended Posts

Guys, I have a real basic question about GDI+ and DrawString. I am trying to make a string to display the pitch value of the aircraft as a number ex: 10 = 10 degrees pitch up, or -5 = minus five degrees pitch down. I am having problem doing this. I made my own variable, pitch that is a double, and that reads the pitch value from FS. Here is the code.g->DrawString(L"pitch", -1, &Arialf, PointF(110, 15), &whiteBrush); In this snip, pitch is written, but if I take the quotes and the L(I don't know what that is, but I know that it has to be there), I can't compile. Can anybody help me out? Thank you very much in adcance.Sincerely,Tiberiu Brasov

Share this post


Link to post
Share on other sites
Guest bartels

L converts "normal" char strings to wide-character (WCHAR) versions. Graphics::DrawString needs the string in the form of WCHAR, for printing a WCHAR use swprintf. E.g. WCHAR string[5] = L"";... swprintf(string,L"%02d",pitch); m_graphics->DrawString(string,wcslen(string),...);Arne Bartels

Share this post


Link to post
Share on other sites

Arne, Thank you very much for your super prompt answer! I am having a problem compiling your code. I apologise not understanding your example, but I can't get code to compile.WCHAR string[5] = L"";swprintf(string,L"%02d",pitch);g->DrawString(string, wcslen(string), -1, &Arialf, PointF(110, 15), &whiteBrush); Thank you very much for taking your time to help me! I really appreciate it!Sincerely,Tibeiru Brasov

Share this post


Link to post
Share on other sites
Guest bartels

What are the problems (warnings, errors etc.)? "Can't get to compile" is not much info. See also the DrawString definition in the C++ documentation, it's either -1 or wcslen(string) but not both.Arne Bartels

Share this post


Link to post
Share on other sites
Guest Fabio Miguez

Hey Tiberiu,Like Arne says, either wcslen or -1. I always use -1 since that is easier to write and it automatically adjusts for the string length, but only if the string is null terminated.Your first snippet is right, you need the L"your text" format, if the text is constant. For dynamic strings, just write to a variabe what you wish with swprintf, then use DrawString(&your_string_buffer, -1, .........);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...