October 22, 200520 yr Okay here's a new question. I'm typically used to being able to get a Token Variable's value and display it in a string using this:lookup_var(&TokenVar);FLOAT64 val_TokenVar = TokenVar.var_value.n;or something similar. The DrawString method is like this:graphics.DrawString(L"LBS X 1000", -1, &font, pointFtot, &solidBrushText);Okay but I want to put a FLOAT value as the string (this is for a fuel gauge). I've tried:graphics.DrawString(L"%f", val_TokenVar, -1, &font, pointFtot, &solidBrushText);and it obviously didn't work (I can't just throw a new argument into the call, I understand that. My question is this:How DO I make those "%f" values show up?Thanks
October 22, 200520 yr Use wsprintf. ex.//------------------------lookup_var(&TokenVar);FLOAT64 val_TokenVar = TokenVar.var_value.n;wchar_t ws_str = malloc(128 * sizeof(wchar_t)); (*ws_str) = 0;wsprintf(ws_str,L"%f",val_TokenVar);graphics.DrawString(ws_str, -1, &font, pointFtot, &solidBrushText);free(ws_str);//----------------------Hope it helps.Kioussis Konstantinos
October 22, 200520 yr Okay, I gave it a shot, and I got a few errors that I'm not sure how to fix:...fuelstat.cpp(217) : error C2440: 'initializing' : cannot convert from 'void *' to 'wchar_t' There is no context in which this conversion is possible...fuelstat.cpp(218) : error C2100: illegal indirection...fuelstat.cpp(219) : error C2664: 'wsprintfW' : cannot convert parameter 1 from 'wchar_t' to 'LPWSTR' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast...fuelstat.cpp(220) : error C2664: 'Gdiplus::Status Gdiplus::Graphics::DrawString(const WCHAR *,INT,const Gdiplus::Font *,const Gdiplus::PointF &,const Gdiplus::Brush *)' : cannot convert parameter 1 from 'wchar_t' to 'const WCHAR *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast...fuelstat.cpp(221) : error C2664: 'free' : cannot convert parameter 1 from 'wchar_t' to 'void *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style castHere's what I typed. The gauge itself is a fuel status gauge that measures the amount (in lbs) of fuel in the tanks. wchar_t ws_str_l = malloc(128 * sizeof(wchar_t));(*ws_str_l) = 0;wsprintf(ws_str_l, L"%f", val_lqty);graphics.DrawString(ws_str_l, -1, &font, pointFlfl, &solidBrushText);free(ws_str_l);I'm newish to gauges in general and very new to GDI+ so any help is greatly appreciated.
October 22, 200520 yr Change thiswchar_t ws_str_l = malloc(128 * sizeof(wchar_t));towchar_t* ws_str_l = malloc(128 * sizeof(wchar_t));
October 22, 200520 yr Okay, that knocked back most of the errors. The one remaining has an obvious solution, but my attempts to solve it produced more errors. (Gotta love this stuff!)...fuelstat.cpp(217) : error C2440: 'initializing' : cannot convert from 'void *' to 'wchar_t *' Conversion from 'void*' to pointer to non-'void' requires an explicit castI've tried :wchar_t* ws_str_l = malloc(128 * sizeof((float)(wchar_t));and even:(float)wchar_t* ws_str_l = malloc(128 * sizeof((float)(wchar_t));(no laughing too hard!)By the way, what exactly is the difference between:wchar_t ws_str_l = malloc(128 * sizeof(wchar_t)); andwchar_t* ws_str_l = malloc(128 * sizeof(wchar_t));?Thanks
October 22, 200520 yr Author Moderator That particular method is using the (Sizeof) to dynamically set the character array's size based on the input variable.Being more conservative, since I already know what size to expect, I simply declare it explicitly as n + 1. Note also that I use swprintf*...SolidBrush blackBrush(Color(255, (8*brt)/100, (8*brt)/100, (8*brt)/100));FontFamily Arial(L"Arial");Font LargeNumbers(&Arial, 62*dy, FontStyleRegular, UnitPixel);Font SmallNumbers(&Arial, 33*dy, FontStyleRegular, UnitPixel);lookup_var(&RECIP_ENGINE1_OIL_PRESS_PSFvar);eng1_op = PSF_TO_PSI(RECIP_ENGINE1_OIL_PRESS_PSFvar.var_value.n);WCHAR eng1_op_wch[3] = L"";swprintf(eng1_op_wch, L"%2.0f", eng1_op);PointF pointOP(375*dx, 308*dy);graphics.DrawString(eng1_op_wch, -1, &SmallNumbers, pointOP, &blackBrush);*NOTE: sprintf returns the number of bytes stored in buffer, not counting the terminating null character. swprintf returns the number of wide characters stored in buffer, not counting the terminating null wide character.swprintf is a wide-character version of sprintf; the pointer arguments to swprintf are wide-character strings. Detection of encoding errors in swprintf may differ from that in sprintf. swprintf and fwprintf behave identically except that swprintf writes output to a string rather than to a destination of type FILE. Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
October 22, 200520 yr Well, Bill, Once again, I owe you a thanks. That seems to have nailed it!I appreciate all the help guys.
October 23, 200520 yr Author Moderator >Well, Bill, Once again, I owe you a thanks. That seems to>have nailed it!>>I appreciate all the help guys.No problem... I don't mind folks asking questions, because more often than not, I wind up learning something new myself! ;)The main thing to keep in mind is that you can only "print" string data in GDI or GDI+, so all numbers must be converted to character strings.Also, int variables won't work at all, but must be converted to FLOAT64 first... Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
Create an account or sign in to comment