1. 程式人生 > 其它 >cef右鍵儲存圖片

cef右鍵儲存圖片

 

    // CefContextMenuHandler methods
    void BrowserHandler::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
            CefRefPtr<CefFrame> frame,
            CefRefPtr<CefContextMenuParams> params,
            CefRefPtr<CefMenuModel> model) {
        REQUIRE_UI_THREAD();
        
        
// CM_TYPEFLAG_MEDIA 包含圖片、視訊、檔案等等 // 可以再進行細化判斷:params->GetMediaType() & CM_MEDIATYPE_IMAGE != 0 if ((params->GetTypeFlags() & CM_TYPEFLAG_MEDIA) != 0 && (params->GetMediaType() & CM_MEDIATYPE_IMAGE != 0)) { if (model->GetCount() > 0) {
// 禁止右鍵選單 model->Clear(); } model->InsertItemAt(0, CLIENT_ID_COPY_IMAGE, L"複製圖片"); model->InsertItemAt(1, CLIENT_ID_SAVE_IMAGE_AS, L"圖片另存為..."); model->InsertSeparatorAt(2); model->AddItem(MENU_ID_PRINT, L"
列印"); } } // 處理點選事件 bool BrowserHandler::OnContextMenuCommand(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefContextMenuParams> params, int command_id, EventFlags event_flags) { // 複製圖片到剪下板 if (command_id == CLIENT_ID_COPY_IMAGE) { frame->Copy(); } else if (command_id == CLIENT_ID_SAVE_IMAGE_AS) { // 儲存圖片 frame->GetBrowser().get()->GetHost().get()->StartDownload(frame->GetURL()); } if (handle_delegate_) return handle_delegate_->OnContextMenuCommand(browser, frame, params, command_id, event_flags); else return false; }

 

轉載於:libcef3——自定義右鍵選單,複製圖片和圖片另存為_Go和分散式IM的部落格-CSDN部落格