// TaTabDlg.cpp : implementation file // #include "stdafx.h" // #include "DICOM.h" // #include "TaTabDlg.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."; ///////////////////////////////////////////////////////////////////////////// // CTagTableDlg dialog CTagTableDlg::CTagTableDlg(CWnd* pParent /*=NULL*/) : CDialog(CTagTableDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTagTableDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CTagTableDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTagTableDlg) DDX_Control(pDX, IDC_EDIT8, m_Text8); DDX_Control(pDX, IDC_EDIT7, m_Text7); DDX_Control(pDX, IDC_EDIT6, m_Text6); DDX_Control(pDX, IDC_EDIT5, m_Text5); DDX_Control(pDX, IDC_EDIT4, m_Text4); DDX_Control(pDX, IDC_EDIT3, m_Text3); DDX_Control(pDX, IDC_EDIT2, m_Text2); DDX_Control(pDX, IDC_EDIT1, m_Text1); DDX_Control(pDX, IDC_LIST1, m_ListView1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTagTableDlg, CDialog) //{{AFX_MSG_MAP(CTagTableDlg) ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1) 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_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_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTagTableDlg message handlers BOOL CTagTableDlg::OnInitDialog() { CDialog::OnInitDialog(); m_ListView1.InsertColumn( 1, "Code", LVCFMT_LEFT, 65); m_ListView1.InsertColumn( 2, "Mask", LVCFMT_LEFT, 65); m_ListView1.InsertColumn( 3, "Name", LVCFMT_LEFT, 120); m_ListView1.InsertColumn( 4, "VR", LVCFMT_LEFT, 50); m_ListView1.InsertColumn( 5, "MinVM", LVCFMT_LEFT, 50); m_ListView1.InsertColumn( 6, "MaxVM", LVCFMT_LEFT, 50); m_ListView1.InsertColumn( 7, "DivideVM", LVCFMT_LEFT, 50); 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; 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 CTagTableDlg::FillList() { long lCount; long nIndex=-1; ILEADDicomTagPtr pCurrentTag=NULL; CString szItem; short nRet; //get the Tag Item count lCount = m_pLEADDicomDS->GetTagCount(); //get the first Tag nRet = m_pLEADDicomDS->MoveFirstTag(); while(nRet == 0) { //add item to the ListView control pCurrentTag = m_pLEADDicomDS->GetCurrentTag(); szItem.Format("%04X:%04X", GETGROUP(pCurrentTag->GetCode()), GETELEMENT(pCurrentTag->GetCode())); nIndex = m_ListView1.InsertItem(nIndex+1, szItem); szItem.Format("%04X:%04X", GETGROUP(pCurrentTag->GetMask()), GETELEMENT(pCurrentTag->GetMask())); m_ListView1.SetItemText(nIndex, 1, szItem); szItem = (LPCSTR)pCurrentTag->GetName(); m_ListView1.SetItemText(nIndex, 2, szItem); szItem.Format("%d", pCurrentTag->GetVR()); m_ListView1.SetItemText(nIndex, 3, szItem); szItem.Format("%d", pCurrentTag->GetMinVM()); m_ListView1.SetItemText(nIndex, 4, szItem); szItem.Format("%d", pCurrentTag->GetMaxVM()); m_ListView1.SetItemText(nIndex, 5, szItem); szItem.Format("%d", pCurrentTag->GetDivideVM()); m_ListView1.SetItemText(nIndex, 6, szItem); m_ListView1.SetItemData(nIndex, pCurrentTag->GetCode()); nRet = m_pLEADDicomDS->MoveNextTag(); } m_ListView1.SetItemState( 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED ); m_ListView1.SetFocus(); m_ListView1.Update(0); m_nSelectedItem = 0; } void CTagTableDlg::DisplayItem() { CString szOut; ILEADDicomTagPtr pCurrentTag=NULL; pCurrentTag = m_pLEADDicomDS->GetCurrentTag(); szOut.Format("%04X:%04X", GETGROUP(pCurrentTag->GetCode()), GETELEMENT(pCurrentTag->GetCode())); m_Text1.SetWindowText(szOut); szOut.Format("%04X:%04X", GETGROUP(pCurrentTag->GetMask()), GETELEMENT(pCurrentTag->GetMask())); m_Text2.SetWindowText(szOut); CString cs = (LPCSTR)pCurrentTag->GetName(); m_Text3.SetWindowText(cs); //display the items information switch(pCurrentTag->GetVR()) { case VR_AE: m_Text4.SetWindowText("AE"); break; case VR_AS: m_Text4.SetWindowText("AS"); break; case VR_AT: m_Text4.SetWindowText("AT"); break; case VR_CS: m_Text4.SetWindowText("CS"); break; case VR_DA: m_Text4.SetWindowText("DA"); break; case VR_DS: m_Text4.SetWindowText("DS"); break; case VR_DT: m_Text4.SetWindowText("DT"); break; case VR_FD: m_Text4.SetWindowText("FD"); break; case VR_FL: m_Text4.SetWindowText("FL"); break; case VR_IS: m_Text4.SetWindowText("IS"); break; case VR_LO: m_Text4.SetWindowText("LO"); break; case VR_LT: m_Text4.SetWindowText("LT"); break; case VR_OB: m_Text4.SetWindowText("OB"); break; case VR_OW: m_Text4.SetWindowText("OW"); break; case VR_PN: m_Text4.SetWindowText("PN"); break; case VR_SH: m_Text4.SetWindowText("SH"); break; case VR_SL: m_Text4.SetWindowText("SL"); break; case VR_SQ: m_Text4.SetWindowText("SQ"); break; case VR_SS: m_Text4.SetWindowText("SS"); break; case VR_ST: m_Text4.SetWindowText("ST"); break; case VR_TM: m_Text4.SetWindowText("TM"); break; case VR_UI: m_Text4.SetWindowText("UI"); break; case VR_UL: m_Text4.SetWindowText("UL"); break; case VR_UN: m_Text4.SetWindowText("UN"); break; case VR_US: m_Text4.SetWindowText("US"); break; case VR_UT: m_Text4.SetWindowText("UT"); break; default: szOut.Format("%d", pCurrentTag->GetCode()); m_Text4.SetWindowText(szOut); break; } szOut.Format("%d", pCurrentTag->GetMinVM()); m_Text5.SetWindowText(szOut); szOut.Format("%d", pCurrentTag->GetMaxVM()); m_Text6.SetWindowText(szOut); szOut.Format("%d", pCurrentTag->GetDivideVM()); m_Text7.SetWindowText(szOut); } void CTagTableDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; long lCode; if((pNMListView->uNewState & LVIS_SELECTED)==LVIS_SELECTED) { m_nSelectedItem = pNMListView->iItem; lCode = (long)m_ListView1.GetItemData(pNMListView->iItem); //move to the selected Tag m_pLEADDicomDS->FindTag(lCode); DisplayItem(); } *pResult = 0; } void CTagTableDlg::OnFirst() { if(m_pLEADDicomDS->MoveFirstTag()==0) { UpdateList(); DisplayItem(); } } void CTagTableDlg::OnNext() { if(m_pLEADDicomDS->MoveNextTag()==0) { UpdateList(); DisplayItem(); } m_ListView1.SetFocus(); } void CTagTableDlg::OnPrev() { if(m_pLEADDicomDS->MovePrevTag()==0) { UpdateList(); DisplayItem(); } m_ListView1.SetFocus(); } void CTagTableDlg::OnLast() { if(m_pLEADDicomDS->MoveLastTag()==0) { UpdateList(); DisplayItem(); } } void CTagTableDlg::UpdateList() { LV_FINDINFO lvfind; long lCode; ILEADDicomTagPtr pCurrentTag=NULL; int nIndex; pCurrentTag = m_pLEADDicomDS->GetCurrentTag(); lCode = pCurrentTag->GetCode(); memset(&lvfind, 0, sizeof(LV_FINDINFO)); lvfind.flags = LVFI_PARAM; lvfind.lParam = lCode; nIndex = m_ListView1.FindItem(&lvfind, -1); if(nIndex >= 0) { m_ListView1.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED ); m_ListView1.SetFocus(); m_ListView1.Update(nIndex); m_ListView1.EnsureVisible(nIndex, FALSE); m_nSelectedItem = nIndex; } } void CTagTableDlg::OnButton1() { HCURSOR hOldCursor=NULL; m_ListView1.DeleteAllItems(); hOldCursor = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); m_pLEADDicomDS->DefaultTag(); FillList(); SetCursor(hOldCursor); DisplayItem(); } void CTagTableDlg::OnButton2() { m_ListView1.DeleteAllItems(); //Clear all items from the UID Table m_pLEADDicomDS->ResetTag(); } void CTagTableDlg::OnButton3() { short nRet; ILEADDicomTagPtr pCurrentTag=NULL; int nIndex; CString szItem; long lCode; long lMask; short nVR; short nMinVM; short nMaxVM; short nDivideVM; CString szCode; CString szName; m_Text1.GetWindowText(szCode); lCode = atoi(szCode); nRet = m_pLEADDicomDS->FindTag(lCode); if(nRet == 0) { AfxMessageBox("Already Exists!"); return; } m_Text2.GetWindowText(szCode); lMask = atoi(szCode); m_Text3.GetWindowText(szName); m_Text4.GetWindowText(szCode); nVR = atoi(szCode); m_Text5.GetWindowText(szCode); nMinVM = atoi(szCode); m_Text6.GetWindowText(szCode); nMaxVM = atoi(szCode); m_Text7.GetWindowText(szCode); nDivideVM = atoi(szCode); BSTR bstr = szName.AllocSysString(); nRet = m_pLEADDicomDS->InsertTag(lCode, lMask, bstr, nVR, nMinVM, nMaxVM, nDivideVM); SysFreeString(bstr); if(nRet != 0) { AfxMessageBox("Error"); return; } //add item to the ListView control pCurrentTag = m_pLEADDicomDS->GetCurrentTag(); szItem.Format("%04X:%04X", GETGROUP(pCurrentTag->GetCode()), GETELEMENT(pCurrentTag->GetCode())); nIndex = m_ListView1.InsertItem(m_ListView1.GetItemCount(), szItem); szItem.Format("%04X:%04X", GETGROUP(pCurrentTag->GetMask()), GETELEMENT(pCurrentTag->GetMask())); m_ListView1.SetItemText(nIndex, 1, szItem); szItem = (LPCSTR)pCurrentTag->GetName(); m_ListView1.SetItemText(nIndex, 2, szItem); szItem.Format("%d", pCurrentTag->GetVR()); m_ListView1.SetItemText(nIndex, 3, szItem); szItem.Format("%d", pCurrentTag->GetMinVM()); m_ListView1.SetItemText(nIndex, 4, szItem); szItem.Format("%d", pCurrentTag->GetMaxVM()); m_ListView1.SetItemText(nIndex, 5, szItem); szItem.Format("%d", pCurrentTag->GetDivideVM()); m_ListView1.SetItemText(nIndex, 6, szItem); m_ListView1.SetItemState(nIndex, LVIS_SELECTED, LVIF_STATE); m_ListView1.Update(nIndex); } void CTagTableDlg::OnButton4() { long lCode; short nRet; lCode = (long)m_ListView1.GetItemData(m_nSelectedItem); //move to the selected Tag m_pLEADDicomDS->FindTag(lCode); //delete it nRet = m_pLEADDicomDS->DeleteTag(); 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 CTagTableDlg::OnButton5() { CString szName; ILEADDicomTagPtr pCurrentTag=NULL; //move to the selected Tag m_pLEADDicomDS->FindIndexTag(m_nSelectedItem); pCurrentTag = m_pLEADDicomDS->GetCurrentTag(); if(pCurrentTag == NULL) return; //change the name m_Text8.GetWindowText(szName); BSTR bstr = szName.AllocSysString(); m_pLEADDicomDS->SetTagName(bstr); SysFreeString(bstr); //update it in the list view control DisplayItem(); m_ListView1.SetItemText(m_nSelectedItem, 2, pCurrentTag->GetName()); } void CTagTableDlg::OnClose() { if(m_pLEADDicomDS) m_pLEADDicomDS->Release(); CDialog::OnClose(); }