Sign in to follow this  
n4gix

Newbie MAKE_STRING question

Recommended Posts

Hi,I'm just starting a gauge project in FS2004 for the first time. I'm needing a debug tool and am planning to use MAKE_STRING to display certain variables to the screen during the coarse of a flight. I know my code is running fine but the MAKE_STRING macro does not display anything on the screen. I use the PANEL_SERVICE_PRE_DRAW callback to call a routine that contains MAKE_STRING. Here is the relevant code I am using:#define GAUGE_CHARSET DEFAULT_CHARSET#define GAUGE_FONT_DEFAULT "Courier New"#define GAUGE_WEIGHT_DEFAULT FW_NORMAL void testredraw(){ MAKE_STRING( update_code, NULL, NULL, IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY, 0, 28, 9, 60, 29, 30, TOTAL_AIR_TEMP, DISPLAY_UNITS, MODULE_VAR_NONE, RGB(0,255,0), RGB(255,0,0), RGB(0,0,255), GAUGE_FONT_DEFAULT, GAUGE_WEIGHT_DEFAULT, GAUGE_CHARSET, 0, DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL, NULL) PELEMENT_HEADER update_code_list[] ={&update_code.header,NULL}; }When I call this testredraw() routine should it not be drawing these system variable to the screen?Thanks,Magma

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

You'll also need a MAKE_STATIC background to display the string on - all gauges have to have a MAKE_STATIC macro as the last item in the gauge macro stack. There's nothing to stop the background from being completely transparent so that the string acts like a HUD; in fact I have a hud-type debug gauge that outputs ten variables (plus other info) at any one time.If you haven't already got it, I think that reading sd2gau18.zip may be a great help.-Dai

Share this post


Link to post
Share on other sites

Yes I already have a background image and it is showing up just fine. Here is the MAKE_STATIC code:MAKE_STATIC(test_background,BMP_SMALL_test,NULL,NULL,IMAGE_USE_TRANSPARENCY,0,0,0);PELEMENT_HEADER test_Small = &test_background.header;I know my testredraw() routine is being called, but nothing is being displayed. Can you see anything I'm doing wrong? Thanks,Magma

Share this post


Link to post
Share on other sites

If that is all of your MAKE_STRING code then it looks like the callback routine that actually writes the information to the screen is missing. What you actually put into the callback routine depends on the data you are trying to display (string, integer etc). I really would download sd2gau18.zip and read the tutorial because I go into a lot of detail as to how all of the macros work. There is a lot of sample code included with it, all of which came from my own experience when I started programming gauges back in FS98 days. I know the learning curve you're going through.... I've been there :)-Dai

Share this post


Link to post
Share on other sites

And Dai, I can't imagine what the learning curve would have been like for me withut your awesome tutorials. It's great to see you back around these parts.CheersBob ScottATP IMEL Gulfstream II-III-IV-V L-300Santiago de Chile

Share this post


Link to post
Share on other sites

>And Dai, I can't imagine what the learning curve would have>been like for me withut your awesome tutorials. It's great to>see you back around these parts.>>Cheers>>Bob Scott>ATP IMEL Gulfstream II-III-IV-V L-300>Santiago de Chile>I'd like to second those thanks. The MS SDK has more holes than swiss cheese. Dai's tutorial is a Gauge designers Bible!!Thanks for putting in the effort to share it with us Dai!!RegardsJim

Share this post


Link to post
Share on other sites

As has been pointed out, you don't provide the actual callback for the MAKE_STRING macro...The more important question might be, why are you putting the macro in the PRE_DRAW case anyway?The entire gauge is nothing but a gigantic callback to begin with that executes the loop at 18/sec. Placing the macro in the case switch simply adds a level of obscurity that's totally unnecessary. ;)I prefer using a more structured layout whereby the code is logically structured... One such layout is based loosely on the format generated by Easy Gauge:Gauge Header InformationVariable DeclarationsModule DeclarationsGauge CallbackCase Switch StructureFailure DeclarationsMouse CallbacksMouse MacrosGauge Element CallbacksGauge Element MacrosThe major advantage of this type structure is that all of the Gauge Element Macros are listed in top-to-bottom order, which makes the logical flow of the linked list crystal clear with zero ambiguity... ;)

