10

解決:

この問題は、CefRuntime が Program.cs に読み込まれていないことが原因で発生します。サンプル ファイルのすべてのコードを 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;
        }
4

4 に答える 4

5

SingleProcess実際にはマルチプロセス モードをSingleProcess=false終了できVisual Studio Hosting Processます(

于 2013-03-07T01:31:24.120 に答える
4

私もブラウザの起動に問題がありました。すべての 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;
    }
于 2013-01-21T11:01:20.407 に答える
1

少なくとも表示したサンプルでは、​​フォームのコントロールコレクションにコントロールを追加したことはありません。

于 2013-01-21T00:16:37.793 に答える
1

私も同じ問題を抱えていました。「BrowserSubprocessPath」を変更して解決しました。デフォルトは次のようになります。

        //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」の意味と使い方がいまいち理解できません。

于 2016-06-14T09:38:25.640 に答える