// CLDSTR32Dlg.cpp : implementation file // #include "stdafx.h" #include "CLDSTR32.h" #include "CLDSTR32Dlg.h" #include "OptionsDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // 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) //}}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) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCLDSTR32Dlg dialog CCLDSTR32Dlg::CCLDSTR32Dlg(CWnd* pParent /*=NULL*/) : CDialog(CCLDSTR32Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CCLDSTR32Dlg) m_sStatus = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_sServerName = ""; m_sClientName = ""; m_sServerIP = "0.0.0.0"; m_uServerPort = 104; m_uTimeOut = 0; m_uCompression = 0; } void CCLDSTR32Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCLDSTR32Dlg) DDX_Control(pDX, IDC_LIST_DICOM_FILES, m_cFileList); DDX_Text(pDX, IDC_EDIT_STATUS, m_sStatus); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCLDSTR32Dlg, CDialog) //{{AFX_MSG_MAP(CCLDSTR32Dlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUT_CLOSE, OnButClose) ON_BN_CLICKED(IDC_BUT_OPTIONS, OnButOptions) ON_BN_CLICKED(IDC_BUT_STORE, OnButStore) ON_BN_CLICKED(IDC_BUT_ADD_FILE, OnButAddFile) ON_BN_CLICKED(IDC_BUT_ADD_DICOMDIR, OnButAddDicomdir) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUT_CLEARALL, OnButClearall) ON_WM_CLOSE() ON_NOTIFY(LVN_DELETEITEM, IDC_LIST_DICOM_FILES, OnDeleteitemListDicomFiles) ON_NOTIFY(LVN_INSERTITEM, IDC_LIST_DICOM_FILES, OnInsertitemListDicomFiles) ON_NOTIFY(LVN_DELETEALLITEMS, IDC_LIST_DICOM_FILES, OnDeleteallitemsListDicomFiles) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCLDSTR32Dlg message handlers BOOL CCLDSTR32Dlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // Initialization // Build the listview m_cFileList.InsertColumn(0, "Patient Name", LVCFMT_LEFT, 100, 0); m_cFileList.InsertColumn(1, "Patient ID", LVCFMT_LEFT, 85, 1); m_cFileList.InsertColumn(2, "Study ID", LVCFMT_LEFT, 85, 2); m_cFileList.InsertColumn(3, "Modality", LVCFMT_LEFT, 85, 3); m_cFileList.InsertColumn(4, "Transfer syntax", LVCFMT_LEFT, 90, 4); m_cFileList.InsertColumn(5, "File path", LVCFMT_LEFT, 177, 5); m_cFileList.SetExtendedStyle(m_cFileList.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_UNDERLINEHOT); // Read form registry ReadDataFromRegistry(); return TRUE; // return TRUE unless you set the focus to a control } void CCLDSTR32Dlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CCLDSTR32Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CCLDSTR32Dlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CCLDSTR32Dlg::OnButClose() { CDialog::OnCancel(); } void CCLDSTR32Dlg::OnButOptions() { OptionsDlg CurOptionsDlg; L_UINT nRet; CurOptionsDlg.m_sPubServerName = m_sServerName; CurOptionsDlg.m_sPubClientName = m_sClientName; CurOptionsDlg.m_sPubServerIP = m_sServerIP; CurOptionsDlg.m_nPubServerPort = m_uServerPort; CurOptionsDlg.m_uPubTimeOut = m_uTimeOut; CurOptionsDlg.m_nPubCompression = m_uCompression; // Show Options dialog nRet = CurOptionsDlg.DoModal(); if (nRet != IDOK) return; // Read the options values m_sServerName = CurOptionsDlg.m_sPubServerName; m_sClientName = CurOptionsDlg.m_sPubClientName; m_sServerIP = CurOptionsDlg.m_sPubServerIP; m_uServerPort = CurOptionsDlg.m_nPubServerPort; m_uTimeOut = CurOptionsDlg.m_uPubTimeOut; m_uCompression = CurOptionsDlg.m_nPubCompression; // Save values in registry SaveInRegistry(); } // Read data from the registry L_VOID CCLDSTR32Dlg::ReadDataFromRegistry() { long lRet; lRet = m_cMyRegKey.Open(HKEY_CURRENT_USER, REGISTRY_LOCATION); if (lRet == ERROR_SUCCESS) { L_CHAR szBufValue[1000]; DWORD dwCount; // Server Name dwCount = sizeof(szBufValue); lRet = m_cMyRegKey.QueryValue(szBufValue, "sServerName", &dwCount); if (lRet == ERROR_SUCCESS) { m_sServerName = szBufValue; } // Server IP dwCount = sizeof(szBufValue); lRet = m_cMyRegKey.QueryValue(szBufValue, "sServerIP", &dwCount); if (lRet == ERROR_SUCCESS) { m_sServerIP = szBufValue; } DWORD dwValue; // Server port number lRet = m_cMyRegKey.QueryValue(dwValue, "uServerPort"); if (lRet == ERROR_SUCCESS) { m_uServerPort = dwValue; } // Client Name dwCount = sizeof(szBufValue); lRet = m_cMyRegKey.QueryValue(szBufValue, "sClientName", &dwCount); if (lRet == ERROR_SUCCESS) { m_sClientName = szBufValue; } // Time-out lRet = m_cMyRegKey.QueryValue(dwValue, "uTimeOut"); if (lRet == ERROR_SUCCESS) { m_uTimeOut = dwValue; } // Compression lRet = m_cMyRegKey.QueryValue(dwValue, "uCompression"); if (lRet == ERROR_SUCCESS) { m_uCompression = dwValue; } } } // Save the data in the registry L_VOID CCLDSTR32Dlg::SaveInRegistry() { long lRet; lRet = m_cMyRegKey.Create(HKEY_CURRENT_USER, REGISTRY_LOCATION); if (lRet == ERROR_SUCCESS) { // Server name m_cMyRegKey.SetValue(m_sServerName, "sServerName"); // Server IP m_cMyRegKey.SetValue(m_sServerIP, "sServerIP"); // Server port number m_cMyRegKey.SetValue(m_uServerPort, "uServerPort"); // Client Name m_cMyRegKey.SetValue(m_sClientName, "sClientName"); // Time-out m_cMyRegKey.SetValue(m_uTimeOut, "uTimeOut"); // Time Out (Seconds) m_cMyRegKey.SetValue(m_uCompression, "uCompression"); } } void CCLDSTR32Dlg::OnButStore() { // Empty the status edit box m_sStatus = ""; UpdateData(FALSE); L_BOOL bValid = TRUE; // Check the validation of the connection variables if (m_sServerName.IsEmpty()) bValid = FALSE; if (m_sClientName.IsEmpty()) bValid = FALSE; if (m_sServerIP.IsEmpty()) bValid = FALSE; if (bValid == FALSE) { MessageBox("Please check the validity of the values in the options dialog!","Storage - SCU", MB_OK|MB_ICONEXCLAMATION); return; } m_CurProgress.m_pCurMainDlg = this; // Show the progress dialog m_CurProgress.DoModal(); } void CCLDSTR32Dlg::OnButAddFile() { TCHAR szFilters[] =_T ("DICOM Files (*.dic)|*.dic|DCM Files (*.dcm)|*.dcm|All files (*.*)|*.*||"); L_INT nLoadFlags = 0; CFileDialog dlg ( TRUE, _T ("dic"), _T ("*.dic"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters); if (dlg.DoModal () == IDOK) { CWaitCursor CurCursor; FillListSingleFile((L_CHAR *)(LPCSTR)dlg.GetPathName()); } } L_VOID CCLDSTR32Dlg::FillListSingleFile(CString sFileName) { L_INT nResult; L_UINT uRowsCount; LDicomDS CurDS; nResult = CurDS.LoadDS((L_CHAR *)(LPCTSTR)sFileName,0); if (nResult != DICOM_SUCCESS) { MessageBox("Not able to open the file", "DICOM ERROR", MB_ICONSTOP); return; } pDICOMELEMENT pElement; L_CHAR szUnknown[] = " "; L_CHAR *pszText; uRowsCount = m_cFileList.GetItemCount(); // Patient Name pElement = CurDS.FindFirstElement(NULL, TAG_PATIENT_NAME, FALSE); if (pElement != NULL) { pszText = CurDS.GetStringValue(pElement,0,1); if (pszText) m_cFileList.InsertItem(uRowsCount, pszText); } // Patient ID pszText = NULL; if (pElement) CurDS.FreeValue(pElement); pElement = CurDS.FindFirstElement(NULL, TAG_PATIENT_ID, FALSE); if (pElement != NULL) { pszText = CurDS.GetStringValue(pElement,0,1); if (pszText) m_cFileList.SetItem(uRowsCount, 1, LVIF_TEXT, pszText, 0, 0, LVIS_SELECTED, 0); } // Study ID pszText = NULL; if (pElement) CurDS.FreeValue(pElement); pElement = CurDS.FindFirstElement(NULL, TAG_STUDY_ID, FALSE); if (pElement != NULL) { pszText = CurDS.GetStringValue(pElement,0,1); if (pszText) m_cFileList.SetItem(uRowsCount, 2, LVIF_TEXT, pszText, 0, 0, LVIS_SELECTED, 0); } // Modality pszText = NULL; if (pElement) CurDS.FreeValue(pElement); pElement = CurDS.FindFirstElement(NULL, TAG_MODALITY, FALSE); if (pElement != NULL) { pszText = CurDS.GetStringValue(pElement,0,1); if (pszText) m_cFileList.SetItem(uRowsCount, 3, LVIF_TEXT, pszText, 0, 0, LVIS_SELECTED, 0); } // Transfer syntax pszText = "Implicit VR Little Endian"; if (pElement) CurDS.FreeValue(pElement); pElement = CurDS.FindFirstElement(NULL, TAG_TRANSFER_SYNTAX_UID, FALSE); if (pElement != NULL) { pszText = CurDS.GetStringValue(pElement,0,1); if (pszText) { pDICOMUID pUID; pUID = LDicomUID::Find(pszText); if (pUID) pszText = pUID->pszName; } } m_cFileList.SetItem(uRowsCount, 4, LVIF_TEXT, pszText, 0, 0, LVIS_SELECTED, 0); // File Path m_cFileList.SetItem(uRowsCount, 5, LVIF_TEXT, (LPCTSTR)sFileName, 0, 0, LVIS_SELECTED, 0); } void CCLDSTR32Dlg::OnButAddDicomdir() { TCHAR szFilters[] =_T ("All files (*.*)|*.*||"); L_INT nLoadFlags = 0; CFileDialog dlg ( TRUE, NULL, _T ("DICOMDIR"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters); if (dlg.DoModal () == IDOK) { CWaitCursor CurCursor; GetAllReferncedFiles((L_CHAR *)(LPCSTR)dlg.GetPathName()); } } L_VOID CCLDSTR32Dlg::GetAllReferncedFiles(CString sFileName) { L_INT nResult; CString sPath; LDicomDS CurDS; L_INT nPos; nPos = sFileName.ReverseFind('\\'); if (nPos > 0) sPath = sFileName.Left(nPos + 1); nResult = CurDS.LoadDS((L_CHAR *)(LPCTSTR)sFileName,0); if (nResult != DICOM_SUCCESS) { MessageBox("Not able to open the file", "DICOM ERROR", MB_ICONSTOP); return; } pDICOMELEMENT pElement; L_CHAR szUnknown[] = " "; L_CHAR *pszText; // Get first refernced file ID pElement = CurDS.FindFirstElement(NULL, TAG_REFERENCED_FILE_ID, FALSE); // Loop over all refernced file IDs in DICOMDIR file while (pElement != NULL) { pszText = NULL; pszText = CurDS.GetStringValue(pElement,0,1); if (pszText) FillListSingleFile(sPath + pszText); // Free the variables if (pElement) CurDS.FreeValue(pElement); pElement = CurDS.FindNextElement(pElement, FALSE); } } void CCLDSTR32Dlg::OnCancel() { } void CCLDSTR32Dlg::OnDestroy() { CDialog::OnDestroy(); } void CCLDSTR32Dlg::OnButClearall() { m_cFileList.DeleteAllItems(); m_sStatus = ""; UpdateData(FALSE); } void CCLDSTR32Dlg::OnClose() { CDialog::OnCancel(); } void CCLDSTR32Dlg::OnDeleteitemListDicomFiles(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; if(m_cFileList.GetItemCount() == 0) { CWnd *pButton = GetDlgItem(IDC_BUT_STORE); if(pButton) { pButton->EnableWindow(FALSE); } pButton = GetDlgItem(IDC_BUT_CLEARALL); if(pButton) { pButton->EnableWindow(FALSE); } } *pResult = 0; } void CCLDSTR32Dlg::OnInsertitemListDicomFiles(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; if(m_cFileList.GetItemCount() > 0) { CWnd *pButton = GetDlgItem(IDC_BUT_STORE); if(pButton) { pButton->EnableWindow(TRUE); } pButton = GetDlgItem(IDC_BUT_CLEARALL); if(pButton) { pButton->EnableWindow(TRUE); } } *pResult = 0; } void CCLDSTR32Dlg::OnDeleteallitemsListDicomFiles(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; CWnd *pButton = GetDlgItem(IDC_BUT_STORE); if(pButton) { pButton->EnableWindow(FALSE); } pButton = GetDlgItem(IDC_BUT_CLEARALL); if(pButton) { pButton->EnableWindow(FALSE); } *pResult = 0; }