• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX SubClassing FSX

Messages
47
Country
belgium
Hi,

I'm trying to figuere out how to subclass the FSX window, no luck so far (or I woldn't be posting here off course ;))

Here's what I came up with so far.

Code:
BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved) 
{ 	
	HWND hwnd = FindWindow("FS98MAIN",NULL);

    switch(dwReason)
    {
        case DLL_PROCESS_ATTACH:
            OldWndProc = (WNDPROC)SetClassLong(hwnd, GCL_WNDPROC, (LONG)A300WinProc);
	break;

    }
return TRUE;
}

And then the A300WinProc:

Code:
LRESULT CALLBACK A300WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	LRESULT lr = 1;
	HWND hFSMainWnd;

	switch(msg)
	{
		case WM_KEYFIRST:	
		
		break;
				
		case WM_DESTROY:
			if (OldWndProc){
				hFSMainWnd = FindWindow("FS98MAIN",NULL);
				SetWindowLong(hFSMainWnd, GWL_WNDPROC, (LONG)OldWndProc);
				OldWndProc = NULL;
			}
		break;
	}

	return CallWindowProc((WNDPROC)OldWndProc, hwnd, msg, wParam, lParam);
	
}

OldWndProc gets a valid number but unfortunately the A300WinProc is never called. Anyone see anything that's wrong ?

Thx,
Björn
 
This

Code:
OldWndProc = (WNDPROC)SetClassLong(hwnd, GCL_WNDPROC,(LONG)A300WinProc);

Should be probably be:

Code:
OldWndProc = (WNDPROC)SetWindowLongPtr(hwnd, GCL_WNDPROC,(LONG)A300WinProc);
 
Last edited:
Hi Umberto,

Thx for the tip, tried it but it doesn't work either :(

But this did:

OldWndProc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC,(LONG)A300WinProc);

Thanks again !

Björn
 
Last edited:
Well, both GWLP_WNDPROC and GWL_WNDPROC are defined as -4 so, there shouldn't be any difference.

Are you compiling in Win64 ? Because, in this case they might be different.
 
Hi Umberto,

I compile in 32bit setting, but in my first implementation I used GCL_WNDPROC.

Anyway, I can set-up the subclass but FSX crashes shortly after that with a memory error, maybe because I create a Settimer() during module_init or when I initialize DirectSound or DirectInput or something not sure yet.

Björn
 
I compile in 32bit setting, but in my first implementation I used GCL_WNDPROC.

Ok, then it's different, since GCL_WNDPROC = -24 so, it's a different thing. GWLP_WNDPROC and GWL_WNDPROC, instead, are the same ( -4 ), but only under Win32.

Anyway, I can set-up the subclass but FSX crashes shortly after that with a memory error, maybe because I create a Settimer() during module_init or when I initialize DirectSound or DirectInput or something not sure yet.

I never had any problem calling SetTimer on FS9.

Never tried it in FSX, because it might not be necessary to meddle with timers, since in FSX it's probably best to subscribe to system events, like 6hz or Frame, etc.

BTW, why you need to subclass the Flight sim main window under FSX ? In FS9, this was the only way to add items to its menu, but under FSX is not necessary, since you have Simconnect calls to add menus and submenus.
 
Last edited:
Hi Umberto,

SetTimer works fine in FSX, but after SubClassing "something" is causing an error in the gauge, so I'm was just thinking out loud what it might be ;)

I prefer to use a timer based system over the FSX timer as this give me more security that my functions will be called "on time" for instance for my PID controlers. But I've never used the FSX SimConnect timers so maybe they work as well.

In general however I noticed that SimConnect is not flawless and can cause issues (for instance with keyboard intercepts or intercepting some of the FSX events) so I'm not 100% convinced it is bug free and stable enough to have all my calculations depend on a SimConnect timer-event.

Björn
 
Back
Top