2013-10-11 75 views
0

我試圖創建一個這樣的增強型圖元:C++中的空文件創建增強型圖元結果

// 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 sm一樣。

可能是什麼問題?

P.S.另外,我將它稱爲混合模式應用程序,從c#到C++/cli對象。

編輯解決了奇怪編碼的問題,但創建的文件仍然是0字節長度。它如何解決?

回答

1

演員陣容是個問題,除非你真的需要,否則不要使用演員陣容。

令人驚訝的是,你從微軟網站上獲得了這種投射!你不得不懷疑MS僱用的人員的質量。但是在他們的代碼中,這不僅僅是多餘的。當你將它翻譯成你的代碼時,它是錯誤的。

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

_T宏是寫一個字符串文字將被解釋爲一個Unicode字符串或者根據您的編譯器設置的ANSI字符串的正式方法。

+0

@ tube-builder OK我很驚訝,這對我來說似乎是一個很好的解釋。 – john

+0

地獄,我真的很抱歉,沒有注意,現在文件被創建(仍然是空的)。非常感謝! –

+0

btw你有什麼想法爲什麼創建的文件仍然可以是0字節大小?我試圖找到這件事,但迄今爲止失敗了。沒有經驗與C++。 –