基於OpenCV的視頻圖像組態 (9):CEF瀏覽器初步

背景 javascript

以前,一直用WebBrowser,感受網頁的應用需求夠用了。html

直到Html5的出現,那麼炫的功能,WebBrowser卻展現不出來。就想有沒有什麼好的方法。不過一直沒騰出手來,其次需求也不是太強烈,就沒怎麼琢磨。java

本週,接了航天與軍方兩個項目,須要作故障診斷,忽然發現,若是把HTML5的功能結合進來,管理系統與圖形軟件整合,效果會很好。windows

趁着週末,鑽研了一下,竟然OK了。瀏覽器

 

思路 cookie

先找支持HTML5的瀏覽器,花了一個小時,肯定採用CEF(Chromium Embedded Framework),感受比較靠譜。app

靠譜的緣由是有源碼。oop

若是有源碼還搞不定,那也就枉編這麼多年的代碼了。ui

下載並編譯,卻忽然發現有個cef4delphi,直接裝上就OK了。url

 

在 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,惋惜項目關閉了。

相關文章
相關標籤/搜索