• 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.

FSXA FSX Window Handle

JB3DG

Resource contributor
Messages
1,325
Country
southafrica
During one of my previous stints of attempting to find DirectX texture surfaces, I would call this line (as provided to me by Christopher Coon) to get the handle to the FSX window in order to hack into the IDirect3DDevice9 instance:

g_hWnd = FindWindowA(NULL, "FS98MAIN");

I was told that yes it is called FS98 even though its FSX. And it worked. I had success for a while until i ran into some other DX issues and took a break. I didnt touch this code for several weeks....

Now all of a sudden when i try to get the window handle it returns NULL.

Anyone got any ideas how i can get this fixed?

Thanks
JB
 
Do you get anything useful if you call GetLastError() after FindWindow() returns NULL?

Doug
 
ERROR_RESOURCE_TYPE_NOT_FOUND
1813 (0x715)
The specified resource type cannot be found in the image file.
 
Spy++ confirms that is the correct class name for FSX.
You could try
FindWindowA("Microsoft Flight Simulator X",0);

I might be tempted to retype the line of code, to eliminate the possibility of corruption.

Doug
 
Wierd. I tried swapping the parameters as well, (putting "FS98MAIN" as the first param and 0 as the second) and interestingly I got something back but i still got a 1813 error.

It successfully hooked in to the D3D device though...
 
Last edited:
I found this* while searching for information. I don't know if it'll be helpful or not:

You can't simply cast an "ANSI" string to a Unicode string. You must compile it as a Unicode string.

As for _T() and _TEXT()
http://blogs.msdn.com/oldnewthing/archive/2004/02/12/71851.aspx
To add to the article's comments, if you #define UNICODE you should also #define _UNICODE. (Both with and without the leading underscore.)

So, if you say
hwnd = FindWindow(NULL,TEXT("Quake 2"));
you should be in business.

Substitute "FS98MAIN" for "Quake 2" of course... ;)

* Reference the original question: http://www.cplusplus.com/forum/beginner/3811/
 
I was originally using the FindWindowA version for ANSI. I switched to using the unicode (still had to move the FS98MAIN from the window title to the class title) and used this format:

FindWindow(L"FS98MAIN", NULL). Worked like a charm.
 
The following snippet returns a handle if FSX is running, otherwise NULL.

Code:
HWND Handle = NULL;

Handle = FindWindow(NULL, "Microsoft Flight Simulator X");

I assume it's a handle to FSX!
 
Last edited:
Looking at the definition of FindWindow helped:

Code:
HWND WINAPI FindWindow(
  _In_opt_  LPCTSTR lpClassName,
  _In_opt_  LPCTSTR lpWindowName
);

If you use the second param, it will be Microsoft Flight Simulator X. If you use the first, it will be FS98MAIN.
 
Looking at the definition of FindWindow helped:

Code:
HWND WINAPI FindWindow(
  _In_opt_  LPCTSTR lpClassName,
  _In_opt_  LPCTSTR lpWindowName
);

If you use the second param, it will be Microsoft Flight Simulator X. If you use the first, it will be FS98MAIN.

You know what, I started to post this prototype definition yesterday, but didn't because I "assumed" that you already knew that... :o
 
What does intruige me is that it worked for so long previously when swapped around....
 
FindWindowA() isn't listed in the Windows API.

Googling suggests it's particular to VB and that there's difficulties with it.
 
FindWindowA() isn't listed in the Windows API.

Googling suggests it's particular to VB and that there's difficulties with it.

It's FindWindow() and it's either FindWindowA() or FindWindowW() in the Windows headers. One should not typically use FindWindowA or FindWindowW directly but rather compile with the correct character settings. The 'A' is for single byte (ANSI) strings and the 'W' is for multi-byte (wide) strings.
 
Back
Top