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

P3D v4 [C#] WPF, DefWndProc in a WPF application

Messages
40
Country
netherlands
Hi, while trying to add a new feature to my KsimSaver, i am struggling to find a way to use DefWndProc in WPF.
this code is from the SDK sample, as that is Windows Forms, this code is not usable for WPF, atleast the Protected override void DefWndProc(ref Message m) {} part. the rest of the simconnect code should work perfectly fine.

C#:
protected override void DefWndProc(ref Message m)
        {
            if (m.Msg == WM_USER_SIMCONNECT)
            {
                if (simconnect != null)
                {
                    simconnect.ReceiveMessage();
                }
            }
            else
            {
                base.DefWndProc(ref m);
            }
        }

If anyone has any tips or ideas on how to implement this in WPF please let me know.
 
Messages
40
Country
netherlands
To fix this issue i did the following:
setup a correct handle and add a hook when connecting to SimConnect :

C#:
private HwndSource gHs;

C#:
 WindowInteropHelper lWih = new WindowInteropHelper(Application.Current.MainWindow);
                    IntPtr lHwnd = lWih.Handle;

                    gHs = HwndSource.FromHwnd(lHwnd);

                    gHs.AddHook(new HwndSourceHook(WndProc));

                    // the constructor is similar to SimConnect_Open in the native API
                    simconnect = new SimConnect("KsimSaver", lHwnd, WM_USER_SIMCONNECT, null, 0);

then did the following in WndProc:

C#:
 private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
         
            handled = false;

            // if message is coming from simconnect and the connection is not null;
            // continue and receive message
            if (msg == WM_USER_SIMCONNECT && simconnect != null)
            {
                simconnect.ReceiveMessage();

               
                handled = true;
            }
           
            return (IntPtr)0;
        }
 
Top