基于OpenCV的视频图像组态 (9):CEF浏览器初步

来源:互联网 发布:ubuntu wine 1.9 编辑:程序博客网 时间:2024/04/30 16:00

背景

之前,一直用WebBrowser,感觉网页的应用需求够用了。

直到Html5的出现,那么炫的功能,WebBrowser却展示不出来。就想有没有什么好的方法。不过一直没腾出手来,其次需求也不是太强烈,就没怎么琢磨。

本周,接了航天与军方两个项目,需要做故障诊断,突然发现,如果把HTML5的功能结合进来,管理系统与图形软件整合,效果会很好。

趁着周末,钻研了一下,居然OK了。

 

思路

先找支持HTML5的浏览器,花了一个小时,确定采用CEF(Chromium Embedded Framework),感觉比较靠谱。

靠谱的原因是有源码。

如果有源码还搞不定,那也就枉编这么多年的代码了。

下载并编译,却突然发现有个cef4delphi,直接装上就OK了。

 

在 Delphi下很容易就调用成功了,但在CB下却折腾好久,最终解决后却发现,白折腾,把Dll/resource等放到目标目录下即可。

 

几点:

1) 初始化

    GlobalCEFApp = new TCefApplication;

    GlobalCEFApp->FrameworkDirPath = THelper::File::GetApplicationPath();

    GlobalCEFApp->ResourcesDirPath = GlobalCEFApp->FrameworkDirPath;

    GlobalCEFApp->LocalesDirPath = GlobalCEFApp->FrameworkDirPath +

        L"locales\\";

    GlobalCEFApp->Cache = GlobalCEFApp->FrameworkDirPath + L"cef\cache";

    GlobalCEFApp->Cookies = GlobalCEFApp->FrameworkDirPath + L"cef\cookies";

    GlobalCEFApp->UserDataPath = GlobalCEFApp->FrameworkDirPath +

        L"cef\User Data";

    GlobalCEFApp->EnableGPU = True; // Enable hardware acceleration

    GlobalCEFApp->MultiThreadedMessageLoop = false;

    GlobalCEFApp->FlashEnabled = false;

    GlobalCEFApp->FastUnload = true;

 

2) 创建浏览器

bool __fastcall NewBrowser(TWinControl * control) {

    if(Chromium) {

        int times = 0;

        while(!Chromium->CreateBrowser(control) && ++times < 5)

            THelper::Util::Delay(1000);

        if(times >= 5)

            return false;

        FBrowserParent = control;

        return true;

    }

    return false;

}

 

3) 载入URL

Chromium->LoadURL(url);

这样就实现了CEF浏览器。后续再加入元素之间的交互功能。

演示效果

 

 

没有对比就没有伤害,看看这个浏览器(下图左)与WebBrowser(下图右)就知道了。

 

网上溜达的时候,发现一个求助帖:https://www.freelancer.hk/projects/CPlusPlus-Programming/Sample-VCL-application-with-embedded/

I need someone to write a sample VCL application in C++ Builder XE8 (or newer) aiming to demonstrate:

1. How to embed Chromium Embedded Framework (CEF - [url removed, login to view]) into an Win32 application.

2. How to navigate CEF component to a specified URL.

3. How to execute arbitrary (sample alert) Javascript within CEF component.

4. How to receive an event called before navigation (similar to OnBeforeNavigate2 in TCppWebBrowser).

5. How to receive an event called when page finishes loading (similar to OnDocumentComplete in TCppWebBrowser).

6. How to receive an event called when error occurs during page load (similar to OnNavigateError in TCppWebBrowser).

7. How to intercept popup windows (i.e. javascript alerts) called within CEF component HTML page.

The sample code should be compiled solely within C++ Builder IDE, no additional compilers should be involved.

The sample code should have comments regarding executed actions and intentions.

 

项目报价大概$400,可惜项目关闭了。

阅读全文
0 0
原创粉丝点击