• The previously planned maintenance window for 2022-05-19 has been cancelled due to an abrupt change in availability. The maintenance will be rescheduled soon.

C++ Question more dialog box issues

Cras

Spring of Life!
Donator
Joined
Apr 13, 2011
Messages
2,215
Reaction score
0
Points
36
Location
Los Angeles
Website
www.youtube.com
I tried to just post a follow up post to this thread:
http://www.orbiter-forum.com//showthread.php?t=29075

but I got the message about necroposting and was unable to advance past it, the page just would not load, so I started a new thread.

http://www.orbiter-forum.com//showthread.php?t=29075

Like I said earlier, I had problems trying to get a dialog box to show up. I followed this thread, to the extent that I can, as my C++ skills are just about a half notch above non-existant, and I have still yet to resolve my issue. Well, there is some sort of progress as I have gone from having a frozen pane show up to now...nothing showing up.

It is an add-on to just add some local lights to the XR2, which I intended on attaching to the ship via UCD.

the main code
Code:
#define STRICT
#define ORBITER_MOUDLE

#include "Orbitersdk.h"
#include "resource.h"
#include "DlgCtrl.h"

#include "XR2lights.h"

GDIParams g_Param;
XR2lights *g_lights = 0;

DLLCLBK void InitModule (HINSTANCE hModule)
{
	g_Param.hDLL = hModule;
	oapiRegisterCustomControls (hModule);
}

DLLCLBK void ExitModule (HINSTANCE hModule)
{
	oapiUnregisterCustomControls (hModule);
}

DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
	return new XR2lights (hvessel , flightmodel);
}

DLLCLBK void ovcExit (VESSEL *vessel)
{
	if (vessel)
		delete (XR2lights*) vessel;
}

XR2lights::XR2lights (OBJHANDLE hObj , int fmodel)
	:VESSEL3 (hObj , fmodel)
{
}

XR2lights::~XR2lights ()
{
}

void XR2lights::definelights ()
{
	COLOUR4 diffuse  = {1.00 , 0.9351 , 0.9619 , 0};
	COLOUR4 specular = {2.00 , 0.9351 , 0.9619 , 0};
	COLOUR4 ambient  = {0.00 , 0.0000 , 0.0000 , 0};

	Bay1 = AddSpotLight (_V(0 , 2.10 ,  3.10), _V(0,0,-1) , 0.0001  , 1e-3 , 0 , 2e-3 , RAD*25 , RAD *90 , diffuse , specular , ambient);
	Bay2 = AddSpotLight (_V(0 , 0.90 , -1.88),_V(0,0,1)  , 0.0001, 1e-3 , 0 , 2e-3 , RAD*15 , RAD *60 , diffuse , specular , ambient);
	Dock = AddSpotLight (_V(0 , 0.30 , 10.51),_V(0,0,1)  , 20 , 1e-3 , 0 , 2e-3 , RAD*12 , RAD *23 , diffuse , specular , ambient);

	Bay1->Activate(false);
	Bay2->Activate(false);
	Dock->Activate(false);

	Bay1->SetIntensity (.5);
	Bay2->SetIntensity (.5);
	Dock->SetIntensity (.5);

	BayS  = 0;
	DockS = 0;
	IntB  = 0;
	IntD  = 0;
}

void XR2lights::dBay ()
{
	if (BayS == 1)
	{
		Bay1->Activate(false);
		Bay2->Activate(false);
		BayS = 0;
	}
	else
	{
		Bay1->Activate(true);
		Bay2->Activate(true);
		BayS = 1;
	}
}

void XR2lights::dDock ()
{
	if (DockS == 1)
	{
		Dock->Activate(false);
		DockS = 0;
	}
	else
	{
		Dock->Activate(true);
		DockS = 1;
	}
}

void XR2lights::dIntensityB ()
{
	if (IntB == 1)
	{
		Bay1->SetIntensity (.5);
		Bay2->SetIntensity (.5);
		IntB = 0;
	}
	else
	{
		Bay1->SetIntensity (1);
		Bay2->SetIntensity (1);
		IntB = 1;
	}
}

void XR2lights::dIntensityD ()
{
	if (IntD == 1)
	{
		Dock->SetIntensity (.5);
		IntD = 0;
	}
	else
	{
		Dock->SetIntensity (1);
		IntD = 1;
	}
}

void XR2lights::initialize ()
{
	if (BayS == 1)
	{
		Bay1->Activate(true);
		Bay2->Activate(true);
	}
	else
	{
		Bay1->Activate(false);
		Bay2->Activate(false);
	}

	if (DockS == 1)
		Dock->Activate(true);
	else
		Dock->Activate(false);

	if (IntB == 1)
	{
		Bay1->SetIntensity (1);
		Bay2->SetIntensity (1);
	}
	else
	{
		Bay1->SetIntensity (.5);
		Bay2->SetIntensity (.5);
	}

	if (IntD == 1)
		Dock->SetIntensity (1);
	else
		Dock->SetIntensity (.5);
}



