Advanced Question Help adding dialog box to a vessel

fausto

FOI SuperMod
Joined
Jul 13, 2008
Messages
797
Reaction score
2
Points
0
Location
Monza (Milan)
Hello!
My goal is to create a dialog box similar to Atantis one (you can open it hitting CTRL SPACE) but i'm facing serious troubles in this mission..
I give a look to Atlantis sample and i found what seemed to be right to create a dialog box. I found it in Atlantis.ccp, Atlantis.rc and resource.h.
This is the resulting code:

padqacont.ccp:

Code:
#include "DlgCtrl.h"
#include "resource.h"

ypedef struct {
HINSTANCE hDLL;	
HINSTANCE hModule;	
//SURFHANDLE tkbk_label;
	//HFONT font[1];

}GDIParams;


GDIParams g_Param;

BOOL CALLBACK DlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	

	switch (uMsg) {
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			oapiCloseDialog (hWnd);
			return TRUE;}
		
		break;
	}
	return oapiDefDialogProc (hWnd, uMsg, wParam, lParam);
}

int padqacont::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)

{
	if (!down) return 0; // only process keydown events

	if (KEYMOD_CONTROL (kstate)) {

		switch (key) {
		case OAPI_KEY_SPACE: // deploy/retract antenna
			oapiOpenDialogEx(g_Param.hDLL, IDD_CTRL, DlgProc,DLG_CAPTIONCLOSE, this);
			//failure_code=0;
			return 1;
		}
	
	
}
return 0;
}


resource.h:
Code:
#define IDC_STATIC 100
#define IDD_CTRL                        101


padqacont.rc:

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

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//

#include "winresrc.h"

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

/////////////////////////////////////////////////////////////////////////////
// English (U.K.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#pragma code_page(1252)
#endif //_WIN32



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

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

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

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

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_CTRL DIALOGEX 0, 0, 115, 30
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Control"
FONT 8, "MS Sans Serif"
BEGIN
    GROUPBOX        "Control",IDC_STATIC,4,51,50,28
END

#endif    // English (U.K.) resources
/////////////////////////////////////////////////////////////////////////////



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


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

Now, when I hit CTRL SPACE nothing happens.. I'm fighting for two days but that dialog box refuses to open.. Can someone help me finding the way to do that?
I can tell you I'm using a VISUAL C++ 2010 EXPRESS EDITION compiler.. maybe it can't compile .rc files? It seems strange to me.. the Antares capusle i coded some months ago had an .rc file included for bitmap files list and it worked perfectly..

I need to solve this mistery.. :compbash:
 

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 have run into this exact same problem when trying to get a dialog box to show up that controls lights and various things, and I couldnt for the life of me figure it out, nor the others that I showed the code to.

I will be following this thread closely indeed, and if you do not object, I can post my code snippets here and maybe there is a common mistake we are both making or whatnot, and someone here could figure out the problem.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Is 'g_Param.hDLL' filled with handle to the module upon initialization?

Is oapiRegisterCustomControls called for the module?

(Also, there's missing 't' in 'typedef' in the code snippet.)
 

fausto

FOI SuperMod
Joined
Jul 13, 2008
Messages
797
Reaction score
2
Points
0
Location
Monza (Milan)
I wrote this:

Code:
DLLCLBK void InitModule (HINSTANCE hDLL)
{
	//g_Param.hDLL = hModule;
	oapiRegisterCustomControls (hDLL);
	g_Param.tkbk_label = oapiCreateSurface (LOADBMP (IDB_TKBKLABEL));

	// allocate GDI resources
	g_Param.font[0] = CreateFont (-11, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");
}

DLLCLBK void ExitModule (HINSTANCE hDLL)
{
	oapiUnregisterCustomControls (hDLL);
	oapiDestroySurface (g_Param.tkbk_label);

	// deallocate GDI resources
	DeleteObject (g_Param.font[0]);
}

I compile and get this error:

Code:
error LNK2001: unresolved external symbol "void __cdecl oapiRegisterCustomControls(struct HINSTANCE__ *)" (?oapiRegisterCustomControls@@YAXPAUHINSTANCE__@@@Z) 
1>Padjacont_seq.obj : error LNK2001: unresolved external symbol  "void __cdecl oapiUnregisterCustomControls(struct HINSTANCE__ *)" (?oapiUnregisterCustomControls@@YAXPAUHINSTANCE__@@@Z)


I added Orbitersdk.lib and Orbiter.lib to the project... I tried to add DlgCtrl.lib and i can compile it, but DLL doesn't work at all....
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Code:
DLLCLBK void InitModule (HINSTANCE hDLL)
{
	[color=#c00][s]//[/s][/color]g_Param.hDLL = h[color=#0a0]DLL[/color][color=#c00][s]Module[/s][/color];
	oapiRegisterCustomControls (hDLL);
	[color=#c82]g_Param.tkbk_label = oapiCreateSurface (LOADBMP (IDB_TKBKLABEL));

	// allocate GDI resources
	g_Param.font[0] = CreateFont (-11, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");[/color]
}

DLLCLBK void ExitModule (HINSTANCE hDLL)
{
	oapiUnregisterCustomControls (hDLL);
	[color=#c82]oapiDestroySurface (g_Param.tkbk_label);

	// deallocate GDI resources
	DeleteObject (g_Param.font[0]);[/color]
}
To the g_Param.hDLL should be assigned value of hDLL/hModule. Uncomment that line.

Are you using the font and the label surface (marked with this color), or were they just copied from Atlantis.cpp?


I added Orbitersdk.lib and Orbiter.lib to the project... I tried to add DlgCtrl.lib and i can compile it, but DLL doesn't work at all....
DlgCtrl.lib should be included.

What does it mean that the DLL doesn't work at all?

I can't reproduce in a similar test module using your code/resources not working at all, and instead it displays a dialog window after CTRL+SPACE has been pressed.
 

fausto

FOI SuperMod
Joined
Jul 13, 2008
Messages
797
Reaction score
2
Points
0
Location
Monza (Milan)
It's working!! :cheers:
Thank you very much Orb!!
Just another question.. I need to display on this dialog box some int values.. they are part of a countdown.. how can i do that??

However, I post the right code, so people who need to create a dialog box can give a look:

Main.ccp:
Code:
typedef struct {
	HINSTANCE hDLL;
} GDIParams;
GDIParams g_Param;
//#define LOADBMP(id) (LoadBitmap (g_Param.hDLL, MAKEINTRESOURCE (id)))

BOOL CALLBACK DlgProc (HWND, UINT, WPARAM, LPARAM);

int Main::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)

{
	if (!down) return 0; // only process keydown events

	if (KEYMOD_CONTROL (kstate)) {

		switch (key) {
		case OAPI_KEY_SPACE: 
			oapiOpenDialogEx(g_Param.hDLL, IDD_CTRL, DlgProc,DLG_CAPTIONCLOSE, this);
			return 1;
		}
	
	
}
return 0;
}
DLLCLBK void InitModule (HINSTANCE hModule)
{
	g_Param.hDLL = hModule;
	oapiRegisterCustomControls (hModule);
	
}

DLLCLBK void ExitModule (HINSTANCE hModule)
{
	oapiUnregisterCustomControls (hModule);
	
	
}
BOOL CALLBACK DlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	
	

	switch (uMsg) {
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			oapiCloseDialog (hWnd);
			return TRUE;}
		
		break;
	}
	return oapiDefDialogProc (hWnd, uMsg, wParam, lParam);
}

resource.h
Code:
#define IDC_STATIC                100
#define IDD_CTRL                        101

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

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

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

/////////////////////////////////////////////////////////////////////////////
// English (U.K.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//


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

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

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

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

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_CTRL DIALOGEX 0, 0, 115, 30
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Dialog Box"
FONT 8, "MS Sans Serif"
BEGIN
    GROUPBOX        "Dialog Box",IDC_STATIC,4,51,50,28
END

#endif    // English (U.K.) resources
/////////////////////////////////////////////////////////////////////////////



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


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

you have to add to your project also DlgCtrl.lib, which is located in orbitersdk/lib folder
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Just another question.. I need to display on this dialog box some int values.. they are part of a countdown.. how can i do that??
You can set displayed text or integer value of the countdown by using SetDlgItemInt, SetDlgItemText, or SetWindowText functions, or by sending WM_SETTEXT message (SendMessage / SendDlgItemMessage) either to a read-only (ES_READONLY style) or disabled (WS_DISABLED style) `EDITTEXT` (EDIT) dialog item, or to a `[L|C|R]TEXT` (STATIC) dialog item which has assigned a positive ID (or otherwise you'll need to get the handle of it to be only able to do that), or even you can change the dialog window's caption to the current countdown time with SetWindowText / WM_SETTEXT.

Programming dialog boxes in Orbiter is part of pure WinAPI (mostly User32 functions). You can search MSDN library if you want functions or window messages reference.
 
Top