📄 init.c
字号:
/********************************************************************** * CreateEnhMetaFileA (GDI32.@) */HDC WINAPI CreateEnhMetaFileA( HDC hdc, /* [in] optional reference DC */ LPCSTR filename, /* [in] optional filename for disk metafiles */ const RECT *rect, /* [in] optional bounding rectangle */ LPCSTR description /* [in] optional description */ ){ LPWSTR filenameW = NULL; LPWSTR descriptionW = NULL; HDC hReturnDC; DWORD len1, len2, total; if(filename) { total = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 ); filenameW = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) ); MultiByteToWideChar( CP_ACP, 0, filename, -1, filenameW, total ); } if(description) { len1 = strlen(description); len2 = strlen(description + len1 + 1); total = MultiByteToWideChar( CP_ACP, 0, description, len1 + len2 + 3, NULL, 0 ); descriptionW = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) ); MultiByteToWideChar( CP_ACP, 0, description, len1 + len2 + 3, descriptionW, total ); } hReturnDC = CreateEnhMetaFileW(hdc, filenameW, rect, descriptionW); if(filenameW) HeapFree( GetProcessHeap(), 0, filenameW ); if(descriptionW) HeapFree( GetProcessHeap(), 0, descriptionW ); return hReturnDC;}/********************************************************************** * CreateEnhMetaFileW (GDI32.@) */HDC WINAPI CreateEnhMetaFileW( HDC hdc, /* [in] optional reference DC */ LPCWSTR filename, /* [in] optional filename for disk metafiles */ const RECT* rect, /* [in] optional bounding rectangle */ LPCWSTR description /* [in] optional description */ ){ static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0}; HDC ret; DC *dc; HDC hRefDC = hdc ? hdc : CreateDCW(displayW,NULL,NULL,NULL); /* If no ref, use current display */ EMFDRV_PDEVICE *physDev; HANDLE hFile; DWORD size = 0, length = 0; TRACE("%s\n", debugstr_w(filename) ); if (!(dc = DC_AllocDC( &EMFDRV_Funcs, ENHMETAFILE_DC_MAGIC ))) return 0; physDev = (EMFDRV_PDEVICE *)HeapAlloc(GetProcessHeap(),0,sizeof(*physDev)); if (!physDev) { GDI_FreeObject( dc->hSelf, dc ); return 0; } dc->physDev = (PHYSDEV)physDev; physDev->hdc = dc->hSelf; physDev->dc = dc; if(description) { /* App name\0Title\0\0 */ length = lstrlenW(description); length += lstrlenW(description + length + 1); length += 3; length *= 2; } size = sizeof(ENHMETAHEADER) + (length + 3) / 4 * 4; if (!(physDev->emh = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size))) { HeapFree( GetProcessHeap(), 0, physDev ); GDI_FreeObject( dc->hSelf, dc ); return 0; } physDev->nextHandle = 1; physDev->hFile = 0; physDev->horzres = GetDeviceCaps(hRefDC, HORZRES); physDev->vertres = GetDeviceCaps(hRefDC, VERTRES); physDev->logpixelsx = GetDeviceCaps(hRefDC, LOGPIXELSX); physDev->logpixelsy = GetDeviceCaps(hRefDC, LOGPIXELSY); physDev->horzsize = GetDeviceCaps(hRefDC, HORZSIZE); physDev->vertsize = GetDeviceCaps(hRefDC, VERTSIZE); physDev->bitspixel = GetDeviceCaps(hRefDC, BITSPIXEL); physDev->textcaps = GetDeviceCaps(hRefDC, TEXTCAPS); physDev->rastercaps = GetDeviceCaps(hRefDC, RASTERCAPS); physDev->technology = GetDeviceCaps(hRefDC, TECHNOLOGY); physDev->planes = GetDeviceCaps(hRefDC, PLANES); physDev->emh->iType = EMR_HEADER; physDev->emh->nSize = size; physDev->emh->rclBounds.left = physDev->emh->rclBounds.top = 0; physDev->emh->rclBounds.right = physDev->emh->rclBounds.bottom = -1; if(rect) { physDev->emh->rclFrame.left = rect->left; physDev->emh->rclFrame.top = rect->top; physDev->emh->rclFrame.right = rect->right; physDev->emh->rclFrame.bottom = rect->bottom; } else { /* Set this to {0,0 - -1,-1} and update it at the end */ physDev->emh->rclFrame.left = physDev->emh->rclFrame.top = 0; physDev->emh->rclFrame.right = physDev->emh->rclFrame.bottom = -1; } physDev->emh->dSignature = ENHMETA_SIGNATURE; physDev->emh->nVersion = 0x10000; physDev->emh->nBytes = physDev->emh->nSize; physDev->emh->nRecords = 1; physDev->emh->nHandles = 1; physDev->emh->sReserved = 0; /* According to docs, this is reserved and must be 0 */ physDev->emh->nDescription = length / 2; physDev->emh->offDescription = length ? sizeof(ENHMETAHEADER) : 0; physDev->emh->nPalEntries = 0; /* I guess this should start at 0 */ /* Size in pixels */ physDev->emh->szlDevice.cx = physDev->horzres; physDev->emh->szlDevice.cy = physDev->vertres; /* Size in millimeters */ physDev->emh->szlMillimeters.cx = physDev->horzsize; physDev->emh->szlMillimeters.cy = physDev->vertsize; /* Size in micrometers */ physDev->emh->szlMicrometers.cx = physDev->horzsize * 1000; physDev->emh->szlMicrometers.cy = physDev->vertsize * 1000; memcpy((char *)physDev->emh + sizeof(ENHMETAHEADER), description, length); if (filename) /* disk based metafile */ { if ((hFile = CreateFileW(filename, GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { EMFDRV_DeleteDC( dc->physDev ); return 0; } if (!WriteFile( hFile, (LPSTR)physDev->emh, size, NULL, NULL )) { EMFDRV_DeleteDC( dc->physDev ); return 0; } physDev->hFile = hFile; } TRACE("returning %p\n", dc->hSelf); ret = dc->hSelf; GDI_ReleaseObj( dc->hSelf ); if( !hdc ) DeleteDC( hRefDC ); return ret;}/****************************************************************** * CloseEnhMetaFile (GDI32.@) */HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */{ HENHMETAFILE hmf; EMFDRV_PDEVICE *physDev; DC *dc; EMREOF emr; HANDLE hMapping = 0; TRACE("(%p)\n", hdc ); if (!(dc = (DC *) GDI_GetObjPtr( hdc, ENHMETAFILE_DC_MAGIC ))) return 0; physDev = (EMFDRV_PDEVICE *)dc->physDev; emr.emr.iType = EMR_EOF; emr.emr.nSize = sizeof(emr); emr.nPalEntries = 0; emr.offPalEntries = 0; emr.nSizeLast = emr.emr.nSize; EMFDRV_WriteRecord( dc->physDev, &emr.emr ); /* Update rclFrame if not initialized in CreateEnhMetaFile */ if(physDev->emh->rclFrame.left > physDev->emh->rclFrame.right) { physDev->emh->rclFrame.left = physDev->emh->rclBounds.left * physDev->emh->szlMillimeters.cx * 100 / physDev->emh->szlDevice.cx; physDev->emh->rclFrame.top = physDev->emh->rclBounds.top * physDev->emh->szlMillimeters.cy * 100 / physDev->emh->szlDevice.cy; physDev->emh->rclFrame.right = physDev->emh->rclBounds.right * physDev->emh->szlMillimeters.cx * 100 / physDev->emh->szlDevice.cx; physDev->emh->rclFrame.bottom = physDev->emh->rclBounds.bottom * physDev->emh->szlMillimeters.cy * 100 / physDev->emh->szlDevice.cy; } if (physDev->hFile) /* disk based metafile */ { if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0) { CloseHandle( physDev->hFile ); EMFDRV_DeleteDC( dc->physDev ); return 0; } if (!WriteFile(physDev->hFile, (LPSTR)physDev->emh, sizeof(*physDev->emh), NULL, NULL)) { CloseHandle( physDev->hFile ); EMFDRV_DeleteDC( dc->physDev ); return 0; } HeapFree( GetProcessHeap(), 0, physDev->emh ); hMapping = CreateFileMappingA(physDev->hFile, NULL, PAGE_READONLY, 0, 0, NULL); TRACE("hMapping = %p\n", hMapping ); physDev->emh = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); TRACE("view = %p\n", physDev->emh ); CloseHandle( hMapping ); CloseHandle( physDev->hFile ); } hmf = EMF_Create_HENHMETAFILE( physDev->emh, (physDev->hFile != 0) ); physDev->emh = NULL; /* So it won't be deleted */ EMFDRV_DeleteDC( dc->physDev ); return hmf;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -