// “另存为”菜单 void CMainWindow::OnMenu_SaveAs(TNotifyUI& msg) { if (msg.pSender != m_pSendEdit && msg.pSender != m_pRecvEdit) return; ITextServices * pTextServices = ((CRichEditUI *)msg.pSender)->GetTextServices(); IImageOle * pImageOle = NULL; BOOL bRet = RichEdit_GetImageOle(pTextServices, m_ptRBtnDown, &pImageOle); pTextServices->Release(); if (!bRet || NULL == pImageOle) return; tstring strFileName; BSTR bstrFileName = NULL; HRESULT hr = pImageOle->GetFileName(&bstrFileName); if (SUCCEEDED(hr)) strFileName = bstrFileName; if (bstrFileName != NULL) ::SysFreeString(bstrFileName); LPCTSTR lpszDefExt; LPCTSTR lpszFileName = _T("未命名"); DWORD dwFlags = OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR|OFN_EXTENSIONDIFFERENT; LPCTSTR lpszFilter; HWND hWndParent = m_hWnd; GUID guid = {0}; hr = pImageOle->GetRawFormat(&guid); if (InlineIsEqualGUID(guid, Gdiplus::ImageFormatJPEG)) { lpszDefExt = _T(".jpg"); lpszFilter = _T("图像文件(*.jpg)\0*.jpg\0图像文件(*.bmp)\0*.bmp\0\0"); } else if (InlineIsEqualGUID(guid, Gdiplus::ImageFormatPNG)) { lpszDefExt = _T(".png"); lpszFilter = _T("图像文件(*.png)\0*.png\0\0"); } else if (InlineIsEqualGUID(guid, Gdiplus::ImageFormatGIF)) { lpszDefExt = _T(".gif"); lpszFilter = _T("图像文件(*.gif)\0*.gif\0图像文件(*.jpg)\0*.jpg\0图像文件(*.bmp)\0*.bmp\0\0"); } else { lpszDefExt = _T(".jpg"); lpszFilter = _T("图像文件(*.jpg)\0*.jpg\0图像文件(*.bmp)\0*.bmp\0\0"); } CFileDialogEx fileDlg; fileDlg.SetDefExt(lpszDefExt); fileDlg.SetFileName(lpszFileName); fileDlg.SetFlags(dwFlags); fileDlg.SetFilter(lpszFilter); fileDlg.SetParentWnd(m_hWnd); fileDlg.SetTitle(_T("保存图片")); if (fileDlg.ShowSaveFileDlg()) { tstring strSavePath = fileDlg.GetPathName(); tstring strExtName = _T(".") + ZYM::CPath::GetExtension(strSavePath.c_str()); GUID guid2 = GetFileTypeGuidByExtension(strExtName.c_str()); if (InlineIsEqualGUID(guid, guid2)) { CopyFile(strFileName.c_str(), strSavePath.c_str(), FALSE); } else { BSTR bstrSavePath = ::SysAllocString(strSavePath.c_str()); if (bstrSavePath != NULL) { pImageOle->SaveAsFile(bstrSavePath); ::SysFreeString(bstrSavePath); } } } if (pImageOle != NULL) pImageOle->Release(); }
bool ImageViewForm::Notify(ui::EventArgs* msg) { if (msg->Type == kEventClick) { std::wstring control_name = msg->pSender->GetName(); if (control_name == L"close_btn") { this->Close(); } else if (control_name == L"close_btn_max") { this->Close(); } else if (msg->pSender->GetName() == L"preimage_btn") { ImageViewManager::GetInstance()->ShowNextImageView(false); } else if (msg->pSender->GetName() == L"nextimage_btn") { ImageViewManager::GetInstance()->ShowNextImageView(true); } else if (control_name == L"normal_btn") { ui_image_view_->SetOriginalSize(); ShowImageScale(true); } else if (control_name == L"max_btn") { ::ShowWindow(m_hWnd, SW_MAXIMIZE); } else if (control_name == L"restore_btn") { ::ShowWindow(m_hWnd, SW_RESTORE); } else if (control_name == L"magnify_btn") { ui_image_view_->ScalePic(UiImageView::kMagnifyPic); ShowImageScale(true); } else if (control_name == L"reduce_btn") { ui_image_view_->ScalePic(UiImageView::kReducePic); ShowImageScale(true); } else if (control_name == L"rotate_btn") { ui_image_view_->RotatePic(UiImageView::kClockWise); } else if (msg->pSender->GetName() == L"save_btn") { if (!image_path_.empty()) { std::wstring extension; nbase::FilePathExtension(image_path_, extension); if (extension.empty()) { std::wstring mime_type; GetMimeType(image_path_, mime_type, extension); } nbase::Time::TimeStruct now = nbase::Time::Now().ToTimeStruct(true); std::wstring file_name = nbase::StringPrintf(L"IMG%04d%02d%02d_%02d%02d%02d", now.year(), now.month(), now.day_of_month(), now.hour(), now.minute(), now.second()); file_name += extension; std::wstring file_type = ui::MutiLanSupport::GetInstance()->GetStringViaID(L"STRING_PIC_FILE"); std::wstring info = nbase::StringPrintf(L"%s(*%s)", file_type.c_str(), extension.c_str()); CFileDialogEx* fileDlg = new CFileDialogEx(); std::wstring filter = L"*" + extension; std::map<LPCTSTR, LPCTSTR> filters; filters[info.c_str()] = filter.c_str(); fileDlg->SetFilter(filters); fileDlg->SetFileName(file_name.c_str()); fileDlg->SetParentWnd(m_hWnd); CFileDialogEx::FileDialogCallback2 callback2 = nbase::Bind(&ImageViewForm::SaveImageDlgCallback, this, std::placeholders::_1, std::placeholders::_2); fileDlg->AyncShowSaveFileDlg(callback2); } } } return true; }