Aracılığıyla paylaş


Gelişmiş Meta Dosyası Oluşturma

Bu bölüm, kullanıcı tarafından belirtilen bir dosya adı kullanılarak diskte depolanan gelişmiş bir meta dosyası oluşturmayı gösteren bir örnek içerir.

Örnek, uygulama penceresi için cihaz bağlamını referans cihaz bağlamı olarak kullanır. (Sistem, bu cihazın çözümleme verilerini gelişmiş meta dosyasının üst bilgisinde depolar.) Uygulama, GetDC işlevini çağırarak bu cihaz bağlamını tanımlayan bir tanıtıcı alır.

Örnek, resim çerçevesinin boyutlarını tanımlamak için uygulamanın istemci alanının boyutlarını kullanır. GetClientRect işlevi tarafından döndürülen dikdörtgen boyutlarını kullanarak, uygulama cihaz birimlerini 0,01 milimetre birimine dönüştürür ve dönüştürülen değerleri CreateEnhMetaFile işlevine geçirir.

Örnekte, kullanıcının yeni geliştirilmiş meta dosyasının dosya adını belirtmesini sağlayan Farklı Kaydet ortak iletişim kutusu görüntülenir. Sistem bu dosya adına üç karakterli .emf uzantısını ekler ve adı createEnhMetaFileişlevinegeçirir.

Örnek, gelişmiş meta dosyası üst bilgisine resmin metin açıklamasını da ekler. Bu açıklama, uygulamanın kaynak dosyasının dize tablosunda kaynak olarak belirtilir. Ancak, çalışan bir uygulamada, bu dize ortak bir iletişim kutusundaki özel denetimden veya yalnızca bu amaçla görüntülenen ayrı bir iletişim kutusundan alınır.

// Obtain a handle to a reference device context.  
 
hdcRef = GetDC(hWnd); 
 
// Determine the picture frame dimensions.  
// iWidthMM is the display width in millimeters.  
// iHeightMM is the display height in millimeters.  
// iWidthPels is the display width in pixels.  
// iHeightPels is the display height in pixels  
 
iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE); 
iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE); 
iWidthPels = GetDeviceCaps(hdcRef, HORZRES); 
iHeightPels = GetDeviceCaps(hdcRef, VERTRES); 
 
// Retrieve the coordinates of the client  
// rectangle, in pixels.  
 
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; 
 
// Load the filename filter from the string table.  
 
LoadString(hInst, IDS_FILTERSTRING, 
     (LPSTR)szFilter, sizeof(szFilter)); 
 
// Replace the '%' separators that are embedded  
// between the strings in the string-table entry  
// with '\0'.  
 
for (i=0; szFilter[i]!='\0'; i++) 
    if (szFilter[i] == '%') 
            szFilter[i] = '\0'; 
 
// Load the dialog title string from the table.  
 
LoadString(hInst, IDS_TITLESTRING, 
     (LPSTR)szTitle, sizeof(szTitle)); 
 
// Initialize the OPENFILENAME members.  
 
szFile[0] = '\0'; 
 
Ofn.lStructSize = sizeof(OPENFILENAME); 
Ofn.hwndOwner = hWnd; 
Ofn.lpstrFilter = szFilter; 
Ofn.lpstrFile= szFile; 
Ofn.nMaxFile = sizeof(szFile)/ sizeof(*szFile); 
Ofn.lpstrFileTitle = szFileTitle; 
Ofn.nMaxFileTitle = sizeof(szFileTitle); 
Ofn.lpstrInitialDir = (LPSTR)NULL; 
Ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT; 
Ofn.lpstrTitle = szTitle; 
 
// Display the Filename common dialog box. The  
// filename specified by the user is passed  
// to the CreateEnhMetaFile function and used to  
// store the metafile on disk.  
 
GetSaveFileName(&Ofn); 
 
// Load the description from the string table.  
 
LoadString(hInst, IDS_DESCRIPTIONSTRING, 
     (LPSTR)szDescription, sizeof(szDescription)); 
 
// Replace the '%' string separators that are  
// embedded between strings in the string-table  
// entry with '\0'.  
 
for (i=0; szDescription[i]!='\0'; i++) 
{
    if (szDescription[i] == '%') 
            szDescription[i] = '\0'; 
}
 
// Create the metafile device context.  
 
hdcMeta = CreateEnhMetaFile(hdcRef, 
          (LPTSTR) Ofn.lpstrFile, 
          &rect, (LPSTR)szDescription); 
 
if (!hdcMeta) 
    errhandler("CreateEnhMetaFile", hWnd); 
 
// Release the reference device context.  
 
ReleaseDC(hWnd, hdcRef);