C ++创建增强型图元文件会产生一个空文件

时间:2013-10-11 07:12:45

标签: c++ .net mixed-mode metafile .emf

我试图像这样创建一个增强的图元文件:

// Obtain a handle to a reference device context.  

HDC hdcRef = GetDC(hwnd); 

// Determine the picture frame dimensions.  

int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE); 
int iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE); 
int iWidthPels = GetDeviceCaps(hdcRef, HORZRES); 
int iHeightPels = GetDeviceCaps(hdcRef, VERTRES); 

// Retrieve the coordinates of the client  
// rectangle, in pixels.  
RECT rect;
GetClientRect(hwnd, &rect); 

// Convert client coordinates to .01-mm units.  
// Use iWidthMM, iWidthPels, iHeightMM, and  
// iHeightPels to determine the number of  
// .01-millimeter units per pixel in the x-  
//  and y-directions.  

rect.left = (rect.left * iWidthMM * 100)/iWidthPels; 
rect.top = (rect.top * iHeightMM * 100)/iHeightPels; 
rect.right = (rect.right * iWidthMM * 100)/iWidthPels; 
rect.bottom = (rect.bottom * iHeightMM * 100)/iHeightPels; 


// Create the metafile device context.  

CreateEnhMetaFile(hdcRef, (LPTSTR)"temp.emf", &rect, NULL); 

// Release the reference device context.  

ReleaseDC(hwnd, hdcRef); 

取代码here

我到底得到的是一些0字节的非扩展文件,名称编码奇怪,像整灭攮sm。

可能是什么问题?

P.S。另外,我在混合模式应用程序中调用它,从c#到c ++ / cli对象。

编辑解决了奇怪编码的问题,但创建的文件仍然是0字节长度。怎么解决?

1 个答案:

答案 0 :(得分:1)

演员阵容是问题所在,除非你真的需要,否则不要使用演员表。

很棒,你从微软网站上获得了这个演员阵容!你不得不怀疑MS雇用的人的质量。但是在他们的代码中,这并不是多余的错误。将它翻译成代码时,这是错误的。

CreateEnhMetaFile(hdcRef, _T("temp.emf"), &rect, NULL);

_T宏是编写字符串文字的官方方式,根据您的编译器设置,它将被解释为Unicode字符串或ANSI字符串。

相关问题