2018-09-10 02:41:13 +02:00
|
|
|
// Copyright © 2010 The CefSharp Authors. All rights reserved.
|
2014-06-25 12:00:58 +10:00
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
2018-09-17 00:46:21 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2012-02-24 18:33:38 -08:00
|
|
|
using CefSharp.Example;
|
2016-09-01 16:51:20 +10:00
|
|
|
using CefSharp.Example.Handlers;
|
|
|
|
|
using CefSharp.WinForms.Example.Handlers;
|
2014-10-21 21:52:39 +10:00
|
|
|
using CefSharp.WinForms.Example.Minimal;
|
2010-12-03 16:22:41 +00:00
|
|
|
|
2012-02-23 13:20:34 -08:00
|
|
|
namespace CefSharp.WinForms.Example
|
2010-12-03 16:22:41 +00:00
|
|
|
{
|
2015-07-03 12:44:34 +10:00
|
|
|
public class Program
|
2010-12-03 16:22:41 +00:00
|
|
|
{
|
|
|
|
|
[STAThread]
|
2015-11-19 19:03:42 +10:00
|
|
|
public static int Main(string[] args)
|
2010-12-03 16:22:41 +00:00
|
|
|
{
|
2022-08-08 13:37:17 +10:00
|
|
|
// DEMO: Change to true to self host the BrowserSubprocess.
|
|
|
|
|
// instead of using CefSharp.BrowserSubprocess.exe, your applications exe will be used.
|
|
|
|
|
// In this case CefSharp.WinForms.Example.exe
|
2020-11-26 09:27:35 +10:00
|
|
|
const bool selfHostSubProcess = false;
|
2015-11-19 19:03:42 +10:00
|
|
|
|
2020-11-25 16:17:49 +10:00
|
|
|
if (selfHostSubProcess)
|
2015-07-03 12:44:34 +10:00
|
|
|
{
|
2020-11-26 09:27:35 +10:00
|
|
|
var exitCode = CefSharp.BrowserSubprocess.SelfHost.Main(args);
|
2015-11-19 19:03:42 +10:00
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
if (exitCode >= 0)
|
2015-11-19 19:03:42 +10:00
|
|
|
{
|
|
|
|
|
return exitCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
if (!System.Diagnostics.Debugger.IsAttached)
|
|
|
|
|
{
|
2019-01-10 23:57:28 +01:00
|
|
|
MessageBox.Show("When running this Example outside of Visual Studio " +
|
2015-11-19 19:03:42 +10:00
|
|
|
"please make sure you compile in `Release` mode.", "Warning");
|
|
|
|
|
}
|
2015-07-03 12:44:34 +10:00
|
|
|
#endif
|
|
|
|
|
|
2015-11-19 19:03:42 +10:00
|
|
|
var settings = new CefSettings();
|
2020-04-29 08:13:08 +10:00
|
|
|
settings.BrowserSubprocessPath = System.IO.Path.GetFullPath("CefSharp.WinForms.Example.exe");
|
2015-11-19 19:03:42 +10:00
|
|
|
|
|
|
|
|
Cef.Initialize(settings);
|
2015-10-21 19:56:45 +10:00
|
|
|
|
2022-08-08 13:37:17 +10:00
|
|
|
Application.EnableVisualStyles();
|
2021-07-29 11:09:58 +10:00
|
|
|
var browser = new SimpleBrowserForm();
|
2015-11-19 19:03:42 +10:00
|
|
|
Application.Run(browser);
|
|
|
|
|
}
|
|
|
|
|
else
|
2015-10-21 19:56:45 +10:00
|
|
|
{
|
2015-11-19 19:03:42 +10:00
|
|
|
#if DEBUG
|
|
|
|
|
if (!System.Diagnostics.Debugger.IsAttached)
|
|
|
|
|
{
|
2019-01-10 23:57:28 +01:00
|
|
|
MessageBox.Show("When running this Example outside of Visual Studio " +
|
2015-11-19 19:03:42 +10:00
|
|
|
"please make sure you compile in `Release` mode.", "Warning");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-08-08 13:37:17 +10:00
|
|
|
// DEMO: To integrate CEF into your applications existing message loop
|
|
|
|
|
// set multiThreadedMessageLoop = false;
|
2019-06-02 20:08:12 +10:00
|
|
|
const bool multiThreadedMessageLoop = true;
|
2022-08-08 13:37:17 +10:00
|
|
|
// When multiThreadedMessageLoop = true then externalMessagePump must be set to false
|
|
|
|
|
// To enable externalMessagePump set multiThreadedMessageLoop = false and externalMessagePump = true
|
2019-05-15 21:27:56 +10:00
|
|
|
const bool externalMessagePump = false;
|
2015-11-19 19:03:42 +10:00
|
|
|
|
2022-08-08 13:37:17 +10:00
|
|
|
//TEST: There are a number of different Forms for testing purposes.
|
2019-06-01 09:00:29 +10:00
|
|
|
var browser = new BrowserForm(multiThreadedMessageLoop);
|
2023-01-06 06:32:02 +10:00
|
|
|
//var browser = new SimpleBrowserForm();
|
2015-11-19 19:03:42 +10:00
|
|
|
//var browser = new TabulationDemoForm();
|
2016-09-01 16:51:20 +10:00
|
|
|
|
|
|
|
|
IBrowserProcessHandler browserProcessHandler;
|
|
|
|
|
|
2018-09-10 02:41:13 +02:00
|
|
|
if (multiThreadedMessageLoop)
|
2016-09-01 16:51:20 +10:00
|
|
|
{
|
|
|
|
|
browserProcessHandler = new BrowserProcessHandler();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-05-15 21:27:56 +10:00
|
|
|
if (externalMessagePump)
|
|
|
|
|
{
|
2019-06-02 20:34:44 +10:00
|
|
|
//Get the current taskScheduler (must be called after the form is created)
|
|
|
|
|
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
|
2019-05-15 21:27:56 +10:00
|
|
|
browserProcessHandler = new ScheduleMessagePumpBrowserProcessHandler(scheduler);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-06-02 20:34:44 +10:00
|
|
|
//We'll add out WinForms timer to the components container so it's Diposed
|
|
|
|
|
browserProcessHandler = new WinFormsBrowserProcessHandler(browser.Components);
|
2019-05-15 21:27:56 +10:00
|
|
|
}
|
|
|
|
|
|
2016-09-01 16:51:20 +10:00
|
|
|
}
|
|
|
|
|
|
2018-08-02 10:47:12 +10:00
|
|
|
var settings = new CefSettings();
|
|
|
|
|
settings.MultiThreadedMessageLoop = multiThreadedMessageLoop;
|
2019-05-15 21:27:56 +10:00
|
|
|
settings.ExternalMessagePump = externalMessagePump;
|
2018-08-02 10:47:12 +10:00
|
|
|
|
|
|
|
|
CefExample.Init(settings, browserProcessHandler: browserProcessHandler);
|
2016-09-01 16:51:20 +10:00
|
|
|
|
2022-08-08 13:37:17 +10:00
|
|
|
Application.EnableVisualStyles();
|
2021-07-29 11:09:58 +10:00
|
|
|
//Application.Run(new MultiFormAppContext());
|
2015-11-19 19:03:42 +10:00
|
|
|
Application.Run(browser);
|
2015-10-21 19:56:45 +10:00
|
|
|
}
|
2010-12-03 16:22:41 +00:00
|
|
|
|
2015-11-19 19:03:42 +10:00
|
|
|
return 0;
|
2010-12-03 16:22:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|