International - France - Spain/Latam - Germany - Benelux - Italia - Poland - Portugal - Russia - India - Japan - simMarket - About simFlight

DOES ANYONE KNOW HOW TO DISPLAY DIALOGS FROM A MODULE?

Official Support Forum for FSUIPC, WideFS, AdvDisplay, AutoSave, PFC DLL, FStarRC, GPSout, EpicInfo, Epic95, EpicLink, Esound

Moderator: Pete Dowson

DOES ANYONE KNOW HOW TO DISPLAY DIALOGS FROM A MODULE?

Postby Mirkos on Sun Jan 08, 2006 1:23 pm

Hi, i'm trying to program a fs2004 module,
this is the main file:


#include <windows.h>
#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
Mirkos
 
Posts: 12
Joined: Sun Jan 08, 2006 1:14 pm
Location: Olbia, Italia

Re: DOES ANYONE KNOW HOW TO DISPLAY DIALOGS FROM A MODULE?

Postby Pete Dowson on Sun Jan 08, 2006 2:39 pm

Mirkos wrote:...
// 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
User avatar
Pete Dowson
 
Posts: 16122
Joined: Fri Mar 07, 2003 1:11 pm
Location: Near Stoke-on-Trent, UK

Postby Mirkos on Mon Jan 09, 2006 12:53 pm

IT WORKS!!!!!!!!! THANKS.

Now i've another question: why when i call a dialogbox api flight simulator goes in pause?


thanks for the answer

mirko
Last edited by Mirkos on Mon Jan 09, 2006 4:38 pm, edited 1 time in total.
Mirkos
 
Posts: 12
Joined: Sun Jan 08, 2006 1:14 pm
Location: Olbia, Italia

Postby Mirkos on Mon Jan 09, 2006 1:05 pm

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


thanks for the answer

mirko
Mirkos
 
Posts: 12
Joined: Sun Jan 08, 2006 1:14 pm
Location: Olbia, Italia

Postby beatle on Tue Jan 10, 2006 6:17 am

Mirkos wrote: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
beatle
 
Posts: 68
Joined: Wed Nov 02, 2005 6:52 am
Location: Fredericksburg, VA

Postby Mirkos on Tue Jan 10, 2006 7:02 am

thank you for your complete explanation Tim!!!

best regards

Mirko
Mirkos
 
Posts: 12
Joined: Sun Jan 08, 2006 1:14 pm
Location: Olbia, Italia

Re: DOES ANYONE KNOW HOW TO DISPLAY DIALOGS FROM A MODULE?

Postby scottme on Wed Feb 08, 2006 6:23 am

Mirkos wrote:/**
* 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;
}


Pete wrote: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.
scottme
 
Posts: 6
Joined: Tue Jul 13, 2004 4:20 am

Re: DOES ANYONE KNOW HOW TO DISPLAY DIALOGS FROM A MODULE?

Postby Mirkos on Wed Feb 08, 2006 11:43 am

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
Mirkos
 
Posts: 12
Joined: Sun Jan 08, 2006 1:14 pm
Location: Olbia, Italia

Postby Andreww on Wed Mar 29, 2006 10:00 am

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.
Andreww
 
Posts: 8
Joined: Sat Nov 29, 2003 11:42 am

Postby Delvos on Tue Aug 01, 2006 10:03 am

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...
Delvos
 
Posts: 150
Joined: Thu Apr 24, 2003 8:01 am
Location: Düsseldorf

use wndclassex

Postby Mayhem on Wed Aug 02, 2006 8:47 am

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
------------------MayhemOfCode-------------------
bradmATecpsDOTcomDOTau
http://www.ecps.com.au

http://www.easyasweb.com will be
supplying various flight sim related
projects that include & exclude FSUIPC.
Some freeware & others payware.

Image
User avatar
Mayhem
 
Posts: 20
Joined: Sat Jun 17, 2006 11:22 am
Location: Australia, SA, Adelaide, YPAD

Postby Andreww on Sun Aug 13, 2006 8:03 pm

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
Andreww
 
Posts: 8
Joined: Sat Nov 29, 2003 11:42 am


Return to FSUIPC Support Pete Dowson Modules

Who is online

Users browsing this forum: No registered users and 3 guests