MyFileIO.cpp
上传用户:cding2008
上传日期:2007-01-03
资源大小:1812k
文件大小:4k
- /////////////////////////////////////////////////////////////////////////////
- // MyFileIO.cpp : File I/O helper implementation
- //
- // ModelMagic 3D and 'glOOP' (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1998
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is freely distributable without licensing fees and is
- // provided without guarantee or warrantee expressed or implied. This
- // program is -not- in the public domain.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "MyFileIO.h"
- /////////////////////////////////////////////////////////////////////////////
- // Helpers for saving/restoring window state in the ini file
- static TCHAR szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
- BOOL PASCAL NEAR ReadWindowPlacement(LPWINDOWPLACEMENT pwp, LPSTR lpszSection, LPSTR lpszWindowName)
- {
- CString strBuffer = AfxGetApp()->GetProfileString(lpszSection, lpszWindowName);
- if (strBuffer.IsEmpty())
- return FALSE;
- WINDOWPLACEMENT wp;
- int nRead = _stscanf(strBuffer, szFormat,
- &wp.flags, &wp.showCmd,
- &wp.ptMinPosition.x, &wp.ptMinPosition.y,
- &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
- &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
- &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
- if (nRead != 10)
- return FALSE;
- wp.length = sizeof wp;
- *pwp = wp;
- return TRUE;
- }
- void PASCAL NEAR WriteWindowPlacement(LPWINDOWPLACEMENT pwp, LPSTR lpszSection, LPSTR lpszWindowName)
- // write a window placement to settings section of app's ini file
- {
- TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
- wsprintf(szBuffer, szFormat,
- pwp->flags, pwp->showCmd,
- pwp->ptMinPosition.x, pwp->ptMinPosition.y,
- pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
- pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
- pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
- AfxGetApp()->WriteProfileString(lpszSection, lpszWindowName, szBuffer);
- }
- void DisplayFileIOException(CFileException* exception)
- {
- if(exception->m_cause == CFileException::none )
- AfxMessageBox("No error occured. False exception??", MB_OK, NULL);
- if(exception->m_cause == CFileException::generic )
- AfxMessageBox("An unspecified error occurred!", MB_OK, NULL);
- if(exception->m_cause == CFileException::fileNotFound )
- AfxMessageBox("The file could not be located!", MB_OK, NULL);
- if(exception->m_cause == CFileException::badPath )
- AfxMessageBox("All or part of the path is invalid!", MB_OK, NULL);
- if(exception->m_cause == CFileException::tooManyOpenFiles )
- AfxMessageBox("The permitted number of open files was exceeded!", MB_OK, NULL);
- if(exception->m_cause == CFileException::accessDenied )
- AfxMessageBox("The file could not be accessed!", MB_OK, NULL);
- if(exception->m_cause == CFileException::invalidFile )
- AfxMessageBox("There was an attempt to use an invalid file handle!", MB_OK, NULL);
- if(exception->m_cause == CFileException::removeCurrentDir )
- AfxMessageBox("The current working directory cannot be removed!", MB_OK, NULL);
- if(exception->m_cause == CFileException::directoryFull )
- AfxMessageBox("There are no more directory entries!", MB_OK, NULL);
- if(exception->m_cause == CFileException::badSeek )
- AfxMessageBox("There was an error trying to set the file pointer!", MB_OK, NULL);
- if(exception->m_cause == CFileException::hardIO )
- AfxMessageBox("There was a hardware error!", MB_OK, NULL);
- if(exception->m_cause == CFileException::sharingViolation )
- AfxMessageBox("SHARE.EXE was not loaded, or a shared region was locked!", MB_OK, NULL);
- if(exception->m_cause == CFileException::lockViolation )
- AfxMessageBox("There was an attempt to lock a region that was already locked!", MB_OK, NULL);
- if(exception->m_cause == CFileException::diskFull )
- AfxMessageBox("The disk is full!", MB_OK, NULL);
- if(exception->m_cause == CFileException::endOfFile )
- AfxMessageBox("The end of file was reached!", MB_OK, NULL);
- }