GDI+ Gauges Tutorial

mendiola_loyola

Resource contributor
#1
Dear All:

Where can i get a GDI+ gauge tutorial for FSX, i was testing the ESP example, but the gauge flickers and stops randomly.

If there is C++ code, please reply.

Thanks.
Alfredo Mendiola Loyola
Lima, Péru
 

mendiola_loyola

Resource contributor
#3
Dear Lefteris:

When i'm flying with the ESP GDI+ gauges i can see the green arrows and some numbers correctly, but at some time, for example each 30 seconds my numbers are set to 0.0 and the green arrows disappear for a fraction of second, then everything is ok until the next 30 second when the problem arrise again.

Thanks.
Alfredo Mendiola Loyola
Lima, Perú
 

Lefteris Kalamaras

Administrator
Staff member
FSDevConf team
#4
Alfredo-

This is a great candidate for some learning here, especially in the use of Visual Studio debugging!

I strongly recommend that you set up the gauge in debug mode and put breakpoints where the values are set - that way, you can see who is at fault for setting the values to 0.0 etc.
 

mendiola_loyola

Resource contributor
#5
Alfredo-

This is a great candidate for some learning here, especially in the use of Visual Studio debugging!

I strongly recommend that you set up the gauge in debug mode and put breakpoints where the values are set - that way, you can see who is at fault for setting the values to 0.0 etc.
Dear Lefteris:

I have debugged Dlls calling an EXE file using Visual Studio 2005, but with FSX how can i debug a gauge?

Is there instructions or tutorials to do that?

Thanks.
Alfredo Mendiola Loyola
Lima, Perú
 

n4gix

Resource contributor
#6
Both VS and FSX must be on the same computer...

Start a Debug session, and when prompted, browse to FSX and choose fsx.exe...

I use it frequently while developing.
 
#7
Start a Debug session, and when prompted, browse to FSX and choose fsx.exe...
Doing like this, will waste a lot of time, because if you stop the debugging, FSX will close, because it was launched as a child process by VS, so you'll need to restart it every time you make a modification and recompile.

Instead, specifically for Gauge programming (it wont work for .DLL modules, of course), there's a much better way, which will save a lot of time:

- Keep FSX always open, but change to an airplane that doesn't load your gauge (es. the default C172), when working on VS and compiling.

- Compile your gauge for Debug, then choose "Attach to Process" from the Debug menu, and select to Attach to FSX.EXE

- In FSX, select an airplane that *loads* the Gauge you just compiled. After the airplane loads, the Gauge will load as well, and the debugging session will be active. Of course, you'll need to set the target folder for the compiled Gauge to the actual Gauge folder used by that airplane in FSX.

- Do your debugging

- When you need to go back to editing, select the default C172, and leave FSX open, for the next cycle.


This way, you can always keep FSX open between editing sessions, saving a lot of time.

Dual monitors config helps a lot as well, because you can keep FSX open in full screen on one monitor, and working/debugging in VS on the other one.


regards,

Umberto Colapicchioni - VIRTUALI
http://www.fsdreamteam.com
 
Last edited:

n4gix

Resource contributor
#8
Actually, Umberto you've just described precisely what I do, but you took the time to explain it in more detail... :D

This neat "trick" has saved me a lot of time, especially since I have three monitor over which I can spread my work...

Left is VS+ 2005
Center is FSX
Right is Photoshop CS v8.8

This means I can "tweak" my gauge bitmaps and test 'em quickly and easily. :rotfl:
 

mendiola_loyola

Resource contributor
#10
I can't debug my gauge

Dear All:

I have attached my FSX process to VS2005 while FSX is running my gauge.

But in VS2005 all my breakpoins are disabled.

Am i doing something wrong?

Here is my code:

// An32.ADI.cpp
// Copyright (c) 2006 Microsoft Corporation. All rights reserved.

// Set up gauge header
char adi_gauge_name[] = GAUGE_NAME;
extern PELEMENT_HEADER adi_list;
extern MOUSERECT adi_mouse_rect[];

