Hi!
I am trying to host a delphi 7 vcl application in a .Net wpf application. Everything works fine, except that modal dialogs do not behave like modal dialogs, the parent window does not turn off.
This is my code:
class MySimpleDelphiHost : HwndHost
{
private Process _appProc;
public IntPtr hwndHost;
protected override HandleRef BuildWindowCore(HandleRef hwndParent)
{
_appProc = new Process();
_appProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
_appProc.StartInfo.FileName = @"MySimpleDelphiApplication.exe";
_appProc.Start();
Thread.Sleep(1000);
hwndHost = Win32API.FindWindow("TMainForm", null);
int oldStyle = Win32API.GetWindowLong(hwndHost, Win32API.GWL_STYLE);
Win32API.SetWindowLong(hwndHost, Win32API.GWL_STYLE, (oldStyle | Win32API.WS_CHILD) & ~Win32API.WS_BORDER);
Win32API.SetParent(hwndHost, hwndParent.Handle);
Win32API.ShowWindowAsync(hwndHost, Win32API.SW_SHOWMAXIMIZED);
return new HandleRef(this, hwndHost);
}
protected override void DestroyWindowCore(HandleRef hwnd)
{
_appProc.Kill();
}
}
If I host any delphi application, this works fine. Any ideas?
I created a demo http://www.easy-share.com/1913154119/SimpleDelphiAppHosting.zip . Sorry for the hosting site.
source
share