Skip to content

Commit

Permalink
WinForms - If the ChromiumWebBrowser has it's handle recreated then i…
Browse files Browse the repository at this point in the history
…n OnHandleCreated we will now attempt to reparent a existing instance rather than creating a new browser

# Conflicts:
#	CefSharp.WinForms/ChromiumWebBrowser.cs
  • Loading branch information
amaitland committed Jan 18, 2018
1 parent 0032ae4 commit 85e3297
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CefSharp.Core/NativeMethodWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ namespace CefSharp
}
}
}

void NativeMethodWrapper::SetWindowParent(IntPtr child, IntPtr newParent)
{
HWND childHwnd = static_cast<HWND>(child.ToPointer());
HWND newParentHwnd = static_cast<HWND>(newParent.ToPointer());

SetParent(childHwnd, newParentHwnd);
}
}
1 change: 1 addition & 0 deletions CefSharp.Core/NativeMethodWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ namespace CefSharp
static void CopyMemoryUsingHandle(IntPtr dest, IntPtr src, int numberOfBytes);
static bool IsFocused(IntPtr handle);
static void SetWindowPosition(IntPtr handle, int x, int y, int width, int height);
static void SetWindowParent(IntPtr child, IntPtr newParent);
};
}
11 changes: 10 additions & 1 deletion CefSharp.WinForms/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,16 @@ private void CreateBrowser()

if (((IWebBrowserInternal)this).HasParent == false)
{
managedCefBrowserAdapter.CreateBrowser(BrowserSettings, (RequestContext)requestContext, Handle, Address);
if(IsBrowserInitialized == false || browser == null)
{
managedCefBrowserAdapter.CreateBrowser(BrowserSettings, (RequestContext)RequestContext, Handle, Address);
}
else
{
//If the browser already exists we'll reparent it to the new Handle
var browserHandle = browser.GetHost().GetWindowHandle();
NativeMethodWrapper.SetWindowParent(browserHandle, Handle);
}
}
}

Expand Down

0 comments on commit 85e3297

Please sign in to comment.