CefWebBrowser不显示 [英] CefWebBrowser doesn't show up

查看:4590
本文介绍了CefWebBrowser不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案:



此问题是由不加载在Program.cs中CefRuntime造成的。简单地复制示例文件到您的Program.cs中所有代码。



然后,如果你的CefWebBrowser被卡住,并有一纺等待鼠标光标,然后将SingleProcess =真



的原因是,如果在浏览器从一个公认的次级过程调用,整个过程将被阻止,直到处理结束。






问:



任何人有在winform使用CEF经验(铬嵌入式框架)?



此组件已折磨了我整整一天。我不能使它工作。
它只是简单地不露面



所以我的问题是:如何在WinForm应用程序使用CEF



我做检查的论坛,但出人意料的没有一个人问过这个问题。
好像只有我哑的人谁不知道如何使用它。

 公共部分类Form1中:形态
{
私人CefWebBrowser cefwbShell = NULL;
//私人只读的SynchronizationContext _pUIThread;

私人无效Form1_Load的(对象发件人,EventArgs五)
{
cefwbShell.Visible = TRUE;
cefwbShell =新CefWebBrowser {StartUrl =htt​​p://example.com};
cefwbShell.Parent =这一点;
cefwbShell.Dock = DockStyle.Fill;
cefwbShell.BringToFront();
cefwbShell.Show();
}
}



更新:



我想使用 Xilium.CefGlue
后,我复制释放的dll的正确版本(991)我得到一个异常:

  InvalidOperationException异常被用户unhandlled代码
无法创建浏览器。

来源:
Xilium.CefGlue



堆栈跟踪:

 在Xilium.CefGlue.CefBrowserHost。 CreateBrowser(CefWindowInfo windowInfo,CefClient客户端,CefBrowserSettings设置,字符串URL)在C:\Winston\Knowledge\Projects\xilium-xilium.cefglue-61551ec98ad8\xilium-xilium.cefglue-61551ec98ad8\CefGlue\Classes .Proxies\CefBrowserHost.cs:\Winston\Knowledge\Projects\xilium-xilium.cefglue-61551ec98ad8\\:在Xilium.CefGlue.WindowsForms.CefWebBrowser.OnHandleCreated(EventArgs五)在C线37 
\\xilium-xilium.cefglue-61551ec98ad8\CefGlue.WindowsForms\CefWebBrowser.cs:在System.Windows.Forms.Control.WmCreate线71
(消息和M)
在System.Windows.Forms的.Control.WndProc(消息&放大器;米)
。在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息&放大器;米)
。在System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息&放大器,M )
在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr的的HWND,味精的Int32,IntPtr的WPARAM,LPARAM的IntPtr)
在System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(的Int32 dwExStyle参数,字符串lpszClassName,字符串lpszWindowName,的Int32风格的Int32 X,的Int32 Y,宽度的Int32,的Int32高度,HandleRef hWndParent,HandleRef HMENU,HandleRef HINST,对象pvParam)
在System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(的Int32 dwExStyle参数,字符串lpszClassName,串lpszWindowName,的Int32风格的Int32 X,的Int32 Y,宽度的Int32,的Int32高度,HandleRef hWndParent,HandleRef HMENU,HandleRef HINST,对象在System.Windows.Forms.NativeWindow.CreateHandle(CP的CreateParams)$ b pvParam)
在System.Windows.Forms.Control.CreateHandle()
在System.Windows.Forms.Control.CreateControl(布尔fIgnoreVisible)
。在System.Windows.Forms.Control.CreateControl $ b(布尔fIgnoreVisible)在System.Windows.Forms.Control.CreateControl()
在System.Windows.Forms.Control.SetVisibleCore(布尔值)



谁能帮我请



