cef右鍵儲存圖片
阿新 • • 發佈:2022-04-15
// 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; }