簡體   English   中英

CefWebBrowser沒有出現

[英]CefWebBrowser doesn't show up

解:

此問題是由於未在Program.cs中加載CefRuntime引起的。 只需將示例文件中的所有代碼復制到Program.cs即可。

然后,如果您的CefWebBrowser卡住並且“旋轉等待鼠標光標”,則設置SingleProcess = true。

原因是如果從已識別的輔助進程調用瀏覽器,則整個進程將被阻止,直到進程結束。


題:

任何人都有在WinForm中使用CEF(Chromium Embedded Framework)的經驗?

這個組件讓我折磨了一整天。 我不能讓它發揮作用。 它只是沒有出現。

所以我的問題是:如何在WinForm應用程序中使用CEF?

我確實檢查了論壇,但令人驚訝的是沒有人問過這個問題。 似乎我是唯一一個不懂如何使用它的愚蠢的人。

public partial class Form1 : Form
{
    private CefWebBrowser cefwbShell = null;
    //private readonly SynchronizationContext _pUIThread;

    private void Form1_Load(object sender, EventArgs e)
    {
        cefwbShell.Visible = true;
        cefwbShell = new CefWebBrowser { StartUrl = "http://example.com" };
        cefwbShell.Parent = this;
        cefwbShell.Dock = DockStyle.Fill;
        cefwbShell.BringToFront();
        cefwbShell.Show();
    }
}

更新:

我正在嘗試使用Xilium.CefGlue 在我復制了版本dll(991)的正確版本后,我得到了一個例外:

InvalidOperationException was unhandlled by user code 
   Failed to create browser.

資料來源: Xilium.CefGlue

堆棧跟蹤:

at Xilium.CefGlue.CefBrowserHost.CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, String url) in C:\Winston\Knowledge\Projects\xilium-xilium.cefglue-61551ec98ad8\xilium-xilium.cefglue-61551ec98ad8\CefGlue\Classes.Proxies\CefBrowserHost.cs:line 37
   at Xilium.CefGlue.WindowsForms.CefWebBrowser.OnHandleCreated(EventArgs e) in C:\Winston\Knowledge\Projects\xilium-xilium.cefglue-61551ec98ad8\xilium-xilium.cefglue-61551ec98ad8\CefGlue.WindowsForms\CefWebBrowser.cs:line 71
   at System.Windows.Forms.Control.WmCreate(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)

有人可以幫我嗎?

更新2:

private void Create()
        {
            var page = new TabPage("New Tab");
            page.Padding = new Padding(0, 0, 0, 0);

            var browser = new CefWebBrowser();
            browser.StartUrl = startUrl;
            browser.Dock = DockStyle.Fill;
            browser.TitleChanged += (s, e) =>
            {
                BeginInvoke(new Action(() =>
                {
                    var title = browser.Title;
                    if (tabControl.SelectedTab == page)
                    {
                        Text = browser.Title + " - " + _mainTitle;
                    }
                    page.ToolTipText = title;
                    if (title.Length > 18)
                    {
                        title = title.Substring(0, 18) + "...";
                    }
                    page.Text = title;
                }));
            };
            browser.AddressChanged += (s, e) =>
            {
                BeginInvoke(new Action(() =>
                {
                    addressTextBox.Text = browser.Address;
                }));
            };
            browser.StatusMessage += (s, e) =>
            {
                BeginInvoke(new Action(() =>
                {
                    statusLabel.Text = e.Value;
                }));
            };

            page.Controls.Add(browser);

            tabControl.TabPages.Add(page);

            tabControl.SelectedTab = page;
        }

您不應該使用SingleProcess進行生產,您實際上可以退出多SingleProcess=false模式( SingleProcess=false )但需要禁用Visual Studio Hosting Process並且您不會遇到調試問題(旋轉等待游標)

我也有啟動瀏覽器的問題。 我可以加載所有CEF DLL,但瀏覽器不會顯示! 我得到的只是懸停在控件上方的旋轉等待鼠標光標。

不幸的是我沒有找到問題的根源,但是由於示例項目CefGlue.Client工作,我只是將其復制到我的解決方案中。

另外,我沒有看到你如何初始化CEF運行時。 看看CefGlue.Client中的Program.cs是如何完成的,但它基本上是這樣的:

    [STAThread]
    private static int Main(string[] args)
    {
        try
        {
            CefRuntime.Load();
        }
        catch (DllNotFoundException ex)
        {
            MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return 1;
        }
        catch (CefRuntimeException ex)
        {
            MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return 2;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return 3;
        }

        var mainArgs = new CefMainArgs(args);
        var app = new DemoApp();

        var exitCode = CefRuntime.ExecuteProcess(mainArgs, app);
        if (exitCode != -1)
            return exitCode;

        var settings = new CefSettings
            {
                // BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
                SingleProcess = false,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Disable,
                LogFile = "CefGlue.log",
            };

        CefRuntime.Initialize(mainArgs, settings, app);

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        if (!settings.MultiThreadedMessageLoop)
        {
            Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
        }

        Application.Run(new MainForm());

        CefRuntime.Shutdown();
        return 0;
    }

您從未將控件添加到窗體的控件集合中,至少在您顯示的示例中。

我也有同樣的問題,我通過修改“BrowserSubprocessPath”來解決它,defualt是這樣的:

        //var browserProcessPath = CombinePaths(localFolder, "..", "..", "..",
        //    "CefGlue.Demo.WinForms", "bin", "Release", "Xilium.CefGlue.Demo.WinForms.exe");

        var browserProcessPath = CombinePaths(localFolder, "Xilium.CefGlue.Demo.WinForms.exe");

        var settings = new CefSettings
        {
            BrowserSubprocessPath = browserProcessPath,
            SingleProcess = false,
            MultiThreadedMessageLoop = true,
            LogSeverity = CefLogSeverity.Disable,
            LogFile = "CefGlue.log",
        };

因為我已經更改了應用程序輸出目錄,所以“browserProcessPath”無效,然后我修改“browserProcessPath”以匹配輸出目錄,以便應用程序可以找到它。

但是,我仍然無法理解“browserProcessPath”的含義和用法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM