|
Opening an Enhanced Metafile and Displaying Its Contents
This section contains an example demonstrating how an application opens an
enhanced metafile stored on disk and displays the associated picture in the client
area.
The example uses the Open common dialog box to enable the user to select an
enhanced metafile from a list of existing files. It then passes the name of the
selected file to the GetEnhMetaFile function, which returns a handle identifying the file. This handle is passed
to the PlayEnhMetaFile function in order to display the picture.
LoadString(hInst, IDS_FILTERSTRING,
(LPSTR)szFilter, sizeof(szFilter));
/*
* Replace occurrences of '%' string separator
* with '\0'.
*/
for (i=0; szFilter[i]!='\0'; i++)
if (szFilter[i] == '%')
szFilter[i] = '\0';
LoadString(hInst, IDS_DEFEXTSTRING,
(LPSTR)szDefExt, sizeof(szFilter));
/*
* Use the OpenFilename common dialog box
* to obtain the desired filename.
*/
szFile[0] = '\0';
Ofn.lStructSize = sizeof(OPENFILENAME);
Ofn.hwndOwner = hWnd;
Ofn.lpstrFilter = szFilter;
Ofn.lpstrCustomFilter = (LPSTR)NULL;
Ofn.nMaxCustFilter = 0L;
Ofn.nFilterIndex = 1L;
Ofn.lpstrFile = szFile;
Ofn.nMaxFile = sizeof(szFile);
Ofn.lpstrFileTitle = szFileTitle;
Ofn.nMaxFileTitle = sizeof(szFileTitle);
Ofn.lpstrInitialDir = (LPSTR) NULL;
Ofn.lpstrTitle = (LPSTR)NULL;
Ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
Ofn.nFileOffset = 0;
Ofn.nFileExtension = 0;
Ofn.lpstrDefExt = szDefExt;
GetOpenFileName(&Ofn);
/* Open the metafile. */
hemf = GetEnhMetaFile(Ofn.lpstrFile);
/* Retrieve a handle to a window DC. */
hDC = GetDC(hWnd);
/* Retrieve the client rectangle dimensions. */
GetClientRect(hWnd, &rct);
/* Draw the picture. */
PlayEnhMetaFile(hDC, hemf, &rct);
/* Release the metafile handle. */
DeleteEnhMetaFile(hemf);
/* Release the window DC. */
ReleaseDC(hWnd, hDC);
Related Links
Software for Delphi and C++ Builder developers
Software for Visual Studio .NET developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET
More Online Helps
Win32 Multimedia Programmer's Reference (mmedia.hlp)
OLE Programmer's Reference (ole.hlp)
Microsoft Windows Pen API Programmer's Reference (penapi.hlp)
Microsoft Windows Sockets 2 Reference (sock2.hlp)
Microsoft Windows Telephony API (TAPI) Programmer's Reference (tapi.hlp)
Unix Manual Pages
|