void wxEnhMetaFileDCImpl::Create(HDC hdcRef, const wxString& filename, int width, int height, const wxString& description) { m_width = width; m_height = height; RECT rect; RECT *pRect; if ( width && height ) { rect.top = rect.left = 0; rect.right = width; rect.bottom = height; // CreateEnhMetaFile() wants them in HIMETRIC PixelToHIMETRIC(&rect.right, &rect.bottom, hdcRef); pRect = ▭ } else { // GDI will try to find out the size for us (not recommended) pRect = (LPRECT)NULL; } m_hDC = (WXHDC)::CreateEnhMetaFile(hdcRef, GetMetaFileName(filename), pRect, description.wx_str()); if ( !m_hDC ) { wxLogLastError(wxT("CreateEnhMetaFile")); } }
bool wxMetafileDataObject::GetDataHere(void *buf) const { METAFILEPICT *mfpict = (METAFILEPICT *)buf; const wxMetafile& mf = GetMetafile(); wxCHECK_MSG( mf.GetHMETAFILE(), false, wxT("copying invalid metafile") ); // doesn't seem to work with any other mapping mode... mfpict->mm = MM_ANISOTROPIC; //mf.GetWindowsMappingMode(); mfpict->xExt = mf.GetWidth(); mfpict->yExt = mf.GetHeight(); // transform the picture size to HIMETRIC units (0.01mm) - as we don't know // what DC the picture will be rendered to, use the default display one PixelToHIMETRIC(&mfpict->xExt, &mfpict->yExt); mfpict->hMF = CopyMetaFile((HMETAFILE)mf.GetHMETAFILE(), NULL); return true; }
void PixelToHIMETRIC(LONG *x, LONG *y) { PixelToHIMETRIC(x, y, ScreenHDC()); }
bool wxEnhMetaFileDataObject::GetDataHere(const wxDataFormat& format, void *buf) const { wxCHECK_MSG( m_metafile.Ok(), false, _T("copying invalid enh metafile") ); HENHMETAFILE hEMF = (HENHMETAFILE)m_metafile.GetHENHMETAFILE(); if ( format == wxDF_ENHMETAFILE ) { HENHMETAFILE hEMFCopy = ::CopyEnhMetaFile(hEMF, NULL); if ( !hEMFCopy ) { wxLogLastError(_T("CopyEnhMetaFile")); return false; } *(HENHMETAFILE *)buf = hEMFCopy; } else { wxASSERT_MSG( format == wxDF_METAFILE, _T("unsupported format") ); // convert to WMF ScreenHDC hdc; // first get the buffer size and alloc memory size_t size = ::GetWinMetaFileBits(hEMF, 0, NULL, MM_ANISOTROPIC, hdc); wxCHECK_MSG( size, false, _T("GetWinMetaFileBits() failed") ); BYTE *bits = (BYTE *)malloc(size); // then get the enh metafile bits if ( !::GetWinMetaFileBits(hEMF, size, bits, MM_ANISOTROPIC, hdc) ) { wxLogLastError(_T("GetWinMetaFileBits")); free(bits); return false; } // and finally convert them to the WMF HMETAFILE hMF = ::SetMetaFileBitsEx(size, bits); free(bits); if ( !hMF ) { wxLogLastError(_T("SetMetaFileBitsEx")); return false; } METAFILEPICT *mfpict = (METAFILEPICT *)buf; wxSize sizeMF = m_metafile.GetSize(); mfpict->hMF = hMF; mfpict->mm = MM_ANISOTROPIC; mfpict->xExt = sizeMF.x; mfpict->yExt = sizeMF.y; PixelToHIMETRIC(&mfpict->xExt, &mfpict->yExt); } return true; }