// ProgressDlg.cpp : implementation file // #include "stdafx.h" #include "cldstr32.h" #include "ProgressDlg.h" #include "CLDSTR32Dlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define ID_PROGRESS_TIMER 1 struct { L_UINT uStatusID; // ID of the status message L_CHAR* pszDescription; // The description of the status message L_BOOL bFinish; // Whether the process is to be finished or not } StatusArray[] = { STR_CONNECT_FAILED, "Connect operation failed", TRUE, STR_CONNECT_SUCCEEDED, "Connect operation succeeded", FALSE, STR_SEND_ASSOCIATION_REQUEST, "Sending assocaition request", FALSE, STR_RECEIVE_ASSOCIATE_ACCEPT, "Receiving association accept", FALSE, STR_RECEIVE_ASSOCIATE_REJECT, "Receiving association reject", TRUE, STR_ABSTRACT_SYNTAX_NOT_SUPPORTED, "Abstract Syntax NOT supported", TRUE, STR_SEND_CSTORE_REQUEST, "Sending C-STORE request", FALSE, STR_RECEIVE_CSTORE_RESPONSE, "** Storage (C-STORE) completed successfully **", TRUE, STR_CONNECTION_CLOSED, "Closing connection", TRUE, STR_PROCESS_TERMINATED, "Storage has been terminated", TRUE, STR_SEND_RELEASE_REQUEST, "Sending release request", FALSE, STR_RECEIVE_RELEASE_RESPONSE, "Receiving release response", TRUE, STR_DICOM_ERROR, "General DICOM Error", TRUE, }; ///////////////////////////////////////////////////////////////////////////// // ProgressDlg dialog ProgressDlg* ProgressDlg::m_pStaticDlg; ProgressDlg::ProgressDlg(CWnd* pParent /*=NULL*/) : CDialog(ProgressDlg::IDD, pParent) { //{{AFX_DATA_INIT(ProgressDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void ProgressDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ProgressDlg) DDX_Control(pDX, IDC_ANIMATE, m_Animate); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(ProgressDlg, CDialog) //{{AFX_MSG_MAP(ProgressDlg) ON_BN_CLICKED(ID_BUT_CANCEL, OnButCancel) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ProgressDlg message handlers BOOL ProgressDlg::OnInitDialog() { CDialog::OnInitDialog(); // Get all selected files and add them to CStoreClass POSITION pos = m_pCurMainDlg->m_cFileList.GetFirstSelectedItemPosition(); if (pos == NULL) { // No selected item MessageBox("Please select an image (or a set of images) from the list to be stored!", "Storage SCU", MB_OK | MB_ICONEXCLAMATION); CloseDialog(); return TRUE; } else { // Empty the list of files in the class m_StrSCU.RemoveAllFiles(); // Fill all the selected files in the list inside the class while (pos) { int nItem = m_pCurMainDlg->m_cFileList.GetNextSelectedItem(pos); m_StrSCU.AddFile((L_CHAR*)(LPCTSTR) m_pCurMainDlg->m_cFileList.GetItemText(nItem, 5)); } } m_StrSCU.m_pWnd = this; m_pStaticDlg = this; m_Animate.Open(IDR_WAITAVI); m_uCountTimer = 0; GetDlgItem(IDC_STAT_FILENAME)->SetWindowText("Storing progress ..."); // Set timer if the time-out value is not zero if (m_pCurMainDlg->m_uTimeOut > 0) SetTimer(ID_PROGRESS_TIMER, 1000, TimerProc); // Play the AVI m_Animate.Play(0, -1, -1); L_INT nRet; // Start the verification process nRet = m_StrSCU.DoStore((L_CHAR*)(LPCTSTR) m_pCurMainDlg->m_sServerName, (L_CHAR*)(LPCTSTR) m_pCurMainDlg->m_sClientName, (L_CHAR*)(LPCTSTR) m_pCurMainDlg->m_sServerIP, m_pCurMainDlg->m_uCompression, m_pCurMainDlg->m_uServerPort); if (nRet != 0) { // Dicom Error // Show the staus in the status edit box if (m_pCurMainDlg) { m_pCurMainDlg->m_sStatus.Format("DICOM error. The process will be terminated!\r\nError code is: %i\r\n", nRet); m_pCurMainDlg->UpdateData(FALSE); return TRUE; } } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CALLBACK EXPORT ProgressDlg::TimerProc( HWND hWnd, // handle of CWnd that called SetTimer UINT nMsg, // WM_TIMER UINT nIDEvent, // timer identification DWORD dwTime // system time ) { // m_pStaticDlg if (nIDEvent == ID_PROGRESS_TIMER) { m_pStaticDlg->m_uCountTimer++; // Check if the time out is expired if (m_pStaticDlg->m_uCountTimer > m_pStaticDlg->m_pCurMainDlg->m_uTimeOut) { // Operation finished m_pStaticDlg->KillTimer(nIDEvent); // Show the staus in the status edit box CString sCurStat; // Get the text in the status edit box m_pStaticDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->GetWindowText(sCurStat); m_pStaticDlg->m_pCurMainDlg->m_sStatus = sCurStat + "Time-out expired. The process will be terminated!" + "\r\n"; //m_pStaticDlg->m_pCurMainDlg->m_sStatus = m_pStaticDlg->m_pCurMainDlg->m_sStatus + "Time-out expired. The process will be terminated!" + "\r\n"; m_pStaticDlg->m_pCurMainDlg->UpdateData(FALSE); // Abort the process m_pStaticDlg->AbortStoreProcess(); // Close the dialog if it is not closed yet m_pStaticDlg->CloseDialog(); } } } void ProgressDlg::OnCancel() { } void ProgressDlg::OnButCancel() { // Abort the process AbortStoreProcess(); CDialog::OnCancel(); } L_VOID ProgressDlg::AbortStoreProcess() { // Kill timer KillTimer(ID_PROGRESS_TIMER); // Terminate the process m_StrSCU.TerminateStorage(); } L_VOID ProgressDlg::CloseDialog() { L_UINT nRet = 1; EndDialog(nRet); } ////////////////////////////////////////////////////////////////////////// // CStoreClass methods // Get the current file name L_VOID CStoreClass::OnProgressFiles(L_CHAR* pszFileName) { CString sFileName = pszFileName; CString sStatus; ProgressDlg* pDlg = (ProgressDlg*) m_pWnd; if (pDlg) { // Get the text in the status edit box pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->GetWindowText(sStatus); sStatus += "*** File to be stored: " + sFileName + " ***\r\n"; // Show the status in the staus edit box pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->SetWindowText(sStatus); pDlg->GetDlgItem(IDC_STAT_FILENAME)->SetWindowText(sFileName); // Vertical scroll LRESULT nCurPos; pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->GetWindowText(sStatus); nCurPos = SendMessage(pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->m_hWnd, EM_LINEFROMCHAR, sStatus.GetLength() - 1, 0); SendMessage(pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->m_hWnd, EM_LINESCROLL, 0, nCurPos); } } // Check the status of the process L_VOID CStoreClass::OnStatus(L_UINT uStatus, L_INT nErrorCode) { CString sStatus; ProgressDlg* pDlg = (ProgressDlg*) m_pWnd; // Progress if (pDlg) { // Get the text in the status edit box pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->GetWindowText(sStatus); // If general DICOM error if (uStatus == STR_DICOM_ERROR) { // Show the staus in the status edit box CString sTemp; sTemp.Format("DICOM error. The process will be terminated! --- Error code is: %i\r\n", nErrorCode); sStatus = sStatus + sTemp; } else { // Get the current status related text sStatus += GetStatusText(uStatus, nErrorCode) + "\r\n"; } // Show the status in the status edit box pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->SetWindowText(sStatus); // Vertical scroll LRESULT nCurPos; pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->GetWindowText(sStatus); nCurPos = SendMessage(pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->m_hWnd, EM_LINEFROMCHAR, sStatus.GetLength() - 1 , 0); SendMessage(pDlg->GetParent()->GetDlgItem(IDC_EDIT_STATUS)->m_hWnd, EM_LINESCROLL, 0, nCurPos); // Check to close the progress dialog if ((uStatus == STR_CONNECTION_CLOSED) || (uStatus == STR_CONNECT_FAILED)) pDlg->CloseDialog(); } } CString CStoreClass::GetStatusText(L_UINT uStatusConst, L_INT nErrorCode) { CString sErrorReturn; int iLength = sizeof(StatusArray) / sizeof(StatusArray[0]); // Determination of the text that should appear in the status edit box for (int iCounter = 0; iCounter < iLength; iCounter++) { if (StatusArray[iCounter].uStatusID == uStatusConst) { if (uStatusConst == STR_RECEIVE_CSTORE_RESPONSE) { if (nErrorCode != COMMAND_STATUS_SUCCESS) { sErrorReturn.Format("*** Status: 0x%04x ***",nErrorCode); return sErrorReturn; } } return StatusArray[iCounter].pszDescription; } } return ""; }