更新2:

 私人无效的Create()
{
VAR页=新的TabPage(新建选项卡);
page.Padding =新填充(0,0,0,0);

变种浏览器=新CefWebBrowser();
browser.StartUrl = startUrl;
browser.Dock = DockStyle.Fill;
browser.TitleChanged + =(S,E)=>
{
的BeginInvoke(新动作(()=>
{
VAR标题= browser.Title;
如果(tabControl.SelectedTab ==页)
{
文字= browser.Title + - + _mainTitle;
}
page.ToolTipText =称号;
如果(title.Length> 18)
{
标题= title.Substring(0,18)+...;
}
page.Text =称号;
}));
};
browser.AddressChanged + =(S,E)=>
{
的BeginInvoke(新动作(()=>
{
addressTextBox.Text = browser.Address;
}));
};
browser.StatusMessage + =(S,E)=>
{
的BeginInvoke(新动作(()=>
{
statusLabel.Text = e.Value;
}));
};

page.Controls.Add(浏览器);

tabControl.TabPages.Add(页);

tabControl.SelectedTab =页;
}


解决方案

我也有问题启动浏览器。我可以加载所有的DLL CEF的,但是浏览器不会显示出来!所有我徘徊在控制上面的时候是纺纱等待鼠标光标。



不幸的是我还没有找到问题的根源,但由于样本项目CefGlue.Client作品中,我简单地将它复制到我的解决方案来代替。



另外,我不知道你是如何初始化CEF运行。在Program.cs中的CefGlue.Client看看它是如何做的,但它基本上是这样的:

  [STAThread] 
私人静态INT主要(字串[] args)
{

{
CefRuntime.Load();
}
赶上(DllNotFoundException前)
{
MessageBox.Show(ex.Message,错误!,MessageBoxButtons.OK,MessageBoxIcon.Error);
返回1;
}
赶上(CefRuntimeException前)
{
MessageBox.Show(ex.Message,错误!,MessageBoxButtons.OK,MessageBoxIcon.Error);
返回2;
}
赶上(异常前)
{
MessageBox.Show(ex.ToString(),错误!,MessageBoxButtons.OK,MessageBoxIcon.Error);
返回3;
}

变种mainArgs =新CefMainArgs(参数);
VAR应用=新DemoApp();

VAR EXITCODE = CefRuntime.ExecuteProcess(mainArgs,应用);
如果(EXITCODE!= -1)
返回EXITCODE;

VAR设置=新CefSettings
{
// BrowserSubprocessPath = @D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\\ \\bin\Release\Xilium.CefGlue.Demo.exe,
SingleProcess =假,
MultiThreadedMessageLoop = TRUE,
LogSeverity = CefLogSeverity.Disable,
日志文件=CefGlue .LOG,
};

CefRuntime.Initialize(mainArgs,设置,应用程序);

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(假);

如果
{
Application.Idle + =(发件人,E)=>(settings.MultiThreadedMessageLoop!); {CefRuntime.DoMessageLoopWork(); };
}

Application.Run(新的MainForm());

CefRuntime.Shutdown();
返回0;
}


Solution:

This issue is caused by not loading the CefRuntime in the Program.cs. Simply copying all code in the sample file to your Program.cs.

And then if your CefWebBrowser is stuck and having "a spinning wait mouse cursor" then set the SingleProcess = true.

The reason is if the browser is called from a recognized secondary process, the whole process will be blocked until the process is ended.


Question:

Anyone has experience using CEF (Chromium Embedded Framework) in WinForm?

This component has tortured me a whole day. I cannot make it work. It just simply doesn't show up.

So my question is: how to use CEF in a WinForm application?

I did check the forum, but surprisingly no one asked this question. It seems like I am the only dumb person who doesn't know how to use it.

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();
    }
}

Update:

I am trying to use Xilium.CefGlue. After I copied right version of the release dlls (991) I get an exception:

InvalidOperationException was unhandlled by user code 
   Failed to create browser.

Source: Xilium.CefGlue

Stack Trace:

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)

Can anyone help me please?

Update 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;
        }

解决方案

I too had problems launching the browser. I could load all the CEF DLL's, but the browser wouldn't show up! All I got was the spinning wait mouse cursor when hovering above the control.

Unfortunately I haven't found the root of the problem, but since the sample project CefGlue.Client works, I simply copied it to my solution instead.

Also, I don't see how you are initializing the CEF runtime. Have a look in Program.cs in CefGlue.Client how it's done, but it's basically this:

    [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;
    }

这篇关于CefWebBrowser不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