Jump to content
The simFlight Network Forums

DOES ANYONE KNOW HOW TO DISPLAY DIALOGS FROM A MODULE?


Recommended Posts

Hi, i'm trying to program a fs2004 module,

this is the main file:

#include

#include "module.h"

#include "resource.h"

BOOL APIENTRY InfoDlgProc(HWND, UINT, WPARAM, LPARAM);

HINSTANCE hinst;

HWND g_hToolbar = NULL;

/*

* We define just basic interface to the flight simulator so it will be

* able to load the module.

*/

DLLEXPORT MODULE_IMPORT ImportTable = {

{0x00000000, NULL},

{0x00000000, NULL}

};

void FSAPI module_init(void) {}

void FSAPI module_deinit(void) {}

DLLEXPORT MODULE_LINKAGE Linkage = {

0x00000000,

module_init,

module_deinit,

0,

0,

0x0900, // FS2004 version (use 0x0800 for FS2002)

NULL

};

// The standard window procedure used by the flight simulator

WNDPROC oldWndProc;

// Flight simulator main window handle

HWND hFSimWindow;

#define MENU_ENTRY "&FSSerial"

#define ID_MY_MENUITEM 40002

/**

* Main window procedure that is called by the flight simulator to process

* incoming window messages.

*/

LRESULT CALLBACK FSimWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

switch (uMsg) {

case WM_NCPAINT:

{

HMENU hMenu, hMyMenu;

hMenu = GetMenu(hwnd);

if (hMenu != NULL) {

int i;

// Look for our menu entry in the main menu.

for (i = 0; i < GetMenuItemCount(hMenu); i++) {

char buf[128];

GetMenuString(hMenu, i, buf, 128, MF_BYPOSITION);

if (strcmp(buf, MENU_ENTRY) == 0) {

// It is already here, we do not need to add it again

break;

}

}

if (i < GetMenuItemCount(hMenu)) {

// It is already here, we do not need to add it again

break;

}

/* Create new menu. NOTE: It seems that this will be

* reached more times, so we cannot save the handle, because

* in such case it could be destroyed and we will not have

* any access to it in the simulator.

*/

hMyMenu = CreateMenu();

AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, ID_MY_MENUITEM, "Info");

// add the created menu to the main menu

AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hMyMenu, MENU_ENTRY);

DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_INFO) , hFSimWindow, (DLGPROC)InfoDlgProc);

}

}

break;

case WM_COMMAND:

if (LOWORD(wParam) == ID_MY_MENUITEM) {

// This is my code

DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_INFO) , hwnd, (DLGPROC)InfoDlgProc);

MessageBox(hwnd, "Ancora in costruzione!", "FSSerial - by Mirko Siciliano", MB_OK | MB_ICONEXCLAMATION);

return 0;

}

break;

}

// Call the original window procedure to handle all other messages

return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam);

}

BOOL APIENTRY InfoDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)

{

switch(uMsg)

{

case WM_COMMAND:

switch(LOWORD(wParam))

{

case IDOK:

EndDialog(hDlg,0);

return TRUE;

}

break;

default:

return FALSE;

}

return TRUE;

}

/**

* Entry point of the DLL.

*/

BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)

{

switch (fdwReason) {

case DLL_PROCESS_ATTACH:

hFSimWindow = FindWindow("FS98MAIN", NULL);

oldWndProc = (WNDPROC)SetWindowLong(hFSimWindow, GWL_WNDPROC, (LONG)FSimWindowProc);

break;

}

return TRUE;

}

I need to show a dialog included into the resources but compiling this code it only dispalys my menu into Flight Simulator and when i click on the "Info" sub menu it shows only the messagebox.

COULD ANYONE HELP ME???? PLEASE..............................

Thanks

P.S. I'm sorry for my english! i'm italian

Link to comment
Share on other sites

...

// This is my code

DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_INFO) , hwnd, (DLGPROC)InfoDlgProc);

...

BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)

...

Does "GetModuleHandle(NULL)" always get the Instance? I always save the Instance supplied to the module in the DLLmain call, and use that.

Otherwise I can only think that it doesn't like the resource for some reason. The "DialogBox" call I use works fine.

