C++/CLI : Interop window is not properly configured
- by raytaller
Hi, I'm trying to load a WPF control in a C++/CLI application, using the HwndSource class.
Here is my code :
UBOOL MyWindowWrapper::Init(const HWND InParentWindowHandle)
{
    Interop::HwndSourceParameters sourceParams( "WindowName" );
    sourceParams.PositionX = 0;
    sourceParams.PositionY = 0;
    sourceParams.ParentWindow = (IntPtr)InParentWindowHandle;
    sourceParams.WindowStyle = (WS_VISIBLE | WS_CHILD);
    sourceParams.HwndSourceHook = nullptr;
    InteropWindow = gcnew Interop::HwndSource(sourceParams);
    Control = gcnew MyWPFUserControl();
    InteropWindow-RootVisual = Control;
    InteropWindow-AddHook(
        gcnew Interop::HwndSourceHook( this, &MyWindowWrapper::MessageHookFunction ) );
    return TRUE;
}
And I define a Hook function so the keyboard events are passed to the window :
IntPtr MyWindowWrapper::MessageHookFunction( IntPtr HWnd, int Msg, IntPtr WParam, IntPtr LParam, bool% OutHandled )
{
    IntPtr Result = (IntPtr)0;
    OutHandled = false;
    if( Msg == WM_GETDLGCODE )
    {
        OutHandled = true;
        // This tells Windows that we'll need keyboard events for this control
        Result = IntPtr( DLGC_WANTALLKEYS | DLGC_WANTCHARS | DLGC_WANTMESSAGE );
    }
    return Result;
}
And here are my problems :
The window title is empty (so the "WindowName" parameter is not taken in account)
Only some keyboard events are transferred : space, control, arrows are ok, but I can't type any character in all the text boxes
What am I doing wrong ?
Thanks !