Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Add IBrowserProcessHandler.OnScheduleMessagePumpWork #1748

Closed
amaitland opened this issue Jul 20, 2016 · 8 comments
Closed

Comments

@amaitland
Copy link
Member

amaitland commented Jul 20, 2016

CEF Now provides support for integrating into an existing message loop.

Resolved with 63ef6be

Breaking Change:
Cef.OnContextInitialized has been removed and is now part of the IBrowserProcessHandler interface.

Notes:

Background:
The default is to use MultiThreadedMessageLoop, this provides excellent performance though has it's own problems in the message loop is run in a different thread to your main application. This makes it difficult for messages to be passed, like when you display the context menu, click on your app title bar, there menu will stay shown as the message loops aren't aware of the message triggered by clicking the title bar.

@amaitland amaitland added this to the 53.0.0 milestone Jul 20, 2016
@amaitland
Copy link
Member Author

amaitland commented Sep 8, 2016

I've added a rough example, not production ready by any means.

https://github.com/cefsharp/CefSharp/search?l=C%23&q=OnScheduleMessagePumpWork

@amaitland
Copy link
Member Author

amaitland commented Oct 10, 2016

For WinForms Arrows and Tab keys don't work when integrating into a current message loop. I've applied a fix to master, you can either subclass ChromiumWebBrowser and override the same method or hook PreviewKeyDown and set e.IsInputKey=true; for those keys as described in http://stackoverflow.com/a/7815185
Fix in master is e23ad38

@amaitland
Copy link
Member Author

@cplotts
Copy link

cplotts commented Jul 25, 2018

Is integrating into a current message loop still an acceptable solution?

Also, I'm not thrilled with adding a timer that runs 30 times a second. It doesn't seem to adversely affect performance but it's always running ... even if a ChromiumWebBrowser is not being shown/used. Is there a way, maybe, to set up a WpfBrowserProcessHandler ... when using a ChromiumWebBrowser ... and then taking it down ... when I'm no longer using a ChromiumWebBrowser? That is, is there another way to hook this baby in ... instead of via Cef.Initialize?

@amaitland
Copy link
Member Author

Is integrating into a current message loop still an acceptable solution?

Yes, see https://github.com/cefsharp/CefSharp/wiki/General-Usage#multithreadedmessageloop

Is there a way, maybe, to set up a WpfBrowserProcessHandler ... when using a ChromiumWebBrowser ... and then taking it down ... when I'm no longer using a ChromiumWebBrowser? That is, is there another way to hook this baby in ... instead of via Cef.Initialize?

No, we're limited by the CEF API here.

http://magpcss.org/ceforum/apidocs3/projects/(default)/(_globals).html#CefInitialize(constCefMainArgs&,constCefSettings&,CefRefPtr%3CCefApp%3E,void*)
http://magpcss.org/ceforum/apidocs3/projects/(default)/CefApp.html#GetBrowserProcessHandler()
http://magpcss.org/ceforum/apidocs3/projects/(default)/CefBrowserProcessHandler.html#OnScheduleMessagePumpWork(int64)

@amaitland
Copy link
Member Author

There is nothing that says you have to run a Timer from within the IBrowserProcessHandler, you just need to call Cef.DoMessageLoopWork sufficiently frequently for your application to run smoothly (usually at least 30 times per second).

http://magpcss.org/ceforum/apidocs3/projects/(default)/(_globals).html#CefDoMessageLoopWork()

If you have further questions please ask them on https://gitter.im/cefsharp/CefSharp

@JacquesOkes

This comment has been minimized.

@A-J-Bauer
Copy link

A-J-Bauer commented Aug 31, 2020

Maybe this quick hack helps someone. For the menu to close when clicking on the browser control I created a simple class file "ChromiumWebBrowser.cs" and added:

	using  System;
	using System.Runtime.InteropServices;
	using System.Windows.Forms;

	namespace CefSharp.MinimalExample.WinForms
	{
		[Obsolete]
		class ChromiumWebBrowser : CefSharp.WinForms.ChromiumWebBrowser
		{
			public ChromiumWebBrowser(string path) : base(path)
			{           
			}

			[return: MarshalAs(UnmanagedType.Bool)]
			[DllImport("user32.dll", SetLastError = true)]
			static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

			protected override void WndProc(ref Message m)
			{
				const int WM_PARENTNOTIFY = 0x0210;
				const int WM_NCLBUTTONDOWN = 0x00A1;
				//Console.WriteLine(m.Msg);
				if (m.Msg == WM_PARENTNOTIFY)
				{
					PostMessage(Parent.Handle, WM_NCLBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
				}
				base.WndProc(ref m);
			}
		}
	}

@cefsharp cefsharp locked as resolved and limited conversation to collaborators Aug 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants