16,472
社区成员
发帖
与我相关
我的任务
分享
/****************************************************************************
* FUNCTION: SaveAs(HWND)
* PURPOSE: Invokes the common dialog function to save the current
* buffer to a file.
* COMMENTS:
* This function initializes the OPENFILENAME structure for any
* mode selected by the user: standard, using a hook or using a
* customized template. It then calls the GetSaveFileName()
* common dialog function.
* RETURN VALUES:
* TRUE - The file was saved successfully.
* FALSE - The buffer was not saved to a file.
****************************************************************************/
BOOL SaveAs(HWND hWnd)
{
strcpy( szFile, "");
strcpy( szFileTitle, "");
OpenFileName.lStructSize = sizeof(OPENFILENAME);
OpenFileName.hwndOwner = hWnd;
OpenFileName.hInstance = (HANDLE) hInst;
OpenFileName.lpstrFilter = "Enhanced MetaFile(*.EMF)\0*.EMF\0\0";
OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
OpenFileName.nMaxCustFilter = 0L;
OpenFileName.nFilterIndex = 1L;
OpenFileName.lpstrFile = szFile;
OpenFileName.nMaxFile = sizeof(szFile);
OpenFileName.lpstrFileTitle = szFileTitle;
OpenFileName.nMaxFileTitle = sizeof(szFileTitle);
OpenFileName.lpstrInitialDir = NULL;
OpenFileName.lpstrTitle = "Save File As";
OpenFileName.nFileOffset = 0;
OpenFileName.nFileExtension = 0;
OpenFileName.lpstrDefExt = "emf";
OpenFileName.lCustData = 0;
OpenFileName.Flags = OFN_OVERWRITEPROMPT;
OpenFileName.lpfnHook = (LPOFNHOOKPROC)(FARPROC)NULL;
OpenFileName.lpTemplateName = (LPSTR)NULL;
if ( GetSaveFileName( &OpenFileName ))
return(TRUE);
else
return FALSE;
}
case IDM_SAVEAS:
if (pPenList)
{
RECT rcBound;
HDC hmetadc;
HDC hdcRef = GetDC(hWnd);
int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE);
int iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE);
int iWidthPels = GetDeviceCaps(hdcRef, HORZRES);
int iHeightPels = GetDeviceCaps(hdcRef, VERTRES);
int iMMPerPelX = (iWidthMM * 100)/iWidthPels;
int iMMPerPelY = (iHeightMM * 100)/iHeightPels;
if (SaveAs(hWnd))
{
memcpy(&rcBound, &grWorkRect, sizeof(RECT));
InflateRect(&rcBound, -4, -4);
rcBound.right --;
rcBound.bottom--;
//Convert client coordinates to .01-mm units.
rcBound.left = rcBound.left * iMMPerPelX;
rcBound.top = rcBound.top * iMMPerPelY;
rcBound.right = rcBound.right * iMMPerPelX;
rcBound.bottom = rcBound.bottom * iMMPerPelY;
hmetadc = CreateEnhMetaFile(hdcRef, szFile, &rcBound, NULL);
// Traverse the Pen List, drawing each line as
// we go. Note that the for loop will only plot
// n-1 lines (n being the number of pens). Thus,
// we need to include a mechanism to plot the
// last line in the list (i.e. simply
// DrawRndLine() again after the loop).
for (pTempPRNode = pPenList; pTempPRNode->next != pPenList; pTempPRNode = pTempPRNode->next)
DrawRndLine(hmetadc, pTempPRNode);
DrawRndLine(hmetadc, pTempPRNode);
DrawJoinCap(hmetadc, pTempPRNode);
DeleteEnhMetaFile(CloseEnhMetaFile(hmetadc));
}
if (hdcRef) ReleaseDC(hWnd, hdcRef);
}
break;