// CLDMWLSCP.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "CLDMWLSCP.h" #include "PropertySheetDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define REGISTRY_LOCATION "SOFTWARE\\LEAD Technologies, Inc.\\DicomMWLSCP" #define MDB_FILENAME "MWLSCP.mdb" #ifndef INVALID_FILE_ATTRIBUTES #define INVALID_FILE_ATTRIBUTES -1 #endif ///////////////////////////////////////////////////////////////////////////// // CCLDMWLSCPApp BEGIN_MESSAGE_MAP(CCLDMWLSCPApp, CWinApp) //{{AFX_MSG_MAP(CCLDMWLSCPApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCLDMWLSCPApp construction CCLDMWLSCPApp::CCLDMWLSCPApp() { } ///////////////////////////////////////////////////////////////////////////// // The one and only CCLDMWLSCPApp object CCLDMWLSCPApp theApp; ///////////////////////////////////////////////////////////////////////////// // CCLDMWLSCPApp initialization BOOL CCLDMWLSCPApp::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 // Load libraries LBase::LoadLibraries(LT_KRN | LT_DLG); // Unlock Support WRPUNLOCKSUPPORT(); if(LSettings::IsSupportLocked(L_SUPPORT_MEDICAL_NET)) { MessageBox(NULL, "The Medical Net support should be unlocked for this demo.","Storage SCU",MB_OK|MB_ICONEXCLAMATION); LBase::UnloadLibraries(LT_KRN | LT_DLG); return FALSE; } // Start up LDicomNet if (LDicomNet::StartUp() != DICOM_SUCCESS) { MessageBox(NULL, "Error in StartUp of LDicomNet!","Storage SCU",MB_OK|MB_ICONERROR); LBase::UnloadLibraries(LT_KRN | LT_DLG); return FALSE; } // Connect to the Database here // Get DB name from registry CString sDBName = DBNameFromReg(); if (!PrepareDatabase(sDBName)) { return FALSE; } CPropertySheetDlg CurPropertySheetDlg(""); // Set the title of the property sheet CurPropertySheetDlg.SetTitle("Modality work-list provider", 0); // Show the property sheet dialog int nResponse = CurPropertySheetDlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Shut down the LDicomNet LDicomNet::ShutDown(); // Unload libraries LBase::UnloadLibraries(LT_KRN | LT_DLG); // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; } BOOL CCLDMWLSCPApp::PrepareDatabase(const CString& sRegDBFileName) { WIN32_FIND_DATA FileData; HANDLE hFind; CString sAppFolder; // Check the existance of the file saved in registry if (!sRegDBFileName.IsEmpty()) { hFind = FindFirstFile(sRegDBFileName, &FileData); if (hFind != INVALID_HANDLE_VALUE) { FindClose(hFind); // Save the DB name in registry SaveDBNameInReg(sRegDBFileName); return TRUE; } } TCHAR szBuffer[MAX_PATH]; if (GetModuleFileName(NULL, szBuffer, MAX_PATH)) { sAppFolder = szBuffer; sAppFolder = sAppFolder.Left(sAppFolder.ReverseFind('\\') + 1); } CString sNewMdbFile = sAppFolder + MDB_FILENAME; // At first, we will assume that the application is running from the "Bin" subfolder of // the folder where LEADTOOLS is installed. CString sLeadToolsFolder; if (sAppFolder.GetLength()) { sLeadToolsFolder = sAppFolder.Left(sAppFolder.GetLength() - 1); sLeadToolsFolder = sLeadToolsFolder.Left(sLeadToolsFolder.ReverseFind('\\') + 1); } CString sMessage; // Locate the database file CString sExistingMdbFile = sLeadToolsFolder + "Images\\" + MDB_FILENAME; hFind = FindFirstFile(sExistingMdbFile, &FileData); if (hFind != INVALID_HANDLE_VALUE) { FindClose(hFind); } else { // Prompt the user to locate the file sMessage = "Failed to locate the database file (MDB) used by this demo. Do you want " \ "to locate it yourself?\n\n" \ "Note: A sample MDB file is located under the \"Images\" directory created " \ "by LEADTOOLS.\n" \ "If the installation path for LEADTOOLS is for example:\n" \ "\"C:\\LEAD Technologies, Inc\\LEADTOOLS\"\n" \ "then the path for the MDB file will be:\n" \ "\"C:\\LEAD Technologies, Inc\\LEADTOOLS\\Images\\" MDB_FILENAME "\"."; if (AfxMessageBox(sMessage, MB_YESNO) != IDYES) { return FALSE; } sExistingMdbFile = MDB_FILENAME; if (!GetFile("Microsoft Access Databases (*.mdb)\0*.mdb\0All Files (*.*)\0*.*\0", "Locate MDB File", sExistingMdbFile)) { return FALSE; } } // Copy the existing databse file if (!CopyFile(sExistingMdbFile, sNewMdbFile, FALSE)) { AfxMessageBox("Failed to copy the database file.", MB_OK | MB_ICONSTOP); return FALSE; } // Save the DB name in registry SaveDBNameInReg(sNewMdbFile); return TRUE; } BOOL CCLDMWLSCPApp::GetFile(LPCTSTR pszFilter, LPCTSTR pszTitle, CString& sFile) const { OPENFILENAME ofn; TCHAR szFile[MAX_PATH]; lstrcpyn(szFile, sFile, MAX_PATH); // Initialize the OPENFILENAME structure ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.lpstrFilter = pszFilter; ofn.nFilterIndex = 1; ofn.lpstrFile = szFile; ofn.nMaxFile = sizeof(szFile) / sizeof(TCHAR); ofn.lpstrTitle = pszTitle; ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; // Display the Open dialog box if (GetOpenFileName(&ofn)) { sFile = szFile; return TRUE; } return FALSE; } CString CCLDMWLSCPApp::DBNameFromReg() { long lRet; CString sDBName; lRet = m_cRegKey.Open(HKEY_CURRENT_USER, REGISTRY_LOCATION); if (lRet == ERROR_SUCCESS) { L_CHAR szBufValue[1000]; DWORD dwCount; // Database name dwCount = sizeof(szBufValue); lRet = m_cRegKey.QueryValue(szBufValue, "sDatabaseName", &dwCount); if (lRet == ERROR_SUCCESS) { sDBName = szBufValue; } m_cRegKey.Close(); } return sDBName; } L_VOID CCLDMWLSCPApp::SaveDBNameInReg(const CString& sDBFileName) { long lRet; lRet = m_cRegKey.Create(HKEY_CURRENT_USER, REGISTRY_LOCATION); if (lRet == ERROR_SUCCESS) { // Database name m_cRegKey.SetValue(sDBFileName, "sDatabaseName"); } }