app.manifest
Код: Выделить всё
PerMonitorV2
App.xaml/.xaml.cs
Код: Выделить всё
Код: Выделить всё
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
bool cefInitialized = InitializeCef();
if (!cefInitialized)
{
Shutdown();
return;
}
var main = new MainWindow();
main.Show();
}
private bool InitializeCef()
{
if (Cef.IsInitialized ?? false) return true;
string subprocessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CefSharp.BrowserSubprocess.exe");
var settings = new CefSettings
{
CachePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "cache"),
LogFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "cef.log"),
LogSeverity = LogSeverity.Verbose,
BrowserSubprocessPath = subprocessPath,
MultiThreadedMessageLoop = true
};
settings.DisableGpuAcceleration();
var initialized = Cef.Initialize(settings, performDependencyCheck: true);
if (!initialized)
{
var exitCode = Cef.GetExitCode();
MessageBox.Show($"CEF initialisation failed. Code: '{exitCode}'.", "Critical Error", MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
return true;
}
protected override void OnExit(ExitEventArgs e)
{
if (Cef.IsInitialized ?? false)
{
Cef.Shutdown();
}
base.OnExit(e);
}
}
MainWindow.xaml/.xaml.cs
Код: Выделить всё
Код: Выделить всё
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Browser.Address = "https://www.google.com";
}
}
Я заметил, что при запуске, когда я инициализирую CEF, в этой части кода:
Код: Выделить всё
var initialized = Cef.Initialize(settings, performDependencyCheck: true);
Мне не нравится, что подпроцесс открывается со страницей Google; Я хочу, чтобы основной процесс загружал окно для отображения страницы Google. Прямо сейчас я получаю сообщение об ошибке инициализации CEF с кодом NormalExitAutoDeElevated, но страница все еще открыта. Я хотел бы понять, как это работает, и решить эту проблему.
Надеюсь, вы мне поможете.
Подробнее здесь: https://stackoverflow.com/questions/798 ... pf-project
Мобильная версия