/****************************************************************** * CopyMetaFile (GDI.151) */ HMETAFILE16 WINAPI CopyMetaFile16( HMETAFILE16 hSrcMetaFile, LPCSTR lpFilename) { HMETAFILE hmf = create_metafile32( hSrcMetaFile ); HMETAFILE hmf2 = CopyMetaFileA( hmf, lpFilename ); DeleteMetaFile( hmf ); return create_metafile16( hmf2 ); }
static void test_marshal_HMETAFILE(void) { USER_MARSHAL_CB umcb; MIDL_STUB_MESSAGE stub_msg; RPC_MESSAGE rpc_msg; unsigned char *buffer; ULONG size; HMETAFILE hmf; HMETAFILE hmf2 = NULL; unsigned char *wirehmf; hmf = create_mf(); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE); size = HMETAFILE_UserSize(&umcb.Flags, 0, &hmf); ok(size > 20, "size should be at least 20 bytes, not %d\n", size); buffer = HeapAlloc(GetProcessHeap(), 0, size); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); HMETAFILE_UserMarshal(&umcb.Flags, buffer, &hmf); wirehmf = buffer; ok(*(DWORD *)wirehmf == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmf); wirehmf += sizeof(DWORD); ok(*(DWORD *)wirehmf == (DWORD)(DWORD_PTR)hmf, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmf); wirehmf += sizeof(DWORD); ok(*(DWORD *)wirehmf == (size - 0x10), "wirestgm + 0x8 should be size - 0x10 instead of 0x%08x\n", *(DWORD *)wirehmf); wirehmf += sizeof(DWORD); ok(*(DWORD *)wirehmf == (size - 0x10), "wirestgm + 0xc should be size - 0x10 instead of 0x%08x\n", *(DWORD *)wirehmf); wirehmf += sizeof(DWORD); ok(*(WORD *)wirehmf == 1, "wirestgm + 0x10 should be 1 instead of 0x%08x\n", *(DWORD *)wirehmf); wirehmf += sizeof(DWORD); /* ... rest of data not tested - refer to tests for GetMetaFileBits * at this point */ init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); HMETAFILE_UserUnmarshal(&umcb.Flags, buffer, &hmf2); ok(hmf2 != NULL, "HMETAFILE didn't unmarshal\n"); HeapFree(GetProcessHeap(), 0, buffer); HMETAFILE_UserFree(&umcb.Flags, &hmf2); DeleteMetaFile(hmf); /* test NULL emf */ hmf = NULL; size = HMETAFILE_UserSize(&umcb.Flags, 0, &hmf); ok(size == 8, "size should be 8 bytes, not %d\n", size); buffer = HeapAlloc(GetProcessHeap(), 0, size); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); HMETAFILE_UserMarshal(&umcb.Flags, buffer, &hmf); wirehmf = buffer; ok(*(DWORD *)wirehmf == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmf); wirehmf += sizeof(DWORD); ok(*(DWORD *)wirehmf == (DWORD)(DWORD_PTR)hmf, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmf); wirehmf += sizeof(DWORD); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); HMETAFILE_UserUnmarshal(&umcb.Flags, buffer, &hmf2); ok(hmf2 == NULL, "NULL HMETAFILE didn't unmarshal\n"); HeapFree(GetProcessHeap(), 0, buffer); HMETAFILE_UserFree(&umcb.Flags, &hmf2); }
/****************************************************************** * PlayMetaFile (GDI.123) * */ BOOL16 WINAPI PlayMetaFile16( HDC16 hdc, HMETAFILE16 hmf16 ) { HMETAFILE hmf = create_metafile32( hmf16 ); BOOL ret = PlayMetaFile( HDC_32(hdc), hmf ); DeleteMetaFile( hmf ); return ret; }
CMFCDCView::~CMFCDCView() { if (m_hMetaFile) { //5 删除MetaFile DeleteMetaFile(m_hMetaFile); } }
wxMetafileRefData::~wxMetafileRefData() { if (m_metafile) { DeleteMetaFile((HMETAFILE) m_metafile); m_metafile = 0; } }
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HMETAFILE hmf ; static int cxClient, cyClient ; HBRUSH hBrush ; HDC hdc, hdcMeta ; int x, y ; PAINTSTRUCT ps ; switch (message) { case WM_CREATE: hdcMeta = CreateMetaFile (NULL) ; hBrush = CreateSolidBrush (RGB (0, 0, 255)) ; Rectangle (hdcMeta, 0, 0, 100, 100) ; MoveToEx (hdcMeta, 0, 0, NULL) ; LineTo (hdcMeta, 100, 100) ; MoveToEx (hdcMeta, 0, 100, NULL) ; LineTo (hdcMeta, 100, 0) ; SelectObject (hdcMeta, hBrush) ; Ellipse (hdcMeta, 20, 20, 80, 80) ; hmf = CloseMetaFile (hdcMeta) ; DeleteObject (hBrush) ; return 0 ; case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; SetMapMode (hdc, MM_ANISOTROPIC) ; SetWindowExtEx (hdc, 1000, 1000, NULL) ; SetViewportExtEx (hdc, cxClient, cyClient, NULL) ; for (x = 0 ; x < 10 ; x++) for (y = 0 ; y < 10 ; y++) { SetWindowOrgEx (hdc, -100 * x, -100 * y, NULL) ; PlayMetaFile (hdc, hmf) ; } EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: DeleteMetaFile (hmf) ; PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
/* * clipboard_free_data - クリップボード形式毎のメモリの解放 */ BOOL clipboard_free_data(TCHAR *format_name, HANDLE data) { BOOL ret = FALSE; BYTE *mem; if (data == NULL) { return TRUE; } switch (clipboard_get_format(0, format_name)) { case CF_PALETTE: // パレット ret = DeleteObject((HGDIOBJ)data); break; case CF_DSPBITMAP: case CF_BITMAP: // ビットマップ ret = DeleteObject((HGDIOBJ)data); break; case CF_OWNERDISPLAY: break; case CF_DSPMETAFILEPICT: case CF_METAFILEPICT: // メタファイル if ((mem = GlobalLock(data)) != NULL) { DeleteMetaFile(((METAFILEPICT *)mem)->hMF); GlobalUnlock(data); } if (GlobalFree((HGLOBAL)data) == NULL) { ret = TRUE; } break; case CF_DSPENHMETAFILE: case CF_ENHMETAFILE: // 拡張メタファイル ret = DeleteEnhMetaFile((HENHMETAFILE)data); break; default: // その他 if (GlobalFree((HGLOBAL)data) == NULL) { ret = TRUE; } break; } return ret; }
static void cdkillcanvas(cdCtxCanvas *ctxcanvas) { HMETAFILE hmf; cdwKillCanvas(ctxcanvas); hmf = CloseMetaFile(ctxcanvas->hDC); wmfMakePlaceableMetafile(hmf, ctxcanvas->filename, ctxcanvas->canvas->w, ctxcanvas->canvas->h); DeleteMetaFile(hmf); free(ctxcanvas->filename); memset(ctxcanvas, 0, sizeof(cdCtxCanvas)); free(ctxcanvas); }
int GPdestroywidget (Gwidget_t *widget) { HENHMETAFILE mfile; if (WPU->mode == 1) { mfile = CloseEnhMetaFile (GC); OpenClipboard (NULL); EmptyClipboard (); SetClipboardData (CF_ENHMETAFILE, mfile); CloseClipboard (); DeleteMetaFile (mfile); } else { EndPage (GC); EndDoc (GC); } return 0; }
/****************************************************************** * create_metafile16 * * Create a 16-bit metafile from a 32-bit one. The 32-bit one is deleted. */ static HMETAFILE16 create_metafile16( HMETAFILE hmf ) { UINT size; HMETAFILE16 hmf16; if (!hmf) return 0; size = GetMetaFileBitsEx( hmf, 0, NULL ); hmf16 = GlobalAlloc16( GMEM_MOVEABLE, size ); if (hmf16) { void *buffer = GlobalLock16( hmf16 ); GetMetaFileBitsEx( hmf, size, buffer ); GlobalUnlock16( hmf16 ); } DeleteMetaFile( hmf ); return hmf16; }
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { /* Definiciones de variables locales */ WNDCLASS wndclass; MSG msg; BOOL flag; /* Obtenemos el fichero del metafile */ lstrcpy (path, lpszCmdLine); /* Obtenemos el MetaFile */ hMF = GetMetaFile (path); /* Obtenemos el handle de la aplicaci�n */ hInstGlobal = hInstance; if (!hPrevInstance) { wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = (WNDPROC) ProcVentApp; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (hInstance, szAppName); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = COLOR_APPWORKSPACE + 1; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; RegisterClass (&wndclass); } /* Estamos en el bucle de mensaje hasta que se escoja 'Salir' */ while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } /* Eliminamos el MetaFile */ DeleteMetaFile (hMF); return (msg.wParam); }
void CWindowsMetaFile::Reset(void) { m_pszFileName = NULL; m_hInstance = NULL; m_pszResource = NULL; m_pszType = NULL; m_fHeaderValid = FALSE; if (m_hMetaFile != NULL) { DeleteMetaFile(m_hMetaFile); m_hMetaFile = NULL; } m_fMetaFileValid = FALSE; }
STDAPI_(void) OleUIMetafilePictIconFree(HGLOBAL hMetaPict) { LPMETAFILEPICT pMF; if (NULL == hMetaPict) return; pMF = (LPMETAFILEPICT)GlobalLock(hMetaPict); if (NULL != pMF) { if (NULL != pMF->hMF) DeleteMetaFile(pMF->hMF); } GlobalUnlock(hMetaPict); GlobalFree(hMetaPict); return; }
static BOOL ClipboardReadMetafile(HANDLE hFile, DWORD dwOffset, DWORD dwLength) { HMETAFILE hMf; HGLOBAL hData; LPVOID lpData; hData = ClipboardReadMemoryBlock(hFile, dwOffset, dwLength); if (!hData) { return FALSE; } lpData = GlobalLock(hData); if (!lpData) { GlobalFree(hData); return FALSE; } hMf = SetMetaFileBitsEx(dwLength, lpData); GlobalUnlock(hData); GlobalFree(hData); if (!hMf) { SetLastError(ERROR_OUTOFMEMORY); return FALSE; } if (!SetClipboardData(CF_METAFILEPICT, hMf)) { DeleteMetaFile(hMf); return FALSE; } return TRUE; }
/* * clipboard_data_to_file - データをファイルに保存 */ BOOL clipboard_data_to_file(DATA_INFO *di, const TCHAR *file_name, const int filter_index, TCHAR *err_str) { HMETAFILE hMeta; HENHMETAFILE enh_meta; BYTE *tmp; DWORD size; if (di->data == NULL) { if (file_write_buf(file_name, NULL, 0, err_str) == FALSE) { return FALSE; } return TRUE; } switch (di->format) { case CF_OWNERDISPLAY: return FALSE; case CF_DSPMETAFILEPICT: case CF_METAFILEPICT: // メタファイル if ((tmp = GlobalLock(di->data)) == NULL) { message_get_error(GetLastError(), err_str); return FALSE; } if ((hMeta = CopyMetaFile(((METAFILEPICT *)tmp)->hMF, file_name)) == NULL) { message_get_error(GetLastError(), err_str); GlobalUnlock(di->data); return FALSE; } DeleteMetaFile(hMeta); GlobalUnlock(di->data); break; case CF_DSPENHMETAFILE: case CF_ENHMETAFILE: // 拡張メタファイル if ((enh_meta = CopyEnhMetaFile(di->data, file_name)) == NULL) { message_get_error(GetLastError(), err_str); return FALSE; } DeleteEnhMetaFile(enh_meta); break; default: // その他 // データをバイト列に変換 if ((tmp = clipboard_data_to_bytes(di, &size)) == NULL) { message_get_error(GetLastError(), err_str); return FALSE; } // ファイルに書き込む if (file_write_buf(file_name, tmp, di->size, err_str) == FALSE) { mem_free(&tmp); return FALSE; } mem_free(&tmp); break; } return TRUE; }
static HENHMETAFILE ReadEnhMetaFile(const char *path,long *width, long *height) { #pragma pack( push ) #pragma pack( 2 ) typedef struct { DWORD dwKey; WORD hmf; SMALL_RECT bbox; WORD wInch; DWORD dwReserved; WORD wCheckSum; } APMHEADER, *PAPMHEADER; #pragma pack( pop ) DWORD dwSize; ENHMETAHEADER emfh; HANDLE hFile; HDC hDC; HENHMETAFILE hTemp; LPBYTE pBits; METAFILEPICT mp; HMETAFILE hOld; *width=512; *height=512; hTemp=GetEnhMetaFile(path); #if defined(MAGICKCORE_HAVE__WFOPEN) if (hTemp == (HENHMETAFILE) NULL) { wchar_t *unicode_path; unicode_path=ConvertUTF8ToUTF16(path); if (unicode_path != (wchar_t *) NULL) { hTemp=GetEnhMetaFileW(unicode_path); unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path); } } #endif if (hTemp != (HENHMETAFILE) NULL) { /* Enhanced metafile. */ GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh); *width=emfh.rclFrame.right-emfh.rclFrame.left; *height=emfh.rclFrame.bottom-emfh.rclFrame.top; return(hTemp); } hOld=GetMetaFile(path); if (hOld != (HMETAFILE) NULL) { /* 16bit windows metafile. */ dwSize=GetMetaFileBitsEx(hOld,0,NULL); if (dwSize == 0) { DeleteMetaFile(hOld); return((HENHMETAFILE) NULL); } pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits)); if (pBits == (LPBYTE) NULL) { DeleteMetaFile(hOld); return((HENHMETAFILE) NULL); } if (GetMetaFileBitsEx(hOld,dwSize,pBits) == 0) { pBits=(BYTE *) DestroyString((char *) pBits); DeleteMetaFile(hOld); return((HENHMETAFILE) NULL); } /* Make an enhanced metafile from the windows metafile. */ mp.mm=MM_ANISOTROPIC; mp.xExt=1000; mp.yExt=1000; mp.hMF=NULL; hDC=GetDC(NULL); hTemp=SetWinMetaFileBits(dwSize,pBits,hDC,&mp); ReleaseDC(NULL,hDC); DeleteMetaFile(hOld); pBits=(BYTE *) DestroyString((char *) pBits); GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh); *width=emfh.rclFrame.right-emfh.rclFrame.left; *height=emfh.rclFrame.bottom-emfh.rclFrame.top; return(hTemp); } /* Aldus Placeable metafile. */ hFile=CreateFile(path,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return(NULL); dwSize=GetFileSize(hFile,NULL); pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits)); ReadFile(hFile,pBits,dwSize,&dwSize,NULL); CloseHandle(hFile); if (((PAPMHEADER) pBits)->dwKey != 0x9ac6cdd7l) { pBits=(BYTE *) DestroyString((char *) pBits); return((HENHMETAFILE) NULL); } /* Make an enhanced metafile from the placable metafile. */ mp.mm=MM_ANISOTROPIC; mp.xExt=((PAPMHEADER) pBits)->bbox.Right-((PAPMHEADER) pBits)->bbox.Left; *width=mp.xExt; mp.xExt=(mp.xExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch); mp.yExt=((PAPMHEADER)pBits)->bbox.Bottom-((PAPMHEADER) pBits)->bbox.Top; *height=mp.yExt; mp.yExt=(mp.yExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch); mp.hMF=NULL; hDC=GetDC(NULL); hTemp=SetWinMetaFileBits(dwSize,&(pBits[sizeof(APMHEADER)]),hDC,&mp); ReleaseDC(NULL,hDC); pBits=(BYTE *) DestroyString((char *) pBits); return(hTemp); }
static void test_marshal_HMETAFILEPICT(void) { USER_MARSHAL_CB umcb; MIDL_STUB_MESSAGE stub_msg; RPC_MESSAGE rpc_msg; unsigned char *buffer, *buffer_end; ULONG size; HMETAFILEPICT hmfp; HMETAFILEPICT hmfp2 = NULL; METAFILEPICT *pmfp; unsigned char *wirehmfp; hmfp = GlobalAlloc(GMEM_MOVEABLE, sizeof(*pmfp)); pmfp = GlobalLock(hmfp); pmfp->mm = MM_ISOTROPIC; pmfp->xExt = 1; pmfp->yExt = 2; pmfp->hMF = create_mf(); GlobalUnlock(hmfp); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE); size = HMETAFILEPICT_UserSize(&umcb.Flags, 0, &hmfp); ok(size > 20, "size should be at least 20 bytes, not %d\n", size); trace("size is %d\n", size); buffer = HeapAlloc(GetProcessHeap(), 0, size); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); buffer_end = HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer, &hmfp); wirehmfp = buffer; ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)hmfp, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); ok(*(DWORD *)wirehmfp == MM_ISOTROPIC, "wirestgm + 0x8 should be MM_ISOTROPIC instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); ok(*(DWORD *)wirehmfp == 1, "wirestgm + 0xc should be 1 instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); ok(*(DWORD *)wirehmfp == 2, "wirestgm + 0x10 should be 2 instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); ok(*(DWORD *)wirehmfp == USER_MARSHAL_PTR_PREFIX, "wirestgm + 0x14 should be \"User\" instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x18 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); pmfp = GlobalLock(hmfp); ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)pmfp->hMF, "wirestgm + 0x1c should be pmfp->hMF instead of 0x%08x\n", *(DWORD *)wirehmfp); GlobalUnlock(hmfp); wirehmfp += sizeof(DWORD); /* Note use (buffer_end - buffer) instead of size here, because size is an * overestimate with native */ ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x28), "wirestgm + 0x20 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x28), "wirestgm + 0x24 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); ok(*(WORD *)wirehmfp == 1, "wirehmfp + 0x28 should be 1 instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); /* ... rest of data not tested - refer to tests for GetMetaFileBits * at this point */ init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer, &hmfp2); ok(hmfp2 != NULL, "HMETAFILEPICT didn't unmarshal\n"); HeapFree(GetProcessHeap(), 0, buffer); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE); HMETAFILEPICT_UserFree(&umcb.Flags, &hmfp2); pmfp = GlobalLock(hmfp); DeleteMetaFile(pmfp->hMF); GlobalUnlock(hmfp); GlobalFree(hmfp); /* test NULL emf */ hmfp = NULL; init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE); size = HMETAFILEPICT_UserSize(&umcb.Flags, 0, &hmfp); ok(size == 8, "size should be 8 bytes, not %d\n", size); buffer = HeapAlloc(GetProcessHeap(), 0, size); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer, &hmfp); wirehmfp = buffer; ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)hmfp, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmfp); wirehmfp += sizeof(DWORD); hmfp2 = NULL; init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer, &hmfp2); ok(hmfp2 == NULL, "NULL HMETAFILE didn't unmarshal\n"); HeapFree(GetProcessHeap(), 0, buffer); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE); HMETAFILEPICT_UserFree(&umcb.Flags, &hmfp2); }
BOOL COleServerItem::GetMetafileData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE)); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); ASSERT(lpStgMedium->tymed == TYMED_NULL); // GetDataHere not valid ASSERT(lpStgMedium->pUnkForRelease == NULL); // medium must be TYMED_MFPICT -- cannot fill in existing HGLOBAL if (!(lpFormatEtc->tymed & TYMED_MFPICT) || lpStgMedium->hGlobal != NULL) return FALSE; // create appropriate memory metafile DC CMetaFileDC dc; if (!dc.Create()) return FALSE; // create attribute DC according to lpFormatEtc->ptd HDC hAttribDC = _AfxOleCreateDC(lpFormatEtc->ptd); if (hAttribDC == NULL) return FALSE; dc.SetAttribDC(hAttribDC); // Paint directly into the metafile. CSize size(0, 0); BOOL bResult = OnDrawEx(&dc, (DVASPECT)lpFormatEtc->dwAspect, size); // attribute DC is no longer necessary dc.SetAttribDC(NULL); ::DeleteDC(hAttribDC); if (!bResult) { #ifdef _DEBUG if (afxTraceFlags & traceOle) TRACE0("calling COleServerItem::OnDrawEx()failed.\n"); #endif return FALSE; } HMETAFILE hMF = dc.Close(); if (hMF == NULL) return FALSE; HGLOBAL hPict; if ((hPict = ::GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, sizeof(METAFILEPICT))) == NULL) { DeleteMetaFile(hMF); return FALSE; } LPMETAFILEPICT lpPict; if ((lpPict = (LPMETAFILEPICT)::GlobalLock(hPict)) == NULL) { DeleteMetaFile(hMF); ::GlobalFree(hPict); return FALSE; } // set the metafile size lpPict->mm = MM_ANISOTROPIC; lpPict->hMF = hMF; if (size.cx == 0 && size.cy == 0 && !OnGetExtent((DVASPECT)lpFormatEtc->dwAspect, size)) { TRACE0("Warning: OnGetExtent failed during OnDrawEx --\n"); TRACE0("\tpresentation metafile may be badly formed!\n"); } lpPict->xExt = size.cx; lpPict->yExt = size.cy; // HIMETRIC height if (lpPict->yExt < 0) { TRACE0("Warning: HIMETRIC natural size is negative.\n"); lpPict->yExt = -lpPict->yExt; // backward compatibility fix } #ifdef _DEBUG if (lpPict->xExt == 0 || lpPict->yExt == 0) { // usually the natural extent is set to something interesting TRACE0("Warning: COleServerItem has no natural size --\n"); TRACE0("\twill not work with some apps like MS Write.\n"); } #endif // return the medium with the hGlobal to the METAFILEPICT ::GlobalUnlock(hPict); lpStgMedium->hGlobal = hPict; lpStgMedium->tymed = TYMED_MFPICT; return TRUE; }
BOOL __stdcall pvdFileOpen2(void *pContext, const wchar_t *pFileName, INT64 lFileSize, const BYTE *pBuf, UINT32 lBuf, pvdInfoImage2 *pImageInfo) { _ASSERTE(pImageInfo->cbSize >= sizeof(pvdInfoImage2)); WmfContext *pw = (WmfContext*)CALLOC(sizeof(WmfContext)); if (!pw) { pImageInfo->nErrNumber = PWE_NOT_ENOUGH_MEMORY; return FALSE; } //pw->h = GetEnhMetaFile ( pFileName+4 ); const wchar_t *p = GetExtension(pFileName); if (!p) { pImageInfo->nErrNumber = PWE_NO_EXTENSION; return FALSE; } pImageInfo->nErrNumber = PWE_WIN32_ERROR; // заранее //if (pImageInfo->PreferredSize.cx && pImageInfo->PreferredSize.cy) { // pw->PreferredSize = pImageInfo->PreferredSize; //} else { pw->PreferredSize.cx = 1000; pw->PreferredSize.cy = 1000; //} // First try to read it as an enhanced metafile // If it works, simply return the handle pw->h = SetEnhMetaFileBits(lBuf, pBuf); gnLastWin32Error = GetLastError(); if (!pw->h) { pw->h = GetEnhMetaFile( pFileName ); gnLastWin32Error = GetLastError(); } if (!pw->h) { HMETAFILE hOld; DWORD dwSize; LPBYTE pBits; METAFILEPICT mp; HDC hDC; if( (hOld = GetMetaFile( pFileName )) != NULL ) { // Ok, it is a 16bit windows metafile // How big are the bits? if( (dwSize = GetMetaFileBitsEx( hOld, 0, NULL )) == 0 ) { gnLastWin32Error = GetLastError(); DeleteMetaFile( hOld ); //MessageBox( hWndParent, "Failed to Get MetaFile Bits Size", "Error Reading MetaFile", MB_OK ); } else { // Allocate that much memory if( (pBits = (LPBYTE)CALLOC( dwSize )) == NULL ) { pImageInfo->nErrNumber = PWE_NOT_ENOUGH_MEMORY; gnLastWin32Error = GetLastError(); DeleteMetaFile( hOld ); //MessageBox( hWndParent, "Failed to Allocate Memory for Metafile Bits", "Error Reading MetaFile", MB_OK ); //return NULL; } else { // Get the metafile bits if( GetMetaFileBitsEx( hOld, dwSize, pBits ) == 0 ) { gnLastWin32Error = GetLastError(); FREE( pBits ); DeleteMetaFile( hOld ); //MessageBox( hWndParent, "Failed to Get MetaFile Bits", "Error Reading MetaFile", MB_OK ); //return NULL; } else { // Fill out a METAFILEPICT structure mp.mm = MM_ANISOTROPIC; mp.xExt = 1000; mp.yExt = 1000; mp.hMF = NULL; // Get a reference DC hDC = GetDC( NULL ); // Make an enhanced metafile from the windows metafile pw->h = SetWinMetaFileBits( dwSize, pBits, hDC, &mp ); gnLastWin32Error = GetLastError(); // Clean up ReleaseDC( NULL, hDC ); DeleteMetaFile( hOld ); FREE( pBits ); } } } } } if (!pw->h) { DWORD dwSize = lBuf; LPBYTE pBits = (LPBYTE)pBuf; METAFILEPICT mp; HDC hDC; // Is it a placeable metafile? (check the key) if( ((PAPMHEADER)pBits)->dwKey != 0x9ac6cdd7l ) { // Not a metafile that we know how to recognise - bail out //MessageBox( hWndParent, "Not a Valid Metafile", szFileName, MB_OK ); //return NULL; pImageInfo->nErrNumber = PWE_NOT_VALID_METAFILE; } else { // Ok, its a placeable metafile // Fill out a METAFILEPICT structure mp.mm = MM_ANISOTROPIC; mp.xExt = ((PAPMHEADER)pBits)->bbox.Right - ((PAPMHEADER)pBits)->bbox.Left; mp.xExt = ( mp.xExt * 2540l ) / (DWORD)(((PAPMHEADER)pBits)->wInch); mp.yExt = ((PAPMHEADER)pBits)->bbox.Bottom - ((PAPMHEADER)pBits)->bbox.Top; mp.yExt = ( mp.yExt * 2540l ) / (DWORD)(((PAPMHEADER)pBits)->wInch); mp.hMF = NULL; // Get a reference DC hDC = GetDC( NULL ); // Create an enhanced metafile from the bits pw->h = SetWinMetaFileBits( dwSize, &(pBits[sizeof(APMHEADER)]), hDC, &mp ); gnLastWin32Error = GetLastError(); // Clean up ReleaseDC( NULL, hDC ); //free( pBits ); //if( hTemp == NULL ) // MessageBox( hWndParent, "Failed to Create MetaFile from Bits", "Error Reading MetaFile", MB_OK ); //return hTemp; } } //if (pw->h) { // //pw->hCompDC = CreateCompatibleDC(NULL); // pw->mfp.mm = MM_ISOTROPIC; // pw->mfp.xExt = pw->PreferredSize.cx; // pw->mfp.yExt = pw->PreferredSize.cy; // pw->h = (HENHMETAFILE)SetMetaFileBitsEx (lBuf, pBuf); // gnLastWin32Error = GetLastError(); // pw->h = SetWinMetaFileBits(lBuf, pBuf, NULL, NULL); //pw->hCompDC, &pw->mfp); // gnLastWin32Error = GetLastError(); //} if (!pw->h) { //gnLastWin32Error = GetLastError(); -- уже FREE(pw); return FALSE; } pw->AddRef(); _ASSERTE(pw->nRefCount == 1); ENHMETAHEADER emh = {0}; DWORD PixelsX, PixelsY, MMX, MMY; emh.nSize = sizeof(ENHMETAHEADER); if( GetEnhMetaFileHeader( pw->h, sizeof( ENHMETAHEADER ), &emh ) ) { // Get the characteristics of the output device HDC hDC = GetDC(NULL); PixelsX = GetDeviceCaps( hDC, HORZRES ); PixelsY = GetDeviceCaps( hDC, VERTRES ); MMX = GetDeviceCaps( hDC, HORZSIZE ) * 100; MMY = GetDeviceCaps( hDC, VERTSIZE ) * 100; ReleaseDC(NULL, hDC); // Calculate the rect in which to draw the metafile based on the // intended size and the current output device resolution // Remember that the intended size is given in 0.01mm units, so // convert those to device units on the target device //pw->PreferredSize.cx = (int)((float)(emh.rclFrame.right - emh.rclFrame.left) * PixelsX / (MMX)); //pw->PreferredSize.cy = (int)((float)(emh.rclFrame.bottom - emh.rclFrame.top) * PixelsY / (MMY)); pw->PreferredSize.cx = ip.MulDivI32((emh.rclFrame.right - emh.rclFrame.left), PixelsX, MMX); pw->PreferredSize.cy = ip.MulDivI32((emh.rclFrame.bottom - emh.rclFrame.top), PixelsY, MMY); _ASSERTE(pw->PreferredSize.cx>0 && pw->PreferredSize.cy>0); if (pw->PreferredSize.cx < 0) pw->PreferredSize.cx = -pw->PreferredSize.cx; if (pw->PreferredSize.cy < 0) pw->PreferredSize.cy = -pw->PreferredSize.cy; } pImageInfo->pImageContext = pw; pImageInfo->nPages = 1; pImageInfo->Flags = 0; pImageInfo->pFormatName = L"WMF"; pImageInfo->pCompression = NULL; pImageInfo->pComments = NULL; return TRUE; }
static HENHMETAFILE ReadEnhMetaFile(const char *szFileName,long *width, long *height) { #pragma pack( push, 2 ) typedef struct { DWORD dwKey; WORD hmf; SMALL_RECT bbox; WORD wInch; DWORD dwReserved; WORD wCheckSum; } APMHEADER, *PAPMHEADER; #pragma pack( pop ) DWORD dwSize; ENHMETAHEADER emfh; HANDLE hFile; HDC hDC; HENHMETAFILE hTemp; LPBYTE pBits; METAFILEPICT mp; HMETAFILE hOld; *width=512; *height=512; hTemp=GetEnhMetaFile(szFileName); if (hTemp != (HENHMETAFILE) NULL) { /* Enhanced metafile. */ GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh); *width=emfh.rclFrame.right-emfh.rclFrame.left; *height=emfh.rclFrame.bottom-emfh.rclFrame.top; return(hTemp); } hOld=GetMetaFile(szFileName); if (hOld != (HMETAFILE) NULL) { /* 16bit windows metafile. */ dwSize=GetMetaFileBitsEx(hOld,0,NULL); if (dwSize == 0) { DeleteMetaFile(hOld); return((HENHMETAFILE) NULL); } pBits=MagickAllocateMemory(LPBYTE,dwSize); if (pBits == (LPBYTE) NULL) { DeleteMetaFile(hOld); return((HENHMETAFILE) NULL); } if (GetMetaFileBitsEx(hOld,dwSize,pBits) == 0) { MagickFreeMemory(pBits); DeleteMetaFile(hOld); return((HENHMETAFILE) NULL); } /* Make an enhanced metafile from the windows metafile. */ mp.mm=MM_ANISOTROPIC; mp.xExt=1000; mp.yExt=1000; mp.hMF=NULL; hDC=GetDC(NULL); hTemp=SetWinMetaFileBits(dwSize,pBits,hDC,&mp); ReleaseDC(NULL,hDC); DeleteMetaFile(hOld); MagickFreeMemory(pBits); GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh); *width=emfh.rclFrame.right-emfh.rclFrame.left; *height=emfh.rclFrame.bottom-emfh.rclFrame.top; return(hTemp); } /* Aldus Placeable metafile. */ hFile=CreateFile(szFileName,GENERIC_READ,0,NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL); if (hFile == INVALID_HANDLE_VALUE) return(NULL); dwSize=GetFileSize(hFile,NULL); pBits=MagickAllocateMemory(LPBYTE,dwSize); ReadFile(hFile,pBits,dwSize,&dwSize,NULL); CloseHandle(hFile); if (((PAPMHEADER) pBits)->dwKey != 0x9ac6cdd7l) { MagickFreeMemory(pBits); return((HENHMETAFILE) NULL); } /* Make an enhanced metafile from the placable metafile. */ mp.mm=MM_ANISOTROPIC; mp.xExt=((PAPMHEADER) pBits)->bbox.Right-((PAPMHEADER) pBits)->bbox.Left; *width=mp.xExt; mp.xExt=(mp.xExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch); mp.yExt=((PAPMHEADER)pBits)->bbox.Bottom-((PAPMHEADER) pBits)->bbox.Top; *height=mp.yExt; mp.yExt=(mp.yExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch); mp.hMF=NULL; hDC=GetDC(NULL); hTemp=SetWinMetaFileBits(dwSize,&(pBits[sizeof(APMHEADER)]),hDC,&mp); ReleaseDC(NULL,hDC); MagickFreeMemory(pBits); return(hTemp); }