GAUGE_HEADER_FS700(GAUGE_W, adi_gauge_name, &adi_list, \
adi_mouse_rect, 0, 0, 0, 0);

UINT32 gyro_card = 0;

/////////////////////////////////////////////////////////////////////////////
FAILURE_RECORD adi_fail[] =
{
{FAIL_GAUGE_MAGNETIC_COMPASS, FAIL_ACTION_FREEZE},
{FAIL_NONE, FAIL_ACTION_NONE}
};


#define PITCH_LIMIT 90.0 // stop at 90 degrees
/////////////////////////////////////////////////////////////////////////////
FLOAT64 FSAPI adi_moving_card_x_cb( PELEMENT_MOVING_IMAGE pelement )
{
return 1.0;
}

FLOAT64 FSAPI adi_moving_card_y_cb( PELEMENT_MOVING_IMAGE pelement )
{
FLOAT64 val = pelement->source_var_y.var_value.n;

if( val > PITCH_LIMIT )
val = PITCH_LIMIT;
else if( val < -PITCH_LIMIT )
val = -PITCH_LIMIT;

return val;
}

FLOAT64 FSAPI adi_needle_cb( PELEMENT_NEEDLE pelement )
{
FLOAT64 val = pelement->source_var.var_value.n;

val *= -1;

return val;
}



MODULE_VAR gyro_hdg = { PLANE_HEADING_DEGREES_GYRO };

FLOAT64 FSAPI obi_deviation_cb( PELEMENT_NEEDLE pelement ) //pelement = VOR1_OBI
{
lookup_var(&gyro_hdg);
gyro_card = 359 - gyro_hdg.var_value.n;

// Offset by attitude card's bank
return (pelement->source_var.var_value.n + gyro_card); //gyro_hdg.var_value.n - pelement->source_var_0.var_value.n;
}
/////////////////////////////////////////////////////////////////////////////
//Slideres
MAKE_SLIDER //ILS
(
cs_adi_slider_horizontal,
BMP_ADI_VERT_MARK,
NULL,
0,
IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY,
0,
175,62,
//176,62,
VOR1_NEEDLE, NULL, 0.38, //Hace el papel del ILS
MODULE_VAR_NONE, NULL, 0
)

MAKE_SLIDER //ILS Glide Slope
(
cs_adi_slider_vertical,
BMP_ADI_HORI_MARK,
NULL,
0,
IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY,
0,
//36,193,
36,194,
MODULE_VAR_NONE, NULL, 0,
VOR1_GS_NEEDLE, NULL, 0.4 //Hace el papel del ILS
)

MAKE_SLIDER //Glide Slope
(
cs_adi_slider_glide_slope,
BMP_ADI_GLIDE_SLOPE,
NULL,
0,
IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY,
0,
125,193,
MODULE_VAR_NONE, NULL, 0,
VOR1_GS_NEEDLE, NULL, 0.4 //Hace el papel del ILS
)

PELEMENT_HEADER cs_adi_sliders_list[] =
{
&cs_adi_slider_vertical.header,
&cs_adi_slider_horizontal.header,
&cs_adi_slider_glide_slope.header,
NULL
};
/////////////////////////////////////////////////////////////////////////////


MAKE_NEEDLE //Obi Needle
(
adi_localizer_needle,
BMP_ADI_LOCALIZER,
cs_adi_sliders_list,
adi_fail,
IMAGE_USE_TRANSPARENCY|IMAGE_USE_ERASE|IMAGE_BILINEAR_COLOR,
0,
177, 282,
3, 123,
VOR1_OBI, obi_deviation_cb,
NULL,
4
)

PELEMENT_HEADER adi_localizer_needle_list[] =
{
(PELEMENT_HEADER)&adi_localizer_needle,
NULL
};

