// ltcdb.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "ltcdb.h" #include "MainFrm.h" #include "ltcdbSet.h" #include "ltcdbDoc.h" #include "ocdbView.h" extern void ExitMFCApp(); #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CLtcdbApp BEGIN_MESSAGE_MAP(CLtcdbApp, CWinApp) //{{AFX_MSG_MAP(CLtcdbApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// void ExitMFCApp() { // Same as double-clicking on main window close box. ASSERT(AfxGetMainWnd() != NULL); AfxGetMainWnd()->SendMessage(WM_CLOSE); } ///////////////////////////////////////////////////////////////////////////// // CLtcdbApp construction CLtcdbApp::CLtcdbApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance m_pRasterIO = NULL; m_pRasterODBC = NULL; m_pRaster = NULL; m_pRasterProcess = NULL; m_iPage = 1; } ///////////////////////////////////////////////////////////////////////////// // The one and only CLtcdbApp object CLtcdbApp theApp; ///////////////////////////////////////////////////////////////////////////// // CLtcdbApp initialization BOOL CLtcdbApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CLtcdbDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CLtcdbView)); AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); //Initialize variables and create COM objects CoInitialize(NULL); //Create the licensed LTRaster COM object HRESULT hr = CreateRasterObjectLic(&m_pRaster); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitMFCApp(); return FALSE; } hr = CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&m_pRasterIO); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitMFCApp(); } hr = CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&m_pRasterProcess); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitMFCApp(); } hr = CoCreateInstance(CLSID_LEADRasterODBC, NULL, CLSCTX_ALL, IID_ILEADRasterODBC, (void**)&m_pRasterODBC); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitMFCApp(); } hr = CoCreateInstance(CLSID_LEADRasterAnnotation, NULL, CLSCTX_ALL, IID_ILEADRasterAnnotation, (void**)&m_pRasterAnn); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitMFCApp(); } m_pRaster->PutEnableMethodErrors(FALSE); m_pRasterIO->PutEnableMethodErrors(FALSE); m_pRasterProcess->PutEnableMethodErrors(FALSE); m_pRasterODBC->PutEnableMethodErrors(FALSE); BOOL bRet = m_pRasterODBC->dbOpen("ODBC;DSN=LEADACCESS", "SELECT photo FROM people ORDER BY who", "photo", DB_OPENOPTIONS_NONE); if(bRet) return FALSE; else m_pRasterODBC->dbClose(); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) // No message handlers //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } ///////////////////////////////////////////////////////////////////////////// void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } ///////////////////////////////////////////////////////////////////////////// BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // App command to run the dialog void CLtcdbApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CLtcdbApp commands int CLtcdbApp::ExitInstance() { CoUninitialize(); return CWinApp::ExitInstance(); } HRESULT CLtcdbApp::CreateRasterObjectLic(ILEADRaster ** ppRaster) { HRESULT hr; *ppRaster = NULL; IClassFactory2 *pCF2 = NULL; hr = CoGetClassObject(CLSID_LEADRaster, CLSCTX_ALL, NULL, IID_IClassFactory2, (void**)&pCF2); if (!pCF2) return hr; IUnknown *pOuter = NULL; static const WCHAR BASED_CODE _szLicString[] =L"LEADTOOLS OCX Copyright (c) 1991-2004 LEAD Technologies, Inc."; BSTR LicKey = SysAllocString(_szLicString); BSTR pszLic = SysAllocString(_szLicString); hr = pCF2->CreateInstanceLic(pOuter, NULL, IID_IUnknown, pszLic, (void**)ppRaster); pCF2->Release(); SysFreeString(pszLic); return hr; } int CLtcdbApp::DisplayLEADError(int nCode) { CString str; if (nCode == COM_ERROR_DLG_CANCELED) nCode = 0; if(nCode) { str.Format(TEXT("A LEADTOOLS error has occured.\nCODE = %d"), nCode); AfxMessageBox(str); } return(nCode); }