void XR2lights::clbkSetClassCaps (FILEHANDLE cfg)
{
	SetSize(4);
	SetEmptyMass(0);
	EnableTransponder (false);
	InitNavRadios (0);
	SetBankMomentScale(0);
	SetPitchMomentScale(0);
	SetGravityGradientDamping(0);
	SetWingAspect(0);
	SetWingEffectiveness(0);
	SetVisibilityLimit(0,0.002);

	definelights();
}


void XR2lights::clbkPostStep (double simt , double simdt , double mjd)
{
}

void XR2lights::clbkSaveState (FILEHANDLE scn)
{
	char cbuffer [256];

    VESSEL3::SaveDefaultState (scn);

	oapiWriteScenario_int (scn , "BAYLIGHTS" , BayS);
	oapiWriteScenario_int (scn , "DOCKING"	 , DockS);
	oapiWriteScenario_int (scn , "BAY_INT"	 , IntB);
	oapiWriteScenario_int (scn , "DOCK_INT"  , IntD);
}

void XR2lights::clbkLoadStateEx (FILEHANDLE scn , void *vs)
{
	char *line;

	while (oapiReadScenario_nextline (scn , line)){
		if (!strnicmp(line, "BAYLIGHTS", 9))
			sscanf (line+9, "%d", &BayS);
		else if (!strnicmp(line, "DOCKING", 7))
			sscanf (line+7, "&d", &DockS);
		else if (!strnicmp(line, "BAY_INT", 7))
			sscanf (line+7, "&d", &IntB);
		else if (!strnicmp(line, "DOCK_INT", 8))
			sscanf (line+8, "&d", &IntD);
		else if (!strnicmp(line, "DIALOG", 6))
			oapiOpenDialogEx (g_Param.hDLL, IDD_DLG, DlgProc, DLG_CAPTIONCLOSE, this);
		else
		ParseScenarioLineEx (line , vs);}

	initialize ();
}

BOOL CALLBACK DlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	return g_lights ->MsgProc (hWnd, uMsg, wParam, lParam);
}

int XR2lights::MsgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg) {
	case WM_INITDIALOG:
		//initDialog (hDlg);
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD (wParam)) {
		case IDCANCEL:
			oapiCloseDialog (hWnd);
			return TRUE;
		case IDC_PLB:
			dBay ();
			return TRUE;
		case IDC_PLBHI:
		case IDC_PLBLO:
			dIntensityB();
			return TRUE;
		case IDC_DCK:
			dDock ();
			return TRUE;
		case IDC_DCKHI:
		case IDC_DCKLO:
			dIntensityD();
			return TRUE;
		}
		break;
	}
	return oapiDefDialogProc (hWnd, uMsg, wParam, lParam);
}

/*
BOOL CALLBACK Light_DlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	XR2lights *lights = (uMsg == WM_INITDIALOG ? (XR2lights*)lParam : (XR2lights*)oapiGetDialogContext (hWnd));

	switch (uMsg) {

	case WM_INITDIALOG:
		{
			//return TRUE;
			return oapiDefDialogProc (hWnd, uMsg, wParam, lParam);
		}

	case WM_COMMAND:
	//if (uMSG == WM_COMMAND){
		//XR2lights *lights = static_cast<XR2lights*>(oapiGetDialogContext(hWnd));
		switch (LOWORD (wParam)) {
		case IDC_PLB:
			lights->dBay ();
			return TRUE;
		case IDC_PLBHI:
		case IDC_PLBLO:
			lights->dIntensityB();
			return TRUE;
		case IDC_DCK:
			lights->dDock ();
			return TRUE;
		case IDC_DCKHI:
		case IDC_DCKLO:
			lights->dIntensityD();
			return TRUE;
		case IDCANCEL:
			oapiCloseDialog (hWnd);
			return TRUE;
			}
		break;
	default:
		return FALSE;
	}
	return TRUE;

	return oapiDefDialogProc (hWnd, uMsg, wParam, lParam);
}*/



int XR2lights::clbkConsumeBufferedKey (DWORD key , bool down , char *kstate)
{
	//int i;
	if (!down)
		return 0;
	else if (key == OAPI_KEY_J)
	{
		dBay ();
	}
	else if (key == OAPI_KEY_K)
	{
		dDock ();
	}
	else if (key == OAPI_KEY_G)
	{
		dIntensityB ();
	}
	else if (key == OAPI_KEY_L)
	{
		dIntensityD ();
	}
	else if (key == OAPI_KEY_SPACE)
	{
		oapiOpenDialogEx (g_Param.hDLL, IDD_CTRL, DlgProc, DLG_CAPTIONCLOSE,this);
	}
	else
		return 0;
}

