- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
CrdFileDriverDoc.cpp
资源名称:cardfile.zip [点击查看]
上传用户:lsj_816
上传日期:2007-01-01
资源大小:37k
文件大小:4k
源码类别:
Windows编程
开发平台:
Visual C++
- // CrdFileDriverDoc.cpp : implementation of the CCrdFileDriverDoc class
- //
- #include "stdafx.h"
- #include "CrdFileDriver.h"
- #include "CrdFileDriverDoc.h"
- #include "CardFile/CardFile.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCrdFileDriverDoc
- IMPLEMENT_DYNCREATE(CCrdFileDriverDoc, CDocument)
- BEGIN_MESSAGE_MAP(CCrdFileDriverDoc, CDocument)
- //{{AFX_MSG_MAP(CCrdFileDriverDoc)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCrdFileDriverDoc construction/destruction
- CCrdFileDriverDoc::CCrdFileDriverDoc()
- {
- // TODO: add one-time construction code here
- }
- CCrdFileDriverDoc::~CCrdFileDriverDoc()
- {
- }
- BOOL CCrdFileDriverDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- ((CEditView*)m_viewList.GetHead())->SetWindowText(NULL);
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCrdFileDriverDoc serialization
- void CCrdFileDriverDoc::Serialize(CArchive& ar)
- {
- // CEditView contains an edit control which handles all serialization
- ((CEditView*)m_viewList.GetHead())->SerializeRaw(ar);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCrdFileDriverDoc diagnostics
- #ifdef _DEBUG
- void CCrdFileDriverDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CCrdFileDriverDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CCrdFileDriverDoc commands
- BOOL CCrdFileDriverDoc::OnOpenDocument(LPCTSTR lpszPathName)
- {
- // It is not necessary to call the base clas implementation of OnOpenDocument()
- // if (!CDocument::OnOpenDocument(lpszPathName))
- // return FALSE;
- HINSTANCE hInst;
- LPCSTR lpszDllPath = "CardFile.dll";
- IMPORTCARDFILE ImportCardFile;
- FREECARDFILEPTR FreeCardFilePtr;
- LPCARDFILECARD cfc;
- DWORD dwNumCards, dwResult;
- LPCSTR lpszDivider = "========================================";
- CString strFormat;
- // Load the carfile dll, and obtain a pointer to the import function
- hInst = LoadLibrary(lpszDllPath);
- if (!hInst)
- {
- AfxMessageBox("Cannot load the cardfile DLL");
- return FALSE;
- }
- ImportCardFile = (IMPORTCARDFILE)GetProcAddress(hInst, "ImportCardFile");
- if (!ImportCardFile)
- {
- AfxMessageBox("Cannot find the "ImportCardFile" process");
- return FALSE;
- }
- // Empty the string that will be shown in the edit control of the child window
- m_strText.Empty();
- // call the function that imports the cardfile. Each car will be loaded into a separate structure
- dwResult = ImportCardFile(lpszPathName, &cfc, &dwNumCards);
- // The cards was imported successfully
- if (dwResult == CF_SUCCESS)
- {
- // For each of the cards create string and add it to the main string m_strText
- // The main string will eventually be shown in the edit window
- for (DWORD i=0 ; i<dwNumCards ; i++)
- {
- strFormat.Format("%srn%srn%srn",
- lpszDivider, cfc[i].szHeading, cfc[i].szBodyText);
- m_strText += strFormat;
- }
- }
- else
- {
- // Error - show a message
- switch (dwResult)
- {
- case CF_FILETOSMALL:
- AfxMessageBox("The file was to small.");
- break;
- case CF_NOTACARDFILE:
- AfxMessageBox("This is not a valid cardfile database.");
- break;
- default:
- AfxMessageBox("Cardfile import failed.");
- }
- return FALSE;
- }
- // Load the process that will perform clean up of the imported cards
- FreeCardFilePtr = (FREECARDFILEPTR)GetProcAddress(hInst, "FreeCardFilePtr");
- if (!FreeCardFilePtr)
- {
- AfxMessageBox("Cannot find the "FreeCardFilePtr" process");
- return FALSE;
- }
- FreeCardFilePtr(&cfc, dwNumCards);
- FreeLibrary(hInst);
- // Make sure that the contents of the string with the cardfiles are shown
- UpdateAllViews(NULL);
- return TRUE;
- }