// PresDlg.cpp : implementation file // #include "stdafx.h" #include "dclient.h" #include "PresDlg.h" const WCHAR BASED_CODE _szLicString[] = LEAD_LICENSE_STRING; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif static UINT BITMAPLIST[] = { IDB_UNSELECT, IDB_SELECT, }; #define BMP_UNSELECTED 0 #define BMP_SELECTED 1 ///////////////////////////////////////////////////////////////////////////// // CPresentationContextDlg dialog CPresentationContextDlg::CPresentationContextDlg(CWnd* pParent /*=NULL*/) : CDialog(CPresentationContextDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPresentationContextDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_hPDU=0; m_nID=0; m_szAbstract=""; } void CPresentationContextDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPresentationContextDlg) DDX_Control(pDX, IDC_TRANSFER, m_Transfer); DDX_Control(pDX, IDC_PROVIDER, m_Provider); DDX_Control(pDX, IDC_USER, m_User); DDX_Control(pDX, IDC_TRANSFERUID_LIST, m_TransferUIDList); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPresentationContextDlg, CDialog) //{{AFX_MSG_MAP(CPresentationContextDlg) ON_NOTIFY(NM_CLICK, IDC_TRANSFER, OnClickTransfer) ON_NOTIFY(NM_DBLCLK, IDC_TRANSFER, OnDblclkTransfer) ON_NOTIFY(TVN_SELCHANGED, IDC_TRANSFER, OnSelchangedTransfer) ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPresentationContextDlg message handlers BOOL CPresentationContextDlg::OnInitDialog() { CDialog::OnInitDialog(); int i; CBitmap Bitmap; short nRet; HTREEITEM hItem=NULL; long nType; short nRole; long lBytes; VARIANT ExtData; VariantInit(&ExtData); CString szOut; long n; BYTE byte; CString szTemp; short x; short y; CString szTransfer; int index; if((m_nID==0)||(m_hPDU==0)) { EndDialog(IDCANCEL); return FALSE; } m_Image.Create(12, 12, ILC_MASK, 0, sizeof(BITMAPLIST) / sizeof(BITMAPLIST[0])); for (i = 0; i < sizeof(BITMAPLIST) / sizeof(BITMAPLIST[0]); i++) { Bitmap.LoadBitmap(BITMAPLIST[i]); m_Image.Add(&Bitmap, (COLORREF)0xFFFFFF); Bitmap.DeleteObject(); } m_Transfer.SetImageList(&m_Image, TVSIL_NORMAL); m_bMouse = FALSE; //******************************* BSTR lpLic = SysAllocString(_szLicString); ILEADDicomFactory *pFactory=NULL; CoCreateInstance(CLSID_LEADDicomFactory, NULL, CLSCTX_ALL, IID_ILEADDicomFactory, (void**)&pFactory); #if _MSC_VER < 1200 m_pLEADDicomNet = (ILEADDicomDS*)pFactory->CreateObject("LEADDicomNet.LEADDicomNet", lpLic); #else ILEADDicomNetPtr spLEADDicomNet=NULL; spLEADDicomNet = pFactory->CreateObject("LEADDicomNet.LEADDicomNet", lpLic); m_pLEADDicomNet = spLEADDicomNet; // m_pLEADDicomNet->AddRef();//because when spLEADDicomNet goes out of scope, it will auto Release()! #endif #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 //************************** m_pLEADDicomNet->EnableMethodErrors = FALSE; m_pLEADDicomDS->EnableMethodErrors = FALSE; //add all Transfer Syntaxes to the list nRet = m_pLEADDicomDS->MoveFirstUID(); while(nRet == 0) { IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); nType = pCurrentUID->GetType(); if((nType == DICOM_UID_TYPE_TRANSFER1)||(nType == DICOM_UID_TYPE_TRANSFER2)) { BSTR bstr = pCurrentUID->GetName(); CString cs = bstr; SysFreeString(bstr); hItem = m_Transfer.InsertItem(cs, BMP_UNSELECTED, BMP_UNSELECTED, TVI_ROOT, TVI_LAST); bstr = pCurrentUID->GetCode(); cs = bstr; SysFreeString(bstr); index = m_TransferUIDList.AddString(cs); m_Transfer.SetItemData(hItem, index); } nRet = m_pLEADDicomDS->MoveNextUID(); } BSTR bstr = m_szAbstract.AllocSysString(); nRet = m_pLEADDicomDS->FindUID(bstr); SysFreeString(bstr); if(nRet != 0) { EndDialog(IDCANCEL); return FALSE; } IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); bstr = pCurrentUID->GetName(); CString cs = bstr; SysFreeString(bstr); SetDlgItemText(IDC_NAME, cs); SetDlgItemText(IDC_CODE, m_szAbstract); nRole = m_pLEADDicomNet->GetUserRole(m_hPDU, m_nID); m_User.SetCurSel(nRole); nRole = m_pLEADDicomNet->GetProviderRole(m_hPDU, m_nID); m_Provider.SetCurSel(nRole); if(m_pLEADDicomNet->IsRoleSelect(m_hPDU, m_nID)) CheckDlgButton(IDC_B_ROLE, 1); else CheckDlgButton(IDC_B_ROLE, 0); lBytes = m_pLEADDicomNet->GetExtendedDataLength(m_hPDU, m_nID); if(lBytes > 0) { ExtData = m_pLEADDicomNet->GetExtendedData(m_hPDU, m_nID); szOut = ""; for(n=0; n<6; n++) // 6 byte max { if(n>=lBytes) break; SafeArrayGetElement(ExtData.parray, &n, &byte); switch(n) { case 0: SetDlgItemInt(IDC_EXTENDED0, byte, FALSE); break; case 1: SetDlgItemInt(IDC_EXTENDED1, byte, FALSE); break; case 2: SetDlgItemInt(IDC_EXTENDED2, byte, FALSE); break; case 3: SetDlgItemInt(IDC_EXTENDED3, byte, FALSE); break; case 4: SetDlgItemInt(IDC_EXTENDED4, byte, FALSE); break; case 5: SetDlgItemInt(IDC_EXTENDED5, byte, FALSE); break; } } } VariantClear(&ExtData); hItem = NULL; for(x=0; xGetTransferCount(m_hPDU, m_nID); y++) { BSTR bstr = m_pLEADDicomNet->GetTransferSyntax(m_hPDU, m_nID, y); szTransfer = bstr; SysFreeString(bstr); if(szTransfer == szTemp) { m_Transfer.SetItem(hItem, TVIF_IMAGE|TVIF_SELECTEDIMAGE, NULL, BMP_SELECTED, BMP_SELECTED, 0, 0, 0); break; } } } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CPresentationContextDlg::OnOK() { long lBytes; VARIANT ExtData; long lCount=0; HTREEITEM hItem=NULL; hItem = m_Transfer.GetRootItem(); while(hItem) { lCount++; hItem = m_Transfer.GetNextItem(hItem, TVGN_NEXT); } if(lCount < 1) { MessageBox("At least one Transfer Syntax must be selected!", "Warning", MB_OK); return; } if(IsDlgButtonChecked(IDC_B_ROLE) == 1) m_pLEADDicomNet->SetRoleSelect(m_hPDU, m_nID, TRUE, m_User.GetCurSel(), m_Provider.GetCurSel()); else m_pLEADDicomNet->SetRoleSelect(m_hPDU, m_nID, FALSE, m_User.GetCurSel(), m_Provider.GetCurSel()); lBytes = 0; CString sz0, sz1, sz2, sz3, sz4, sz5; BYTE b[6]={0,0,0,0,0,0}; GetDlgItemText(IDC_EXTENDED0, sz0); GetDlgItemText(IDC_EXTENDED1, sz1); GetDlgItemText(IDC_EXTENDED2, sz2); GetDlgItemText(IDC_EXTENDED3, sz3); GetDlgItemText(IDC_EXTENDED4, sz4); GetDlgItemText(IDC_EXTENDED5, sz5); if(sz0.GetLength()>0) lBytes=1; if(sz1.GetLength()>0) lBytes=2; if(sz2.GetLength()>0) lBytes=3; if(sz3.GetLength()>0) lBytes=4; if(sz4.GetLength()>0) lBytes=5; if(sz5.GetLength()>0) lBytes=6; if(lBytes>0) { b[0] = (BYTE)GetDlgItemInt(IDC_EXTENDED0, NULL, FALSE); b[1] = (BYTE)GetDlgItemInt(IDC_EXTENDED1, NULL, FALSE); b[2] = (BYTE)GetDlgItemInt(IDC_EXTENDED2, NULL, FALSE); b[3] = (BYTE)GetDlgItemInt(IDC_EXTENDED3, NULL, FALSE); b[4] = (BYTE)GetDlgItemInt(IDC_EXTENDED4, NULL, FALSE); b[5] = (BYTE)GetDlgItemInt(IDC_EXTENDED5, NULL, FALSE); SAFEARRAY FAR *psa; SAFEARRAYBOUND rgsabound[1]; VariantInit(&ExtData); rgsabound[0].lLbound = 0; rgsabound[0].cElements = lBytes; psa = SafeArrayCreate(VT_UI1, 1, rgsabound); if (psa != NULL) { SafeArrayLock(psa); memcpy(psa->pvData, b, lBytes); SafeArrayUnlock(psa); V_VT(&ExtData) = (VT_ARRAY | VT_UI1); V_ARRAY(&ExtData) = psa; m_pLEADDicomNet->SetExtendedData(m_hPDU, m_nID, &ExtData, lBytes); SafeArrayDestroy(psa); } else m_pLEADDicomNet->SetExtendedData(m_hPDU, m_nID, &ExtData, 0); VariantClear(&ExtData); } CDialog::OnOK(); } void CPresentationContextDlg::OnClickTransfer(NMHDR* pNMHDR, LRESULT* pResult) { HTREEITEM hItem; int nImage1; int nImage2; if(pNMHDR->idFrom == IDC_TRANSFER) { hItem = m_Transfer.GetSelectedItem(); if(hItem != NULL) { m_Transfer.GetItemImage(hItem, nImage1, nImage2); if(nImage1 == BMP_SELECTED) { m_Transfer.SetItemImage(hItem, BMP_UNSELECTED, BMP_UNSELECTED); RemoveTransfer(hItem); } else { m_Transfer.SetItemImage(hItem, BMP_SELECTED, BMP_SELECTED); AddTransfer(hItem); } m_bMouse = TRUE; } } *pResult = 0; } void CPresentationContextDlg::OnDblclkTransfer(NMHDR* pNMHDR, LRESULT* pResult) { HTREEITEM hItem; int nImage1; int nImage2; if(pNMHDR->idFrom == IDC_TRANSFER) { hItem = m_Transfer.GetSelectedItem(); if(hItem != NULL) { m_Transfer.GetItemImage(hItem, nImage1, nImage2); if(nImage1 == BMP_SELECTED) { m_Transfer.SetItemImage(hItem, BMP_UNSELECTED, BMP_UNSELECTED); RemoveTransfer(hItem); } else { m_Transfer.SetItemImage(hItem, BMP_SELECTED, BMP_SELECTED); AddTransfer(hItem); } } } *pResult = 0; } void CPresentationContextDlg::OnSelchangedTransfer(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; int nImage1; int nImage2; if(m_bMouse != FALSE) { m_Transfer.GetItemImage(pNMTreeView->itemOld.hItem, nImage1, nImage2); if(nImage1 == BMP_SELECTED) { m_Transfer.SetItemImage(pNMTreeView->itemOld.hItem, BMP_UNSELECTED, BMP_UNSELECTED); RemoveTransfer(pNMTreeView->itemOld.hItem); } else { m_Transfer.SetItemImage(pNMTreeView->itemOld.hItem, BMP_SELECTED, BMP_SELECTED); AddTransfer(pNMTreeView->itemOld.hItem); } m_bMouse = FALSE; } *pResult = 0; } void CPresentationContextDlg::AddTransfer(HTREEITEM hItem) { short nRet; int index; CString szTransfer; index = (int)m_Transfer.GetItemData(hItem); m_TransferUIDList.GetText(index, szTransfer); //add a transfer syntax BSTR bstr = szTransfer.AllocSysString(); nRet = m_pLEADDicomNet->AddTransferSyntax(m_hPDU, m_nID, bstr); SysFreeString(bstr); return; } void CPresentationContextDlg::RemoveTransfer(HTREEITEM hItem) { long x; int index; CString szTransfer; index = (int)m_Transfer.GetItemData(hItem); m_TransferUIDList.GetText(index, szTransfer); //remove a transfer syntax for(x=0; xGetTransferCount(m_hPDU, m_nID); x++) { if(szTransfer == m_pLEADDicomNet->GetTransferSyntax(m_hPDU, m_nID, x)) m_pLEADDicomNet->DeleteTransferSyntax(m_hPDU, m_nID, x); } return; } void CPresentationContextDlg::OnClose() { if(m_pLEADDicomNet) m_pLEADDicomNet->Release(); if(m_pLEADDicomDS) m_pLEADDicomDS->Release(); m_pLEADDicomNet=NULL; m_pLEADDicomDS=NULL; CDialog::OnClose(); }