Share this post


Link to post
Share on other sites

I'm just going through a bit of a learning curve, and the fog is beginning to lift. sd2gau18.zip totally helped. I can see what you mean by "the entire gauge is nothing but a gigantic callback to begin with". You define certain parameters in the macro and also declare your callback routine. Then write your code in the callback routine...correct? I think I understand but I'm still having problems with this small chunk of code. My MAKE_STRING callback is still not being called for some reason. Here is the code:#include "..incgauges.h"#include #include "test.h"//#include #define GAUGE_NAME "Test0"#define GAUGEHDR_VAR_NAME gaugehdr_test#define GAUGE_W 100#define GAUGE_CHARSET DEFAULT_CHARSET#define GAUGE_FONT_DEFAULT "Courier New"#define GAUGE_WEIGHT_DEFAULT FW_NORMALextern PELEMENT_HEADER test_Small;STRING_UPDATE_CALLBACK update_callback;char test_gauge_name[] = GAUGE_NAME;GAUGE_HEADER_FS700(GAUGE_W, test_gauge_name, &test_Small, NULL, NULL, 0, 0, 0);MAKE_STATIC(test_background,BMP_SMALL_test,NULL,NULL,IMAGE_USE_TRANSPARENCY,0,0,0);MAKE_STRING(update_code,NULL,NULL,IMAGE_USE_ERASE | IMAGE_USE_BRIGHT , 0,50, 50,60, 29,30,CLOCK_SECOND ,MODULE_VAR_NONE ,MODULE_VAR_NONE ,RGB(0,255,0),RGB(0,0,0), RGB(92,92,92),GAUGE_FONT_DEFAULT,GAUGE_WEIGHT_DEFAULT,GAUGE_CHARSET,0,DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL,update_callback)PELEMENT_HEADER update_code_list[] ={&update_code.header,NULL};PELEMENT_HEADER test_Small = &test_background.header;FLOAT64 FSAPI update_callback(PELEMENT_STRING pelement ){ FLOAT64 val=pelement->source_var[0].var_value.n; val = !val; wsprintf(pelement->string, "%3d", (UINT32)val); return val;}void FSAPI ModuleInit(void){}void FSAPI ModuleDeinit(void){}GAUGE_TABLE_BEGIN() GAUGE_TABLE_ENTRY(&gaugehdr_BLD) GAUGE_TABLE_END()I'm trying to use the CLOCK_SECOND token variable to trigger my update_callback routine once every second. Is this the right approach or do I still have some learning curve to go?Magma

Share this post


Link to post
Share on other sites