MAKE_NEEDLE
(
adi_needle,
BMP_ADI_NEEDLE,
adi_localizer_needle_list,
adi_fail,
IMAGE_USE_TRANSPARENCY|IMAGE_USE_ERASE|IMAGE_BILINEAR_COLOR,
0,
177, 195,
112, 13,
ATTITUDE_INDICATOR_BANK_DEGREES, adi_needle_cb,
NULL,
4
)

PELEMENT_HEADER adi_needle_list[] =
{
(PELEMENT_HEADER)&adi_needle,
NULL
};



MAKE_MOVING
(
adi_moving_card,
BMP_ADI_HORIZONTE,
adi_needle_list,
adi_fail,
IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY,
0,
//130,-500, //Posición del bitamp
125, 96,
MODULE_VAR_NONE, adi_moving_card_x_cb,
0, 0,

ATTITUDE_INDICATOR_PITCH_DEGREES, adi_moving_card_y_cb,
-90, 90
)


PELEMENT_HEADER adi_moving_card_list[2] =
{
&adi_moving_card.header, //Hace referencia a adi_moving_card
NULL
};

MAKE_STATIC
(
adi_background,
BMP_ADI_BACKGROUND,
&adi_moving_card_list,
NULL,
IMAGE_USE_TRANSPARENCY,
0,
0,0
)

PELEMENT_HEADER adi_list = &adi_background.header;


/////////////////////////////////////////////////////////////////////////////
MOUSE_BEGIN( adi_mouse_rect, HELPID_GAUGE_WHISKEY_COMPASS, 0, 0 )
MOUSE_END


/////////////////////////////////////////////////////////////////////////////
#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME
#undef GAUGE_W
VS2005 in debug mode:



Thanks.
Alfredo Mendiola Loyola
Lima, Perú
 
#11
I have attached my FSX process to VS2005 while FSX is running my gauge.

But in VS2005 all my breakpoins are disabled.
You need to be sure that the gauge being debugged, which is the one that you just compiled, is the same that is loaded by FSX. Try to set the output folder for the compiler to the gauge's folder in FSX. This is even easier in FSX, because gauges can be named .DLL, you don't even need to rename them from .DLL to .GAU, as in FS9.

regards,

Umberto Colapicchioni - VIRTUALI
http://www.fsdreamteam.com
 

mendiola_loyola

Resource contributor
#13
You need to be sure that the gauge being debugged, which is the one that you just compiled, is the same that is loaded by FSX. Try to set the output folder for the compiler to the gauge's folder in FSX. This is even easier in FSX, because gauges can be named .DLL, you don't even need to rename them from .DLL to .GAU, as in FS9.

regards,

Umberto Colapicchioni - VIRTUALI
http://www.fsdreamteam.com
Dear Umberto:

When i attach fsx to VS2005 i get the following message:

'fsx.exe': Loaded 'D:\Program Files\Microsoft Games\Microsoft Flight Simulator X\Gauges\SDK.dll', Binary was not built with debug information.

Here is my makefile:
********************

# makefile
# Copyright (c) 2000 Microsoft Corporation. All rights reserved.

INCDIR = ..\inc
DESTDIR = "D:\Program Files\Microsoft Games\Microsoft Flight Simulator X\Gauges"
INCS = -I$(INCDIR)
LIBS = user32.lib gdi32.lib kernel32.lib

!IFDEF DEBUG

C_FLAGS = /Z7
L_FLAGS = /DEBUG

!ELSE

C_FLAGS =
L_FLAGS =

!ENDIF


goal: SDK.dll


SDK.obj: $(INCDIR)\gauges.h \
SDK.cpp \
SDK.h \
SDK.Attitude.cpp \
SDK.Control_Surfaces.cpp \
SDK.Fuel.cpp \
SDK.Fuel_Selector.cpp \
SDK.Temperature.cpp \
SDK.Whiskey.cpp \
SDK.ADI.cpp
cl $(C_FLAGS) -c $(INCS) SDK.cpp