the header
Code:
typedef struct {
	HINSTANCE hDLL;
	HWND hDlg;
	DWORD dwCmd;
	VESSEL *vessel;
} GDIParams;

class XR2lights:public VESSEL3
{
	friend BOOL CALLBACK DlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
public:
	XR2lights (OBJHANDLE hOBJ , int fmodel);
	~XR2lights ();

	void definelights ();

	void dBay ();
	void dDock ();
	void dIntensityB ();
	void dIntensityD ();

	//void Dialog ();
	int MsgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);

	void initialize ();


	void clbkSetClassCaps (FILEHANDLE cfg);
	void clbkLoadStateEx (FILEHANDLE scn , void *vs);
	void clbkSaveState (FILEHANDLE scn);
	void clbkPostStep (double simt , double simdt , double mjd);
	int clbkConsumeBufferedKey (DWORD key , bool down , char *kstate);

	LightEmitter *Bay1 , *Bay2 , *Dock;

	int BayS , DockS , IntB , IntD;

};

resource.h

Code:
#define IDD_DLG                         9
#define IDD_STATIC						100
#define IDD_CTRL						101
#define IDC_PLB                         1001
#define IDC_DCK                         1002
#define IDC_PLBHI                       1004
#define IDC_DCKHI                       1005
#define IDC_BUTTON5                     1006
#define IDC_DCKLO                       1006
#define IDC_PLBLO                       1007

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        101
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1008
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

xr2lights.rc
Code:
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource1.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_CTRL DIALOGEX 0, 0, 195, 84
STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "XR2 Lights"
FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
    GROUPBOX        "Payload Bay",IDC_STATIC,7,6,87,71
    PUSHBUTTON      "Toggle",IDC_PLB,25,21,50,14
    PUSHBUTTON      "HI",IDC_PLBHI,25,39,50,14
    PUSHBUTTON      "LO",IDC_PLBLO,25,57,50,14
    GROUPBOX        "Docking",IDC_STATIC,95,6,93,71
    PUSHBUTTON      "Toggle",IDC_DCK,117,21,50,14
    PUSHBUTTON      "HI",IDC_DCKHI,117,38,50,14
    PUSHBUTTON      "LO",IDC_DCKLO,117,56,50,14
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
    IDD_DLG, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 188
        TOPMARGIN, 6
        BOTTOMMARGIN, 77
    END
END
#endif    // APSTUDIO_INVOKED

#endif    // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

I will leave these hear in case one of the kind souls here can help. It compiles fine, the key strokes to command the lights to turn on and off and toggle the intensity all seem to work just fine....just cant get the dialog box to show up.

And if my code seems to be written by someone who doesnt know what he is doing, that is because it was. It was a small miracle I even got the thing to work to the extent it does after writing it. But would love to have the extra functionality of the dialog box to complete this small little pet project of mine.

Thanks in advance. :cheers:
 

orb

O-F Administrator,
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
There is a typo. Make this change:
the main code
Code:
#define STRICT
[color=#c00][s]#define ORBITER_MO[b]U[/b]DLE[/s][/color]
[color=#0a0]#define ORBITER_MOD[b]U[/b]LE[/color]
If ORBITER_MODULE isn't defined (but ORBITER_MOUDLE is instead), neither InitModule, nor ExitModule will be called by Orbiter, and g_Param.hDLL won't be filled with the hModule handle, making it NULL, and oapiRegisterCustomControls won't be called either.

but I got the message about necroposting and was unable to advance past it, the page just would not load, so I started a new thread.
You could fill in a bug report. Something strange is with that thread's necropost warning not passing the domain part of the address for displaying the following page. If I don't forget I'll investigate later.
 

Cras

Spring of Life!
Donator
Joined
Apr 13, 2011
Messages
2,215
Reaction score
0
Points
36
Location
Los Angeles
Website
www.youtube.com
TYTYTY Spelling...always comes down to spelling....

Well that helped a great deal actually as now the dialog box shows up on command and looks wonderful.

Now I get CTDs everytime I press one of the buttons......
 

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,664
Reaction score
2
Points
38
TYTYTY Spelling...always comes down to spelling....

Well that helped a great deal actually as now the dialog box shows up on command and looks wonderful.

Now I get CTDs everytime I press one of the buttons......

LoL ... been there the last month on my MFD app-dev!!! I resorted to building a test rig to diagnose parts of Glideslope 2 offline, then gingerly put them back in again with OapiDebugString code and writes to debug files. I was a system programmer a long time ago, doing kernel interrupt coding on mainframes, Unix and VAX systems. Same issues :).
 
Top