The update_callback routine will automatically be called every 18th of a second.Your code is drawing a background referenced by BMP_SMALL_test, it is then placing a text box on it at the coordinates (50,50),the text box will be 60px wide and 29px high,it will then allow you to write up to 30 characters to this box.Because your textbox is 60px wide and you have told it that you want to write 30 characters in it it will only assign 2 pxs per characterYour update_callback will examine the value of CLOCK_SECONDS every 18th of a second.val=!val is an 'unrecognised' C routine (well I've never seen or used it) so will probably assign the value 0 to val.wsprintf(pelement->string, "%3d",(UINT32)val);This will print the value of val in the first 3 chracter spaces of the text box.If your code compiles... all it will do is print a zero, which you probably won't be able to see because its only 2pxs wideChange your code from ... 0,50,50,60,29,30 .... to... 0,50,50,60,29,3 .....Also remove the line val=!val;This should then display the value of CLOCK_SECONDS and you should see it count from 0 to 59RegardsJim

Share this post


Link to post
Share on other sites

Thanks Jim,I tried as you suggested but without success. Still nothing shows up when I run FS. I'm pretty sure that my update_callback routine is never being called by FS. I know this because I can put a routine inside of update_callback that is suppose to paint text to the screen using HDC and hBrush but nothing happens like it does when I set up a callback function through GAUGE_HEADER_FS700 macro. That works fine. So I don't know where the problem is and why my callback routine is never getting called. Am I suppose to export the function in my .h header file or .rc? Magma

Share this post


Link to post
Share on other sites

MagmaChangeGAUGE_TABLE_BEGIN() GAUGE_TABLE_ENTRY(&gaugehdr_BLD) GAUGE_TABLE_END()To:GAUGE_TABLE_BEGIN() GAUGE_TABLE_ENTRY(&gaugehdr_test) GAUGE_TABLE_END()RegardsJim

Share this post


Link to post
Share on other sites

Good eye Jim, but it has already been changed. I had changed some of the names to "test" in order to protect the proprietary project. Guess I missed one when I posted. So anyways it still doesn't work. I've looked at other sample code and it doesn't look like I'm doing anything wrong. It must be something silly I'm not doing.Magma

Share this post


Link to post
Share on other sites

The 'next_element' item in the static macro has to indicate the string. Try this:MAKE_STRING(update_code,NULL,NULL,IMAGE_USE_ERASE | IMAGE_USE_BRIGHT , 0,50, 50,60, 29,30,CLOCK_SECOND ,MODULE_VAR_NONE ,MODULE_VAR_NONE ,RGB(0,255,0),RGB0,0,0),RGB(92,92,92),GAUGE_FONT_DEFAULT,GAUGE_WEIGHT_DEFAULT,GAUGE_CHARSET,0,DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL,update_callback)PELEMENT_HEADER update_code_list[] = {&update_code.header,NULL};MAKE_STATIC( test_background, BMP_SMALL_test, &update_code_list, NULL, IMAGE_USE_TRANSPARENCY, 0, 0, 0 );PELEMENT_HEADER test_Small = &test_background.header;Doug

Share this post


Link to post
Share on other sites

