March 21, 200422 yr Commercial Member 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
March 21, 200422 yr 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
March 21, 200422 yr Commercial Member 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
March 22, 200422 yr 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
March 23, 200422 yr 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, .........);
Create an account or sign in to comment