// UITabDlg.cpp : implementation file // #include "stdafx.h" // #include "DICOM.h" // #include "UITabDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif const WCHAR BASED_CODE _szLicString[] = L"LEADTOOLS OCX Copyright (c) 1991-2004 LEAD Technologies, Inc."; ///////////////////////////////////////////////////////////////////////////// // CUIDTableDlg dialog CUIDTableDlg::CUIDTableDlg(CWnd* pParent /*=NULL*/) : CDialog(CUIDTableDlg::IDD, pParent) { //{{AFX_DATA_INIT(CUIDTableDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CUIDTableDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CUIDTableDlg) DDX_Control(pDX, IDC_COMBO1, m_Combo1); DDX_Control(pDX, IDC_LIST1, m_ListView1); DDX_Control(pDX, IDC_EDIT3, m_Text3); DDX_Control(pDX, IDC_EDIT2, m_Text2); DDX_Control(pDX, IDC_EDIT1, m_Text1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CUIDTableDlg, CDialog) //{{AFX_MSG_MAP(CUIDTableDlg) ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) ON_BN_CLICKED(IDC_BUTTON4, OnButton4) ON_BN_CLICKED(IDC_BUTTON5, OnButton5) ON_BN_CLICKED(IDC_FIRST, OnFirst) ON_BN_CLICKED(IDC_NEXT, OnNext) ON_BN_CLICKED(IDC_PREV, OnPrev) ON_BN_CLICKED(IDC_LAST, OnLast) ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CUIDTableDlg message handlers BOOL CUIDTableDlg::OnInitDialog() { CDialog::OnInitDialog(); m_ListView1.InsertColumn( 1, "Code", LVCFMT_LEFT, 180); m_ListView1.InsertColumn( 2, "Name", LVCFMT_LEFT, 180); BSTR lpLic = SysAllocString(_szLicString); ILEADDicomFactory *pFactory=NULL; CoCreateInstance(CLSID_LEADDicomFactory, NULL, CLSCTX_ALL, IID_ILEADDicomFactory, (void**)&pFactory); #if _MSC_VER < 1200 m_pLEADDicomDS = (ILEADDicomDS*)pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); #else ILEADDicomDSPtr spLEADDicomDS=NULL; spLEADDicomDS = pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); m_pLEADDicomDS = spLEADDicomDS; m_pLEADDicomDS->AddRef();//because when spLEADDicomDS goes out of scope, it will auto Release()! #endif pFactory->Release(); SysFreeString(lpLic); m_pLEADDicomDS->EnableMethodErrors = FALSE; m_Combo1.AddString("Unknown"); m_Combo1.AddString("Transfer Syntax - Uncompressed Image"); m_Combo1.AddString("Transfer Syntax - Compressed Image"); m_Combo1.AddString("SOP Class"); m_Combo1.AddString("Meta SOP Class"); m_Combo1.AddString("SOP Instance"); m_Combo1.AddString("Application Context Name"); m_Combo1.SetCurSel(0); FillList(); DisplayItem(); m_ListView1.SetFocus(); return FALSE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CUIDTableDlg::FillList() { long lCount; long nIndex=-1; CString szItem; short nRet; //get the UID Item count lCount = m_pLEADDicomDS->GetUIDCount(); //get the first UID Item nRet = m_pLEADDicomDS->MoveFirstUID(); while(nRet == 0) { IDicomUIDItemPtr pCurrentUID=NULL; //add item to the ListView control pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); BSTR bstr=pCurrentUID->GetCode(); szItem = bstr; SysFreeString(bstr); nIndex = m_ListView1.InsertItem(nIndex+1, szItem); szItem =(LPCSTR)pCurrentUID->GetName(); m_ListView1.SetItemText(nIndex, 1, szItem); nRet = m_pLEADDicomDS->MoveNextUID(); } //m_ListView1.SetItemState(0, LVIS_SELECTED, LVIF_STATE); m_ListView1.SetItemState( 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED ); m_ListView1.SetFocus(); m_ListView1.Update(0); m_nSelectedItem = 0; } void CUIDTableDlg::DisplayItem() { IDicomUIDItemPtr pCurrentUID=NULL; pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); if(pCurrentUID == NULL) return; //display the items information BSTR bstr = pCurrentUID->GetCode(); CString cs = bstr; SysFreeString(bstr); m_Text1.SetWindowText(cs); cs = (LPCSTR)pCurrentUID->GetName(); m_Text2.SetWindowText(cs); m_Combo1.SetCurSel(pCurrentUID->GetType()); } void CUIDTableDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; CString szCode; if((pNMListView->uNewState & LVIS_SELECTED)==LVIS_SELECTED) { m_nSelectedItem = pNMListView->iItem; szCode = m_ListView1.GetItemText(pNMListView->iItem, 0); //move to the selected UID BSTR bstr = szCode.AllocSysString(); m_pLEADDicomDS->FindUID(bstr); SysFreeString(bstr); DisplayItem(); } *pResult = 0; } void CUIDTableDlg::OnButton1() { HCURSOR hOldCursor=NULL; m_ListView1.DeleteAllItems(); hOldCursor = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); m_pLEADDicomDS->DefaultUID(); FillList(); SetCursor(hOldCursor); DisplayItem(); } void CUIDTableDlg::OnButton2() { m_ListView1.DeleteAllItems(); //Clear all items from the UID Table m_pLEADDicomDS->ResetUID(); } void CUIDTableDlg::OnButton3() { short nRet; CString szCode; CString szName; IDicomUIDItemPtr pCurrentUID=NULL; int nIndex; CString szItem; m_Text1.GetWindowText(szCode); BSTR bstr = szCode.AllocSysString(); nRet = m_pLEADDicomDS->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { AfxMessageBox("Already Exists!"); return; } m_Text2.GetWindowText(szName); BSTR bstr1 = szCode.AllocSysString(); BSTR bstr2 = szName.AllocSysString(); nRet = m_pLEADDicomDS->InsertUID(bstr1, bstr2, m_Combo1.GetCurSel()); SysFreeString(bstr1); SysFreeString(bstr2); if(nRet != 0) { AfxMessageBox("Error"); return; } //add item to the ListView control pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); pCurrentUID->Type = m_Combo1.GetCurSel(); bstr = pCurrentUID->GetCode(); szItem = bstr; SysFreeString(bstr); nIndex = m_ListView1.InsertItem(m_ListView1.GetItemCount(), szItem); szItem = (LPCSTR)pCurrentUID->GetName(); m_ListView1.SetItemText(nIndex, 1, szItem); DisplayItem(); m_ListView1.SetItemState(nIndex, LVIS_SELECTED, LVIF_STATE); m_ListView1.Update(nIndex); m_nSelectedItem = nIndex; } void CUIDTableDlg::OnButton4() { CString szCode; short nRet; szCode = m_ListView1.GetItemText(m_nSelectedItem, 0); //move to the selected UID BSTR bstr = szCode.AllocSysString(); m_pLEADDicomDS->FindUID(bstr); SysFreeString(bstr); //delete it nRet = m_pLEADDicomDS->DeleteUID(); if(nRet != 0) { AfxMessageBox("Error"); return; } //remove it from the list view control m_ListView1.DeleteItem(m_nSelectedItem); if(m_nSelectedItem>0) m_nSelectedItem--; else m_nSelectedItem++; m_ListView1.SetItemState(m_nSelectedItem, LVIS_SELECTED, LVIF_STATE); m_ListView1.Update(m_nSelectedItem); } void CUIDTableDlg::OnButton5() { CString szName; IDicomUIDItemPtr pCurrentUID=NULL; //move to the selected UID m_pLEADDicomDS->FindIndexUID(m_nSelectedItem); //change the name m_Text3.GetWindowText(szName); BSTR bstr = szName.AllocSysString(); m_pLEADDicomDS->SetUIDName(bstr); SysFreeString(bstr); //update it in the list view control DisplayItem(); pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); if(pCurrentUID) { CString cs = (LPCSTR)pCurrentUID->GetName(); m_ListView1.SetItemText(m_nSelectedItem, 1, cs); } } void CUIDTableDlg::OnFirst() { if(m_pLEADDicomDS->MoveFirstUID()==0) { UpdateList(); DisplayItem(); } } void CUIDTableDlg::OnNext() { if(m_pLEADDicomDS->MoveNextUID()==0) { UpdateList(); DisplayItem(); } m_ListView1.SetFocus(); } void CUIDTableDlg::OnPrev() { if(m_pLEADDicomDS->MovePrevUID()==0) { UpdateList(); DisplayItem(); } m_ListView1.SetFocus(); } void CUIDTableDlg::OnLast() { if(m_pLEADDicomDS->MoveLastUID()==0) { UpdateList(); DisplayItem(); } } void CUIDTableDlg::UpdateList() { LV_FINDINFO lvfind; CString szCode; IDicomUIDItemPtr pCurrentUID=NULL; int nIndex; pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); BSTR bstr = pCurrentUID->GetCode(); szCode = bstr; SysFreeString(bstr); memset(&lvfind, 0, sizeof(LV_FINDINFO)); lvfind.flags = LVFI_STRING; lvfind.psz = szCode; nIndex = m_ListView1.FindItem(&lvfind, -1); if(nIndex >= 0) { m_ListView1.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED ); m_ListView1.Update(nIndex); m_ListView1.EnsureVisible(nIndex, FALSE); m_nSelectedItem = nIndex; m_ListView1.SetFocus(); } } void CUIDTableDlg::OnClose() { if(m_pLEADDicomDS) m_pLEADDicomDS->Release(); CDialog::OnClose(); }