SDK.res: SDK.rc \
SDK.h \
res\SDK.Attitude.bg.BMP \
res\SDK.Attitude.card1.BMP \
res\SDK.Attitude.mask1.BMP \
res\SDK.Attitude.card2.BMP \
res\SDK.Attitude.mask2.BMP \
res\SDK.Control_Surfaces.bg.bmp \
res\SDK.Control_Surfaces.Ailerons.bmp \
res\SDK.Control_Surfaces.Elevator.bmp \
res\SDK.Control_Surfaces.Rudder.bmp \
res\SDK.Control_Surfaces.Trim.bmp \
res\SDK.Fuel.bg.bmp \
res\SDK.Fuel.needle.bmp \
res\SDK.Fuel_Selector.Off.BMP \
res\SDK.Fuel_Selector.Left.BMP \
res\SDK.Fuel_Selector.Right.BMP \
res\SDK.Fuel_Selector.Both.BMP \
res\SDK.Temperature.bg.bmp \
res\SDK.Temperature.F.bmp \
res\SDK.Temperature.C.bmp \
res\SDK.Whiskey.bg.BMP \
res\SDK.Whiskey.card.BMP \
res\SDK.Whiskey.mask.BMP \
res\An32.ADI.bg.BMP \
res\An32.ADI.Horizonte.BMP \
res\An32.ADI.mask.bmp
rc -r $(INCS) SDK.rc

SDK.dll: SDK.obj \
SDK.res
link $(L_FLAGS) /dll /out:$(DESTDIR)\SDK.dll SDK.obj SDK.res $(LIBS)

clean:
del $(DESTDIR)\*.exp
del $(DESTDIR)\SDK.dll
del $(DESTDIR)\*.lib
del *.obj
del *.res
 

mendiola_loyola

Resource contributor
#14
My problem is here:

!IFDEF DEBUG

C_FLAGS = /Z7
L_FLAGS = /DEBUG

!ELSE

C_FLAGS =
L_FLAGS =

!ENDIF

But i don't know where to define DEBUG in my VS2005 project?

Thanks.
Alfredo Mendiola Loyola
Lima Perú
 
#15
But i don't know where to define DEBUG in my VS2005 project?
You don't. It's usually already defined when you create a new project, which by default creates a "Release" config and a "Debug" config targets.

When you select the Debug target, you are creating a debuggable build, and the DEBUG constant becomes defined.

You ARE compiling a Debug target, are you ?
 

mendiola_loyola

Resource contributor
#16
Yes. I'm compiling with debug mode, but the makefile always compile the dll as realease mode.

The !IFDEF DEBUG condition never gives me true.

Here is my project config:


Thanks.
 

n4gix

Resource contributor
#18
Just for the sake of curiosity, why are you even bothering with a makefile???

Doesn't that sort of defeat the entire purpose of using Visual Studio?
 

mendiola_loyola

Resource contributor
#19
Just for the sake of curiosity, why are you even bothering with a makefile???

Doesn't that sort of defeat the entire purpose of using Visual Studio?
Dear n4gix:

I created a new win32 dll project from scratch with VS2005 and everything works fine without using a makefile.

You are right.

Thanks.
Alfredo Mendiola Loyola
Lima, Perú
 

n4gix

Resource contributor
#20
Dear n4gix:

I created a new win32 dll project from scratch with VS2005 and everything works fine without using a makefile.

You are right.
I have quite a bit of information available as "sticky posts" in my forum at http://flightsim.com "Panel and Gauges" as well as my Wiki page...

http://forums.flightsim.com/fswiki/index.php/Category:Panel_&_Gauge_Design

I noticed from looking through your makefile that you are compiling the SDK example gauges. I actually had created a VS 2005 "Solution" for that several years ago, and made it available on request.

I also have a C++/GDI+ template "Solution" available on request to me at n4gix@comcast.net...

I make no pretense that it's the only -or even the best!- approach to the subject, but it has the advantage of being well-structured and gives beginners a place to start... :D
 
Top