2

I need to use a WPF Lib with a System.Windows.Navigation.NavigationWindow in a MFC Win32 app but I have a black screen instead of my WPF Windows. I have no error message in the debug output.

All the other WPF control I tried work fine in MFC (button, grid, D3D with C++).

Anyone have an idea how to debug that or how to investigate that?

Thanks

EDIT: The problem happen with System.Windows::Window too. And it work fineif I use my WPF in a WPF App.

DarkPixel
  • 246
  • 1
  • 8
  • do you have small sample that produces this problem you're having? – Erti-Chris Eelmaa Dec 16 '14 at 14:57
  • You can get the microsoft sample and just add NavigationWindow in WPF: http://go.microsoft.com/fwlink/?LinkID=160004 – DarkPixel Dec 16 '14 at 15:39
  • DarkPixel, does this seem similiar? http://stackoverflow.com/questions/19794765/creating-a-reusable-window-control – Erti-Chris Eelmaa Dec 16 '14 at 21:36
  • Maybe it's related. But it work fine in a WPF app, my probleme seem specific to MFC – DarkPixel Dec 16 '14 at 21:45
  • I am not entirely sure if I understand you: are you trying to host WPF Window inside Win32 window? That's not going to be possible. Or are you just calling `(new System.Windows::Window()).Show();` ? – Erti-Chris Eelmaa Dec 16 '14 at 21:56
  • Yes that's what I want. I tried with hwndSource->RootVisual = gcnew MyWindows(). All other control work. Why it's not possible? – DarkPixel Dec 16 '14 at 22:08
  • DarkPixel, okay, I am not 100% sure, but you should try `SetWindowLong` and pass WS_CHILD on your WPF window before setting it as `RootVisual`. It's going to be something similiar to this: http://stackoverflow.com/questions/5028598/hosting-external-app-in-wpf-window See TGasdf post – Erti-Chris Eelmaa Dec 16 '14 at 22:42
  • I see something but it crash if I interact with my WPF windows. My workaround at the moment is to host a process (WPF) and parent the main window in my MFC. It work fine but I would prefer a solution with only process – DarkPixel Dec 17 '14 at 14:11

1 Answers1

0

I can't find a working solution but here's my workaround at the moment.

I created a separate a WPF app with my WPF Lib.

And in my MFC app I do:

HWND wpfProcessMainWnd = CreateProcessWPF();

SetParent(wpfProcessMainWnd, hWnd);

DWORD style = GetWindowLong(wpfProcessMainWnd, GWL_STYLE);
style |= WS_CHILD;
style &= ~(WS_BORDER | WS_OVERLAPPEDWINDOW);

SetWindowLong(wpfProcessMainWnd, GWL_STYLE, style);

SetWindowPos(wpfProcessMainWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER);

From:
https://stackoverflow.com/a/16641537/2849700

Community
  • 1
  • 1
DarkPixel
  • 246
  • 1
  • 8