|
// BridgeDoc.cpp : implementation of the CBridgeDoc class
//
#include "stdafx.h"
#include "Bridge.h"
#include "BridgeDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBridgeDoc
IMPLEMENT_DYNCREATE(CBridgeDoc, CDocument)
BEGIN_MESSAGE_MAP(CBridgeDoc, CDocument)
//{{AFX_MSG_MAP(CBridgeDoc)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBridgeDoc construction/destruction
CBridgeDoc::CBridgeDoc()
{
// Step 1 - Initialize class members
m_pImage = NULL;
}
CBridgeDoc::~CBridgeDoc()
{
// Step 1 - Delete image object, if it is valid
if( m_pImage != NULL )
{
delete m_pImage;
}
}
/////////////////////////////////////////////////////////////////////////////
// CBridgeDoc diagnostics
#ifdef _DEBUG
void CBridgeDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CBridgeDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBridgeDoc commands
void CBridgeDoc::OnFileOpen()
{
CFileDialog FileDialog( TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
| OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,
"Bitmap Files (*.bmp;*.wmf)|*.bmp;*.wmf|DIB Files (*.dib)|*.dib|All Files (*.*)|*.*|||",
NULL );
// Step 1 - Show the dialog box and open the document, if a valid file name is selected
if( FileDialog.DoModal() == IDOK )
{
OnOpenDocument( FileDialog.GetPathName() );
}
}
BOOL CBridgeDoc::OnOpenDocument( LPCTSTR lpszPathName )
{
CWaitCursor WaitCursor;
CImage * pTempImage = NULL;
// Step 1 - Create an image object
pTempImage = new CBmpImage;
if( pTempImage == NULL )
{
CHAR szTempString[ 512 ];
memset( szTempString, 0, sizeof( szTempString ) );
sprintf( szTempString, "Insufficient memory.\n");
AfxMessageBox( "Insufficient memory", MB_ICONSTOP | MB_OK );
return FALSE;
}
// Step 2 - Load image file and configure with the runtime information
// of the implementation class, CWinImp in this case
if( pTempImage->Load( lpszPathName, RUNTIME_CLASS( CWinImp ) ) != SUCCESS )
{
// Step 3 - Delete object and display error message
delete pTempImage;
CHAR szTempString[ 512 ];
memset( szTempString, 0, sizeof( szTempString ) );
sprintf( szTempString, "Unable to open the image file %s.\n", lpszPathName );
AfxMessageBox( szTempString, MB_ICONINFORMATION | MB_OK );
return FALSE;
}
// Step 4 - Delete old image object, if it is valid
if( m_pImage != NULL )
{
delete m_pImage;
}
// Step 5 - Assign, new image object
m_pImage = pTempImage;
UpdateAllViews( NULL );
SetPathName( lpszPathName );
return TRUE;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Kulathu Sarma is working as a Technology Manager for GoldAvenue, a company based in Geneva, Switzerland and responsible for supporting e-business initiatives of GoldAvenue in B2B and B2C Sectors. He has been programming in C/C++ for 9 years and actively working on Patterns for the past 5 years.