Hi,
I have an MFC application with a dialog which contains a WPF user control (The WPF user control contains some buttons and other UI controls).
I want to recieve events in the MFC application which occured from the WPF side.
What is the right way to do it ?
Here is how I host the WPF user control inside the MFC dialog (CHostDialog):
HWND CHostDialog::CreateHwnd(HWND parent, int x, int y, int width, int height)
{
System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew System::Windows::Interop::HwndSourceParameters ("MFCWPFApp");
sourceParams->PositionX = x;
sourceParams->PositionY = y;
sourceParams->Height = height;
sourceParams->Width = width;
sourceParams->ParentWindow = IntPtr(parent);
sourceParams->WindowStyle = WS_VISIBLE | WS_CHILD;
Globals::gHwndSource = gcnew System::Windows::Interop::HwndSource(*sourceParams);
Globals::gwcMainControl = gcnew WPFToolUserControl::MainControl();
FrameworkElement^ myPage = Globals::gwcMainControl;
Globals::gHwndSource->RootVisual = myPage;
return (HWND) Globals::gHwndSource->Handle.ToPointer();
}
ref class Globals
{
public:
static System::Windows::Interop::HwndSource^ gHwndSource;
static WPFToolUserControl::MainControl^ gwcMainControl;
};
thanks,
Yoav.