Why not use the debugger with your compiler to set breakpoints and see what is happening, or at least build checks in (eg. for the result of the DialogBox call and GetLastError codes)? To use a debugger with FS2004 you will have to use the "No CD" crack for the FS9 EXE, otherwise it stops you.

Regards,

Pete

Link to comment
Share on other sites

why when i call a dialogbox api flight simulator goes in pause?

thanks for the answer

mirko

Cause if you use the DialogBox API call, you are creating a Modal dialog box, which basically sits in its own Message Processing Loop (also called a Message Pump) until the dialog is closed, thus depriving Flight Sim of any chance to process messages itself.

You need to create a Modeless dialog box, but off the top of my head, I can't remember what the standard Win32 API calls are for that (check MSDN for Modeless Dialog Box), I haven't used the standard API calls to do dialog boxes in quite sometime (for my personal programming projects I use .NET 2.0 and, Unfortunately FlightSim uses MFC dialogs - over my strenuous objections about 10 years ago :-> - so for Work related stuff I'm still using MFC)

Tim

Link to comment
Share on other sites

  • 4 weeks later...

/**

* Entry point of the DLL.

*/

BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)

{

switch (fdwReason) {

case DLL_PROCESS_ATTACH:

hFSimWindow = FindWindow("FS98MAIN", NULL);

oldWndProc = (WNDPROC)SetWindowLong(hFSimWindow, GWL_WNDPROC, (LONG)FSimWindowProc);

break;

}

return TRUE;

}

I always save the Instance supplied to the module in the DLLmain call, and use that.

Hi, I'm trying to do the same, but I am having a little trouble finding the DLLMain instance. I thought all I would have to do is declare HINSTANCE hInstDLL = NULL and use hInstDLL in the CreateDialog call, but it appears not. hInstDLL contains the DLLmain handle right, or have I got it wrong?

My CreateDialog call is as follows:

g_hFSBRidge = CreateDialog(hInstDLL,

MAKEINTRESOURCE(IDD_FSBRIDGE), hwnd, FSBDlgProc);

I'm sure it's easy, it's just my first serious shot into the world of dialog boxes.

Thanks for you help so far anyway...

Scott.

Link to comment
Share on other sites

Hi Scott,

i use the instance for CreateDialog in this way:

HINSTANCE instance; //declaration

...

...

BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)

{

instance = hInstDLL; //copies the hInstDLL into "instance" for use it into all the APIs

...

...

}

now you can use it (instance) into CreateDialog(instance,...) !

Best Regards,

Mirko Siciliano

Link to comment
Share on other sites

  • 1 month later...

I’m trying to call a dialog window designed with VC++ MFC. Obviously I can’t use the DialogBox() Win32 API; might anyone know how can I use the CDialog class to perform the same task in my FS module?

Edit:

Perhaps this method is what's needed. Maybe it'll also help Mirko with his modeless dialog application?

Appreciate any suggestions.

Link to comment
Share on other sites

  • 4 months later...

Well, the realmodules placed in fs\modules folder cannot use MFC! So you might do the following:

write a MFC Dll that handles your dialogs, put it into your FS main folder and now you are able to interface with your module, that's all...

Link to comment
Share on other sites

create a window..... not dialog.......

using the WNDCLASSEX.....

have used this myself & does not pause flight sim....

on any event use "SetActiveWindow" to focus back flight sim.

this will allow u to have an always on top window....

works "sweeeeet"

email at the address below if you want a little more help...

this was a hard code to crack... so not just gonna post for example on here.......

Willing to guide ppl tho...

i think i posted abit about this in a post i created on here going back a few months....

titled "Module Code DLL / Window ............Source Code"

has what u need if you know what your doing...

is on "Page 3"

http://forums.simflight.com/viewforum.php?f=54&topicdays=0&start=100

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for the reply. I got it working with a little persistence soon after my initial post, building an MFC dialog in C++. It was quite easy to get it to display in FS; just needed to get the Instance handle of FS from DllMain, set this as the ResourceHandle and call DoModal.

The code you used looks like you’re using Win32 methods for the dialog?

Best Regards,

Andrew

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.