// CDicVfryDlg.cpp : implementation file #include "stdafx.h" #include "DicomVrf.h" #include "DicVfryDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif 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[] = { VRFY_CONNECT_FAILED, "Connect operation failed", TRUE, VRFY_CONNECT_SUCCEEDED, "Connect operation succeeded", FALSE, VRFY_SEND_ASSOCIATION_REQUEST, "Sending assocaition request", FALSE, VRFY_RECEIVE_ASSOCIATE_ACCEPT, "Receiving association accept", FALSE, VRFY_RECEIVE_ASSOCIATE_REJECT, "Receiving association reject", TRUE, VRFY_VERIFICATION_NOT_SUPPORTED, "Verification not supported by this association", TRUE, VRFY_SEND_CECHO_REQUEST, "Sending C-ECHO request", FALSE, VRFY_RECEIVE_CECHO_RESPONSE, "**** Verification (C-ECHO) completed successfully ****", TRUE, VRFY_CONNECTION_CLOSED, "Closing connection", TRUE, VRFY_PROCESS_TERMINATED, "Verification has been terminated", TRUE, VRFY_SEND_RELEASE_REQUEST, "Sending release request", FALSE, VRFY_RECEIVE_RELEASE_RESPONSE, "Receiving release response", TRUE, VRFY_DICOM_ERROR , "General DICOM Error", 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) //}}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() ///////////////////////////////////////////////////////////////////////////// // CDicVfryDlg dialog CDicVfryDlg::CDicVfryDlg(CWnd* pParent /*=NULL*/) : CDialog(CDicVfryDlg::IDD, pParent) { //{{AFX_DATA_INIT(CDicVfryDlg) m_sClientName = _T(""); m_sStatus = _T(""); m_sServerName = _T(""); m_uServerPort = 0; m_uTimeOut = 0; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CDicVfryDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDicVfryDlg) DDX_Control(pDX, IDC_EDIT_TIME_OUT, m_Edit_TimeOut); DDX_Control(pDX, IDC_EDIT_SVR_PORT, m_Edit_ServerPort); DDX_Control(pDX, IDC_EDIT_SVR_NAME, m_Edit_ServerName); DDX_Control(pDX, IDC_EDIT_CLIENT_NAME, m_Edit_ClientName); DDX_Control(pDX, IDC_IPADDRESS_SERVERIP, m_cServerIPAddress); DDX_Control(pDX, IDVerify, m_VerifyButton); DDX_Control(pDX, IDABORT, m_AbortButton); DDX_Text(pDX, IDC_EDIT_CLIENT_NAME, m_sClientName); DDX_Text(pDX, IDC_EDIT_STATUS, m_sStatus); DDX_Text(pDX, IDC_EDIT_SVR_NAME, m_sServerName); DDX_Text(pDX, IDC_EDIT_SVR_PORT, m_uServerPort); DDV_MinMaxUInt(pDX, m_uServerPort, 0, 65535); DDX_Text(pDX, IDC_EDIT_TIME_OUT, m_uTimeOut); DDV_MinMaxUInt(pDX, m_uTimeOut, 0, 3599); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDicVfryDlg, CDialog) //{{AFX_MSG_MAP(CDicVfryDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDABORT, OnAbort) ON_WM_TIMER() ON_WM_CLOSE() ON_BN_CLICKED(IDVerify, OnVerify) ON_EN_CHANGE(IDC_EDIT_SVR_NAME, OnChangeEditSvrName) ON_EN_CHANGE(IDC_EDIT_CLIENT_NAME, OnChangeEditClientName) ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDicVfryDlg message handlers BOOL CDicVfryDlg::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 // Set some default values m_uServerPort = 104; m_uTimeOut = 0; m_dwServerIP = 0; // Read data from registry ReadDataFromRegistry(); // Set the server IP m_cServerIPAddress.SetAddress(m_dwServerIP); UpdateData(FALSE); // Check whether to enable or disable the Verify button m_VerifyButton.EnableWindow(EnabledVerify()); return TRUE; // Return TRUE unless you set the focus to a control } void CDicVfryDlg::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 CDicVfryDlg::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 CDicVfryDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CDicVfryDlg::OnVerify() { // Reset the status text if (!UpdateData(TRUE)) return; // Empty the status edit box m_sStatus = ""; UpdateData(FALSE); // Server IP address CString sMyServerIP; GetDlgItemText(IDC_IPADDRESS_SERVERIP, sMyServerIP); // Start the timer if (m_uTimeOut > 0) { SetTimer(ID_TIMEOUT_TIMER, 1000, NULL); } // Disable Verify button and so all the Edit boxes and enable Abort button EnableDisableControl(FALSE); // Save the data in the registry SaveInRegistry(); m_VrfySCU.m_pWnd = this; L_INT nRet; // Start the verification process nRet = m_VrfySCU.Verify((L_CHAR*)(LPCTSTR) m_sServerName, (L_CHAR*)(LPCTSTR) m_sClientName, (L_CHAR*)(LPCTSTR) sMyServerIP, m_uServerPort); if (nRet != 0) { // Dicom Error // Kill the timer KillTimer(ID_TIMEOUT_TIMER); EnableDisableControl(TRUE); // Show the staus in the status edit box m_sStatus.Format("DICOM error. The process will be terminated!\r\nError code is: %i\r\n", nRet); UpdateData(FALSE); } } // Aborting the verification process void CDicVfryDlg::OnAbort() { // Kill timer KillTimer(ID_TIMEOUT_TIMER); // Terminate the process m_VrfySCU.TerminateVrfy(); } // Timer for the time out calculation void CDicVfryDlg::OnTimer(UINT nIDEvent) { if (nIDEvent == ID_TIMEOUT_TIMER) { m_uCountTimer++; // Check if the time out is expired if (m_uCountTimer > m_uTimeOut) { // Time - out expired KillTimer(nIDEvent); // Show the staus in the status edit box m_sStatus = m_sStatus + "Time-out expired. The process will be terminated!" + "\r\n"; UpdateData(FALSE); // Abort the process OnAbort(); } } CDialog::OnTimer(nIDEvent); } void CDicVfryDlg::OnCancel() { } void CDicVfryDlg::OnClose() { CDialog::OnCancel(); } ////////////////////////////////////////////////////////////////////////// // CMyVerifyClass methods // Check the status of the process L_VOID CMyVerifyClass::OnStatus(L_UINT uStatus, L_INT nErrorCode) { CString sStatus; CDicVfryDlg* pDlg = (CDicVfryDlg*) m_pWnd; if (pDlg) { // Get the text in the status edit box pDlg->GetDlgItem(IDC_EDIT_STATUS)->GetWindowText(sStatus); // If general DICOM error if (uStatus == VRFY_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; // Kill the timer pDlg->KillTimer(ID_TIMEOUT_TIMER); // Enable the controls pDlg->EnableDisableControl(TRUE); } else { // Get the current status related text sStatus += GetStatusText(uStatus) + "\r\n"; } // Show the status in the staus edit box pDlg->GetDlgItem(IDC_EDIT_STATUS)->SetWindowText(sStatus); } } CString CMyVerifyClass::GetStatusText(L_UINT uStatusConst) { int iCounter; int iLength = sizeof(StatusArray) / sizeof(StatusArray[0]); // Determination of the text that should appear in the status edit box for (iCounter = 0; iCounter < iLength - 1; iCounter++) { if (StatusArray[iCounter].uStatusID == uStatusConst) { // Whether the process is to be finished or not if (StatusArray[iCounter].bFinish) { CDicVfryDlg* pDlg = (CDicVfryDlg*) m_pWnd; if (pDlg) { // Kill the timer pDlg->KillTimer(ID_TIMEOUT_TIMER); // Enable the controls pDlg->EnableDisableControl(TRUE); } } return StatusArray[iCounter].pszDescription; } } return ""; } L_VOID CDicVfryDlg::EnableDisableControl(L_BOOL bEnable) { // Enable/Disable the controls m_Edit_ServerName.EnableWindow(bEnable); m_AbortButton.EnableWindow(!bEnable); m_Edit_ServerPort.EnableWindow(bEnable); m_cServerIPAddress.EnableWindow(bEnable); m_Edit_ClientName.EnableWindow(bEnable); m_Edit_TimeOut.EnableWindow(bEnable); m_VerifyButton.EnableWindow(bEnable); return; } void CDicVfryDlg::OnChangeEditSvrName() { // Check Whether enable or disable the verify button m_VerifyButton.EnableWindow(EnabledVerify()); } void CDicVfryDlg::OnChangeEditClientName() { // Check Whether enable or disable the verify button m_VerifyButton.EnableWindow(EnabledVerify()); } // Check whether to enable or disable the Verify button L_BOOL CDicVfryDlg::EnabledVerify() { UpdateData(TRUE); if ((lstrlen(m_sServerName) > 0) && (lstrlen(m_sClientName) > 0)) // Verify button should be enabled return TRUE; else // Verify button should be disabled return FALSE; } // Save the data in the registry L_VOID CDicVfryDlg::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 DWORD dwServerIP; m_cServerIPAddress.GetAddress(dwServerIP); m_cMyRegKey.SetValue(dwServerIP, "dwServerIP"); // Server port number m_cMyRegKey.SetValue(m_uServerPort, "uServerPort"); // Client Name m_cMyRegKey.SetValue(m_sClientName, "sClientName"); // Time Out (Seconds) m_cMyRegKey.SetValue(m_uTimeOut, "uTimeOut"); } } // Read data from the registry L_VOID CDicVfryDlg::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; } DWORD dwValue; // Server IP lRet = m_cMyRegKey.QueryValue(dwValue, "dwServerIP"); if (lRet == ERROR_SUCCESS) { m_dwServerIP = 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 (Seconds) lRet = m_cMyRegKey.QueryValue(dwValue, "uTimeOut"); if (lRet == ERROR_SUCCESS) { m_uTimeOut = dwValue; } } } void CDicVfryDlg::OnButtonCancel() { CDialog::OnCancel(); } void CDicVfryDlg::OnDestroy() { CDialog::OnDestroy(); }