Yep, Doug's found itMAKE_STATIC( test_background, BMP_SMALL_test, &update_code_list,Goes back to Bill's point about being methodical in your layout. I always put every element on a new line like this:MAKE_STATIC( test_background, BMP_SMALL_test, &update_code_list, NULL, IMAGE_USE_TRANSPARENCY, 0, 0,0 .....................(but keep coordnates together)makes it so much easier to de-bugRegardsJim

Share this post


Link to post
Share on other sites

That was it thanks Doug! Of course what shows up on the screen is "%3d" which I'm assuming I have to change the data type first in order to properly read the CLOCK_SECOND token variable.Thanks again.Magma

Share this post


Link to post
Share on other sites

FLOAT64 FSAPI update_callback(PELEMENT_STRING pelement ){ FLOAT64 val=pelement->source_var(0).var_value.n; //(use Square brackets though) wsprintf(pelement->string, "%3d",(UINT32)val); return val;}

Share this post


Link to post
Share on other sites

Thanks I just tried what you suggested and it still just showed me "%3d". However I have been playing around with the "%3d" value and have almost got it working with L"%d" value. Using that value I see only the most significant value of the CLOCK_SECOND variable. I've tried L"%2d" and L"%3d" without any luck. Is there a good online tutorial of what the proper syntax would be for this. What does the "L" mean?Magma

Share this post


Link to post
Share on other sites

>Thanks I just tried what you suggested and it still just>showed me "%3d". However I have been playing around with the>"%3d" value and have almost got it working with L"%d" value.>Using that value I see only the most significant value of the>CLOCK_SECOND variable. I've tried L"%2d" and L"%3d" without>any luck. Is there a good online tutorial of what the proper>syntax would be for this. What does the "L" mean?>>MagmaThe code should work.. I pasted it into one of my gauges and it ran fine and displayed the CLOCK_SECONDS OK. I tried your code with the L"%d" and I received a compile warning. It then displayed nothing.Copy and paste the whole of your code in its entirety here or send me a PM/e-mail with it.regardsJim

Share this post


Link to post
Share on other sites

It must have something to do with the compiler. I'm using MS Visual C++ 2005 Express Edition Ver 8.0. Here is all the .c code:#include "..incgauges.h"#include #include "BLD.h"#define GAUGE_NAME "B L D0"#define GAUGEHDR_VAR_NAME gaugehdr_BLD#define GAUGE_W 100#define GAUGE_CHARSET DEFAULT_CHARSET#define GAUGE_FONT_DEFAULT "Courier New"#define GAUGE_WEIGHT_DEFAULT FW_NORMALextern PELEMENT_HEADER BLD_Small;STRING_UPDATE_CALLBACK update_callback;char BLD_gauge_name[] = GAUGE_NAME;GAUGE_HEADER_FS700(GAUGE_W, BLD_gauge_name, &BLD_Small, NULL, NULL, 0, 0, 0);MAKE_STRING(update_code,NULL,NULL,IMAGE_USE_ERASE | IMAGE_USE_BRIGHT , 0,50, 50,40, 20,4,CLOCK_SECOND ,MODULE_VAR_NONE ,MODULE_VAR_NONE ,RGB(0,255,0),RGB(0,0,0), RGB(92,92,92),GAUGE_FONT_DEFAULT,GAUGE_WEIGHT_DEFAULT,GAUGE_CHARSET,0,DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL,update_callback)PELEMENT_HEADER update_code_list[] ={&update_code.header,NULL}; MAKE_STATIC(BLD_background,BMP_SMALL_BLD,&update_code_list,NULL,IMAGE_USE_TRANSPARENCY,0,0,0);PELEMENT_HEADER BLD_Small = &BLD_background.header;FLOAT64 FSAPI update_callback(PELEMENT_STRING pelement ){FLOAT64 val=pelement->source_var[0].var_value.n;wsprintf(pelement->string, L"%d",(UINT32)val);return val;}void FSAPI ModuleInit(void){}void FSAPI ModuleDeinit(void){}GAUGE_TABLE_BEGIN() GAUGE_TABLE_ENTRY(&gaugehdr_BLD) GAUGE_TABLE_END()It compiles fine except one warning that says:bld.c(33) : warning C4133: 'function' : incompatible types - from 'PCHAR' to 'LPWSTR'Thanks for your help. When I get passed all this syntax crap it should be smooth sailing for me.Magma

Share this post


Link to post
Share on other sites

Magma,The only error I can see is the L"%d"Apart from that it looks fine?????????????????Regards Jim

Share this post


Link to post
Share on other sites

??????? is right. I'm not sure why my compiler partially likes the "L" in front of "&d", and I don't even know what it means! I see others have used the "L" but I can't find any explanation for it online. I was about to go off on a rant about the guess work involved in programming in a Microsoft environment but I think I'll save my strength and pray that I randomly hit the right combination that this compiler wants.Magma

Share this post


Link to post
Share on other sites

Also, I'm getting a warning when compiling which points toward the wsprintf line:wsprintf(pelement->string, L"%d", (UINT32)val);Output:warning C4133: 'function' : incompatible types - from 'PCHAR' to 'LPWSTR'Could there a problem with pelement->string?Magma

Share this post


Link to post
Share on other sites

For those that interested and for the history of this string...I figured out my problem. You have to set your preprocessor definitions to ANSI. You do this in MS Visual C++ 2005 Express Edition by right clicking on your project then select Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions and type in ;ANSI at the end of the string. It's just common sense! (what a joke)Thomas

Share this post


Link to post
Share on other sites

Interesting... I don't have to do that...This is all that is in Preprocessor Definitions in my MSVC++ .NET 2003 IDE:WIN32;NDEBUG;_WINDOWS;_USRDLL

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this