public int Run(CefConfig config) { var res = Instance.GetScreenResolution(); var scaleFactor = GetScalingFactor(GetDC(IntPtr.Zero)); config.Width = (int)(config.Width > 0 ? config.Width * scaleFactor : res.Width * .75); config.Height = (int)(config.Height > 0 ? config.Height * scaleFactor : res.Height * .75); if (config.HideConsoleWindow) { Instance.HideConsoleWindow(); } var factory = WinapiHostFactory.Init(config.Icon); using (var window = factory.CreateWindow( () => new CefGlueHost(config), config.WindowTitle, constructionParams: new FrameWindowConstructionParams())) { window.SetSize(config.Width, config.Height); if (config.CenterToScreen) { window.CenterToScreen(); } else if (config.X != null || config.Y != null) { window.SetPosition(config.X.GetValueOrDefault(), config.Y.GetValueOrDefault()); } window.Show(); //startTask.Wait(); return(new EventLoop().Run(window)); } }
public CefGlueBrowser(IntPtr parentHandle, CefApp app, CefConfig config) { this.ParentHandle = parentHandle; this.App = app; this.Config = config; var windowInfo = CefWindowInfo.Create(); windowInfo.SetAsChild(parentHandle, new CefRectangle(0, 0, config.Width, config.Height)); this.WebBrowser = new WebBrowser(this); this.WebBrowser.Created += WebBrowser_Created; this.Client = new WebClient(this.WebBrowser); CefBrowserHost.CreateBrowser(windowInfo, Client, config.CefBrowserSettings, config.StartUrl); }
public int Run(CefConfig config) { this.config = config; var res = Instance.GetScreenResolution(); if (config.FullScreen || config.Kiosk) { config.Width = (int)(ScaleFactor * res.Width) - 1; config.Height = (int)(ScaleFactor * res.Height); } else { config.Width = (int)(config.Width > 0 ? config.Width * ScaleFactor : res.Width * .75); config.Height = (int)(config.Height > 0 ? config.Height * ScaleFactor : res.Height * .75); } if (config.HideConsoleWindow && !config.Verbose) { Instance.HideConsoleWindow(); } var factory = WinapiHostFactory.Init(config.Icon); using (window = factory.CreateWindow( () => new CefGlueHost(config), config.WindowTitle, constructionParams: new FrameWindowConstructionParams())) { try { DesktopState.BrowserHandle = window.Handle; DesktopState.ConsoleHandle = ConsoleHandle; foreach (var scheme in config.Schemes) { CefRuntime.RegisterSchemeHandlerFactory(scheme.Scheme, scheme.Domain, new CefProxySchemeHandlerFactory(scheme)); if (scheme.AllowCors && scheme.Domain != null) { CefRuntime.AddCrossOriginWhitelistEntry(config.StartUrl, scheme.TargetScheme ?? scheme.Scheme, scheme.Domain, true); } } foreach (var schemeFactory in config.SchemeFactories) { CefRuntime.RegisterSchemeHandlerFactory(schemeFactory.Scheme, schemeFactory.Domain, schemeFactory.Factory); if (schemeFactory.AddCrossOriginWhitelistEntry) { CefRuntime.AddCrossOriginWhitelistEntry(config.StartUrl, schemeFactory.Scheme, schemeFactory.Domain, true); } } // if (config.Verbose) // { // Console.WriteLine( // @$"GetScreenResolution: {res.Width}x{res.Height}, scale:{ScaleFactor}, {(int) (ScaleFactor * res.Width)}x{(int) (ScaleFactor * res.Width)}"); // var rect = Instance.GetClientRectangle(window.Handle); // Console.WriteLine( // @$"GetClientRectangle: [{rect.Top},{rect.Left}] [{rect.Bottom},{rect.Right}], scale: [{(int) (rect.Bottom * ScaleFactor)},{(int) (rect.Right * ScaleFactor)}]"); // } if (config.CenterToScreen) { window.CenterToScreen(); } else if (config.X != null || config.Y != null) { window.SetPosition(config.X.GetValueOrDefault(), config.Y.GetValueOrDefault()); } if (config.Kiosk || config.FullScreen) { Instance.SetWindowFullScreen(window.Handle); } else { window.SetSize(config.Width, config.Height - 1); //force redraw in BrowserCreated } window.Browser.BrowserCreated += (sender, args) => { var cef = (CefGlueBrowser)sender; if (!cef.Config.Kiosk) { window.SetSize(config.Width, config.Height); //trigger refresh to sync browser frame with window if (config.CenterToScreen) { window.CenterToScreen(); } if (config.FullScreen) { User32.ShowWindow(window.Handle, User32.WindowShowStyle.SW_MAXIMIZE); } } else { EnterKioskMode(); cef.BrowserWindowHandle.ShowScrollBar(NativeWin.SB_BOTH, false); } }; window.Show(); return(new EventLoop().Run(window)); } catch (Exception e) { Console.WriteLine(e); throw; } } }
public static int Start(CefConfig config) { Instance = Provider; return(Provider.Run(config)); }