#include "dicsrv.h" char gszMdbFileFolder[MAX_PATH]; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int iCmdShow) { char* pBackslash; UNLOCKSUPPORT(); L_DlgInit(DLG_INIT_COLOR); if (GetModuleFileName(NULL, gszApplicationFolder, sizeof(gszApplicationFolder) / sizeof(TCHAR))) { pBackslash = strrchr(gszApplicationFolder, '\\'); if (pBackslash) *(pBackslash + 1) = '\0'; } if (!LoadServerSettings()) // Failed to load the server settings? { // Set some initial values wsprintf(gszMdbFileFolder, TEXT("%s%s"), gszApplicationFolder, DEFAULT_IMAGES_FOLDERNAME); wsprintf(gszImagesFolder, TEXT("%s%s"), gszApplicationFolder, DEFAULT_IMAGES_FOLDERNAME); wsprintf(gszTempFilesFolder, TEXT("%s%s"), gszApplicationFolder, DEFAULT_TEMP_FOLDERNAME); // Display the dialog box if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), NULL, ConfigDlgProc) != IDOK) { L_DlgFree(); return 0; } // The DICOM images folder gbSaveServerSettings = PrepareFolder(gszImagesFolder, DEFAULT_IMAGES_FOLDERNAME); // The temporary files folder gbSaveServerSettings = PrepareFolder(gszTempFilesFolder, DEFAULT_TEMP_FOLDERNAME) && gbSaveServerSettings; // Private key password memset(gszPrivateKeyPassword, 0, sizeof(gszPrivateKeyPassword)); gbValidPrivateKeyPassword = FALSE; if (!PrepareDatabase(gszMdbFileFolder)) { L_DlgFree(); return 0; } // Set default values for the other server settings lstrcpy(gszServerAETitle, "LEAD_SERVER"); guServerPort = 104; giTimeOut = 1; giMaxClients = 5; gbGenerateEventsLogFile = TRUE; gbSaveReceivedCSs = TRUE; gbSaveReceivedDSs = FALSE; gbSaveSentDSs = FALSE; wsprintf(gszLogFolder, TEXT("%s%s"), gszApplicationFolder, DEFAULT_LOGS_FOLDERNAME); PrepareFolder(gszLogFolder, NULL); } else { gbSaveServerSettings = TRUE; PrepareFolder(gszImagesFolder, DEFAULT_IMAGES_FOLDERNAME); PrepareFolder(gszTempFilesFolder, DEFAULT_TEMP_FOLDERNAME); PrepareFolder(gszLogFolder, DEFAULT_LOGS_FOLDERNAME); } ghInstance = hInstance; gSecureMode = DICOM_SECURE_NONE; InitCommonControls(); // Display the main dialog box DialogBox(hInstance, MAKEINTRESOURCE(IDD_DICOMSRV_DIALOG), NULL, ServerDlgProc); L_DlgFree(); return 0; } BOOL CALLBACK ConfigDlgProc(HWND hDlg, UINT uiMessage, WPARAM wParam, LPARAM lParam) { TCHAR szSelectedFolder[MAX_PATH]; switch (uiMessage) { case WM_INITDIALOG: SetDlgItemText(hDlg, IDC_EDIT_MDBFILEFOLDER, gszMdbFileFolder); SetDlgItemText(hDlg, IDC_EDIT_IMAGESFOLDER, gszImagesFolder); SetDlgItemText(hDlg, IDC_EDIT_TEMPFILESFOLDER, gszTempFilesFolder); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDOK: GetDlgItemText(hDlg, IDC_EDIT_MDBFILEFOLDER, gszMdbFileFolder, sizeof(gszMdbFileFolder) / sizeof(gszMdbFileFolder[0])); GetDlgItemText(hDlg, IDC_EDIT_IMAGESFOLDER, gszImagesFolder, sizeof(gszImagesFolder) / sizeof(gszImagesFolder[0])); GetDlgItemText(hDlg, IDC_EDIT_TEMPFILESFOLDER, gszTempFilesFolder, sizeof(gszTempFilesFolder) / sizeof(gszTempFilesFolder[0])); EndDialog(hDlg, IDOK); return TRUE; case IDC_BUTTON_BROWSEMDBFOLDER: if (GetFolder(hDlg, szSelectedFolder, sizeof(szSelectedFolder),TEXT("Select a folder:"))) { SetDlgItemText(hDlg, IDC_EDIT_MDBFILEFOLDER, szSelectedFolder); } return TRUE; case IDC_BUTTON_BROWSEIMGFOLDER: if (GetFolder(hDlg, szSelectedFolder, sizeof(szSelectedFolder),TEXT("Select a folder:"))) { SetDlgItemText(hDlg, IDC_EDIT_IMAGESFOLDER, szSelectedFolder); } return TRUE; case IDC_BUTTON_BROWSETEMPFOLDER: if (GetFolder(hDlg, szSelectedFolder, sizeof(szSelectedFolder),TEXT("Select a folder:"))) { SetDlgItemText(hDlg, IDC_EDIT_TEMPFILESFOLDER, szSelectedFolder); } return TRUE; } } return FALSE; } BOOL CALLBACK ServerDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { WORD wID; LPNMHDR pNMHDR=NULL; switch(uMsg) { case WM_INITDIALOG: InitDialog(hDlg); return FALSE; case WM_CLOSE: if(Unload(hDlg)) return FALSE; return TRUE; case WM_COMMAND: wID = LOWORD(wParam); switch(wID) { case IDOK: case IDCANCEL: if(Unload(hDlg)) EndDialog(hDlg, wID); return TRUE; case IDM_SERVER_ADMINISTRATION: OnServerAdmin(hDlg); return TRUE; case IDM_SERVER_CONNECTIONS: OnServerConnections(hDlg); return TRUE; case IDM_SERVER_LOGOPTIONS: OnServerLoggingOptions(hDlg); return TRUE; case IDM_SERVER_EXIT: if(Unload(hDlg)) EndDialog(hDlg, IDOK); return TRUE; case IDC_BUTTON2: OnImport(hDlg); return TRUE; case IDC_BUTTON3: OnDelete(hDlg); return TRUE; case IDC_BUTTON4: OnCloseClient(hDlg); return TRUE; } return FALSE; case WM_TIMER: OnTimer(hDlg, wParam); break; case WM_NOTIFY: if(ghServerDS) { pNMHDR = (LPNMHDR)lParam; switch(pNMHDR->idFrom) { case IDC_TREE1: switch(pNMHDR->code) { case TVN_SELCHANGED: OnSelchangedTree1(hDlg, pNMHDR); break; case NM_DBLCLK: OnDblclkTree1(hDlg, pNMHDR); break; } break; } } break; case WM_DRAWITEM: if((UINT)wParam == IDC_LEAD1) { DrawImageBtn(hDlg, (LPDRAWITEMSTRUCT)lParam); return TRUE; } break; default: return FALSE; } return FALSE; } VOID EnableLogFolderItems(HWND hDlg) { BOOL bEnable = (IsDlgButtonChecked(hDlg, IDC_CHECK_RECEIVEDCS) == BST_CHECKED) || (IsDlgButtonChecked(hDlg, IDC_CHECK_RECEIVEDDS) == BST_CHECKED) || (IsDlgButtonChecked(hDlg, IDC_CHECK_SENTDS) == BST_CHECKED); EnableWindow(GetDlgItem(hDlg, IDC_STATIC_LOGFOLDER), bEnable); EnableWindow(GetDlgItem(hDlg, IDC_EDIT_LOGFOLDER), bEnable); EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_BROWSE), bEnable); } BOOL CALLBACK LogOptsDlgProc(HWND hDlg, UINT uiMessage, WPARAM wParam, LPARAM lParam) { TCHAR szSelectedFolder[MAX_PATH]; switch (uiMessage) { case WM_INITDIALOG: CheckDlgButton(hDlg, IDC_CHECK_LOGFILE, gbGenerateEventsLogFile ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_CHECK_RECEIVEDCS, gbSaveReceivedCSs ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_CHECK_RECEIVEDDS, gbSaveReceivedDSs ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_CHECK_SENTDS, gbSaveSentDSs ? BST_CHECKED : BST_UNCHECKED); SetDlgItemText(hDlg, IDC_EDIT_LOGFOLDER, gszLogFolder); EnableLogFolderItems(hDlg); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDOK: gbGenerateEventsLogFile = (IsDlgButtonChecked(hDlg, IDC_CHECK_LOGFILE) == BST_CHECKED) ? TRUE : FALSE; gbSaveReceivedCSs = (IsDlgButtonChecked(hDlg, IDC_CHECK_RECEIVEDCS) == BST_CHECKED) ? TRUE : FALSE; gbSaveReceivedDSs = (IsDlgButtonChecked(hDlg, IDC_CHECK_RECEIVEDDS) == BST_CHECKED) ? TRUE : FALSE; gbSaveSentDSs = (IsDlgButtonChecked(hDlg, IDC_CHECK_SENTDS) == BST_CHECKED) ? TRUE : FALSE; GetDlgItemText(hDlg, IDC_EDIT_LOGFOLDER, gszLogFolder, sizeof(gszLogFolder) / sizeof(gszLogFolder[0])); PrepareFolder(gszLogFolder, "Log"); EndDialog(hDlg, IDOK); return TRUE; case IDC_BUTTON_BROWSE: if (GetFolder(hDlg, szSelectedFolder, sizeof(szSelectedFolder),TEXT("Select a folder:"))) { SetDlgItemText(hDlg, IDC_EDIT_LOGFOLDER, szSelectedFolder); } return TRUE; case IDC_CHECK_RECEIVEDCS: case IDC_CHECK_RECEIVEDDS: case IDC_CHECK_SENTDS: if (HIWORD(wParam) == BN_CLICKED) { EnableLogFolderItems(hDlg); } return TRUE; } } return FALSE; } L_VOID OnServerAdmin(HWND hDlg) { SRVADMINDATA dlg; L_INT nRet; L_BOOL bRestart; if(L_DicomGetClientCount(ghServer) > 0) { MessageBox(hDlg, "Cannot change server settings, clients are connected!", "Warning", MB_OK); dlg.bEnableEdits = FALSE; bRestart = FALSE; } else { L_DicomClose(ghServer); /*close server*/ LogEvent(hDlg, gszServerAETitle, "Server ShutDown"); bRestart = TRUE; } dlg.hUserList = GetDlgItem(hDlg, IDC_LIST1); dlg.hEventLog = GetDlgItem(hDlg, IDC_LIST2); lstrcpy(dlg.szAETitle, gszServerAETitle); dlg.lServerPort = guServerPort; dlg.lServerTimeOut = giTimeOut; dlg.lMaxClients = giMaxClients; nRet = DialogBoxParam(ghInstance, MAKEINTRESOURCE(IDD_SRVADMIN), hDlg, AdminDlgProc, (LPARAM)&dlg); lstrcpy(gszServerAETitle, dlg.szAETitle); guServerPort = dlg.lServerPort; giTimeOut = dlg.lServerTimeOut; giMaxClients = dlg.lMaxClients; /*restart server*/ if(bRestart) { /*init server*/ nRet = L_DicomListen(ghServer, "", guServerPort, giMaxClients); if(nRet != DICOM_SUCCESS) MessageBox(hDlg, "Error starting server!", "Error", MB_OK); else LogEvent(hDlg, gszServerAETitle, "Server StartUp"); } } L_VOID OnSelchangedTree1(HWND hDlg, NMHDR* pNMHDR) { HWND hCtl; NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; HTREEITEM hItem=NULL; pDICOMELEMENT pTemp=NULL; TV_ITEM Item; hCtl = GetDlgItem(hDlg, IDC_TREE1); hItem = TreeView_GetSelection(hCtl); if(!hItem) return; memset(&Item, 0, sizeof(TV_ITEM)); Item.mask = TVIF_PARAM; Item.hItem = hItem; TreeView_GetItem(hCtl, &Item); pTemp = (pDICOMELEMENT)Item.lParam; if(!pTemp) return; if(pTemp != gpDisplay) { gpDisplay = pTemp; TreeView_DeleteAllItems(GetDlgItem(hDlg, IDC_TREE2)); if(gBitmap.Flags.Allocated) L_FreeBitmap(&gBitmap); ShowWindow(GetDlgItem(hDlg, IDC_LEAD1), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_TREE2), SW_SHOW); pTemp = L_DicomGetChildElement(ghServerDS, pTemp, TRUE); while(pTemp) { DisplayKey(hDlg, pTemp, NULL); pTemp = L_DicomGetNextElement(ghServerDS, pTemp, TRUE, TRUE); } } } L_VOID OnDblclkTree1(HWND hDlg, NMHDR* pNMHDR) { HWND hCtl; HTREEITEM hItem=NULL; L_CHAR L_FAR* pszKey=NULL; pDICOMELEMENT pTemp=NULL; L_CHAR L_FAR* pszTemp=NULL; TV_ITEM Item; L_CHAR szFile[L_MAXPATH]; hCtl = GetDlgItem(hDlg, IDC_TREE1); hItem = TreeView_GetSelection(hCtl); if(!hItem) return; memset(&Item, 0, sizeof(TV_ITEM)); Item.mask = TVIF_PARAM; Item.hItem = hItem; TreeView_GetItem(hCtl, &Item); pTemp = (pDICOMELEMENT)Item.lParam; if(!pTemp) return; if( (pTemp == gpDisplay) && (!gBitmap.Flags.Allocated) ) { gpDisplay = pTemp; pszKey = L_DicomGetValueKey(ghServerDS, pTemp); if(!lstrcmp(pszKey, "IMAGE")) /*try to display the image*/ { TreeView_DeleteAllItems(GetDlgItem(hDlg, IDC_TREE2)); ShowWindow(GetDlgItem(hDlg, IDC_LEAD1), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_TREE2), SW_HIDE); pTemp = L_DicomGetChildElement(ghServerDS, pTemp, FALSE); if(pTemp) { //find the image pTemp = L_DicomFindFirstElement(ghServerDS, pTemp, TAG_REFERENCED_FILE_ID, TRUE); if(pTemp) { pszTemp = L_DicomGetStringValue(ghServerDS, pTemp, 0, 1); lstrcpy(szFile, gszImagesFolder); lstrcat(szFile, pszTemp); DisplayImageData(hDlg, szFile); return; } } } } else { if(pTemp != gpDisplay) { if(gBitmap.Flags.Allocated) L_FreeBitmap(&gBitmap); } } } VOID OnDelete(HWND hDlg) { HWND hDicomDirCtl; HTREEITEM hSelectedDRItem, hPatientDRItem, hStudyDRItem, hSeriesDRItem, hImageDRItem; pDICOMELEMENT pSelectedDR, pDR, pElement, pParentDR; L_CHAR* pszSelectedDRType; L_CHAR* pszPatientID, * pszStudyInstanceUID, * pszSeriesInstanceUID, * pszRefSOPInstanceUID; hDicomDirCtl = GetDlgItem(hDlg, IDC_TREE1); hSelectedDRItem = TreeView_GetSelection(hDicomDirCtl); if (!hSelectedDRItem) return; gpDisplay = NULL; if (!GetTreeViewItemData(hDicomDirCtl, hSelectedDRItem, (DWORD*) &pSelectedDR)) return; if (!pSelectedDR) return; TreeView_DeleteAllItems(GetDlgItem(hDlg, IDC_TREE2)); if (gBitmap.Flags.Allocated) L_FreeBitmap(&gBitmap); ShowWindow(GetDlgItem(hDlg, IDC_LEAD1), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_TREE2), SW_SHOW); pszSelectedDRType = L_DicomGetValueKey(ghServerDS, pSelectedDR); hPatientDRItem = NULL; hStudyDRItem = NULL; hSeriesDRItem = NULL; hImageDRItem = NULL; if (lstrcmpi(pszSelectedDRType, "PATIENT") == 0) { hPatientDRItem = hSelectedDRItem; } else if (lstrcmpi(pszSelectedDRType, "STUDY") == 0) { hStudyDRItem = hSelectedDRItem; hPatientDRItem = TreeView_GetParent(hDicomDirCtl, hStudyDRItem); } else if (lstrcmpi(pszSelectedDRType, "SERIES") == 0) { hSeriesDRItem = hSelectedDRItem; hStudyDRItem = TreeView_GetParent(hDicomDirCtl, hSeriesDRItem); if (hStudyDRItem) hPatientDRItem = TreeView_GetParent(hDicomDirCtl, hStudyDRItem); } else if (lstrcmpi(pszSelectedDRType, "IMAGE") == 0) { hImageDRItem = hSelectedDRItem; hSeriesDRItem = TreeView_GetParent(hDicomDirCtl, hImageDRItem); if (hSeriesDRItem) hStudyDRItem = TreeView_GetParent(hDicomDirCtl, hSeriesDRItem); if (hStudyDRItem) hPatientDRItem = TreeView_GetParent(hDicomDirCtl, hStudyDRItem); } // Get the Patient ID pszPatientID = NULL; if (hPatientDRItem) { GetTreeViewItemData(hDicomDirCtl, hPatientDRItem, (DWORD*) &pDR); if (pDR) { pElement = L_DicomGetChildElement(ghServerDS, pDR, TRUE); if (pElement) { pElement = L_DicomFindFirstElement(ghServerDS, pElement, TAG_PATIENT_ID, TRUE); } if (pElement) { pszPatientID = L_DicomGetStringValue(ghServerDS, pElement, 0, 1); L_DicomFreeValue(ghServerDS, pElement); } } } if (lstrcmpi(pszSelectedDRType, "PATIENT") == 0) { DeletePatient(hDlg, pszPatientID); L_DicomDeleteKey(ghServerDS, pSelectedDR); TreeView_DeleteItem(hDicomDirCtl, hSelectedDRItem); } else { // Get the Study Instance UID pszStudyInstanceUID = NULL; if (hStudyDRItem) { GetTreeViewItemData(hDicomDirCtl, hStudyDRItem, (DWORD*) &pDR); if (pDR) { pElement = L_DicomGetChildElement(ghServerDS, pDR, TRUE); if (pElement) { pElement = L_DicomFindFirstElement(ghServerDS, pElement, TAG_STUDY_INSTANCE_UID, TRUE); } if (pElement) { pszStudyInstanceUID = L_DicomGetStringValue(ghServerDS, pElement, 0, 1); L_DicomFreeValue(ghServerDS, pElement); } } } if (lstrcmpi(pszSelectedDRType, "STUDY") == 0) { pParentDR = L_DicomGetParentKey(ghServerDS, pSelectedDR); L_DicomDeleteKey(ghServerDS, pSelectedDR); if (L_DicomGetChildKey(ghServerDS, pParentDR) == NULL) { DeletePatient(hDlg, pszPatientID); L_DicomDeleteKey(ghServerDS, pParentDR); TreeView_DeleteItem(hDicomDirCtl, hPatientDRItem); } else { DeleteStudy(hDlg, NULL, NULL, pszStudyInstanceUID); TreeView_DeleteItem(hDicomDirCtl, hSelectedDRItem); } } else { // Get the Series Instance UID pszSeriesInstanceUID = NULL; if (hSeriesDRItem) { GetTreeViewItemData(hDicomDirCtl, hSeriesDRItem, (DWORD*) &pDR); if (pDR) { pElement = L_DicomGetChildElement(ghServerDS, pDR, TRUE); if (pElement) { pElement = L_DicomFindFirstElement(ghServerDS, pElement, TAG_SERIES_INSTANCE_UID, TRUE); } if (pElement) { pszSeriesInstanceUID = L_DicomGetStringValue(ghServerDS, pElement, 0, 1); L_DicomFreeValue(ghServerDS, pElement); } } } if (lstrcmpi(pszSelectedDRType, "SERIES") == 0) { pParentDR = L_DicomGetParentKey(ghServerDS, pSelectedDR); L_DicomDeleteKey(ghServerDS, pSelectedDR); if (L_DicomGetChildKey(ghServerDS, pParentDR) == NULL) { pDR = pParentDR; pParentDR = L_DicomGetParentKey(ghServerDS, pParentDR); L_DicomDeleteKey(ghServerDS, pDR); if (L_DicomGetChildKey(ghServerDS, pParentDR) == NULL) { DeletePatient(hDlg, pszPatientID); L_DicomDeleteKey(ghServerDS, pParentDR); TreeView_DeleteItem(hDicomDirCtl, hPatientDRItem); } else { DeleteStudy(hDlg, NULL, NULL, pszStudyInstanceUID); TreeView_DeleteItem(hDicomDirCtl, hStudyDRItem); } } else { DeleteSeries(hDlg, NULL, NULL, pszStudyInstanceUID, pszSeriesInstanceUID); TreeView_DeleteItem(hDicomDirCtl, hSelectedDRItem); } } else { // Get the SOP Instance UID pszRefSOPInstanceUID = NULL; if (hImageDRItem) { GetTreeViewItemData(hDicomDirCtl, hImageDRItem, (DWORD*) &pDR); if (pDR) { pElement = L_DicomGetChildElement(ghServerDS, pDR, TRUE); if (pElement) { pElement = L_DicomFindFirstElement(ghServerDS, pElement, TAG_REFERENCED_SOP_INSTANCE_UID_IN_FILE, TRUE); } if (pElement) { pszRefSOPInstanceUID = L_DicomGetStringValue(ghServerDS, pElement, 0, 1); L_DicomFreeValue(ghServerDS, pElement); } } } if (lstrcmpi(pszSelectedDRType, "IMAGE") == 0) { pParentDR = L_DicomGetParentKey(ghServerDS, pSelectedDR); L_DicomDeleteKey(ghServerDS, pSelectedDR); if (L_DicomGetChildKey(ghServerDS, pParentDR) == NULL) { pDR = pParentDR; pParentDR = L_DicomGetParentKey(ghServerDS, pParentDR); L_DicomDeleteKey(ghServerDS, pDR); if (L_DicomGetChildKey(ghServerDS, pParentDR) == NULL) { pDR = pParentDR; pParentDR = L_DicomGetParentKey(ghServerDS, pParentDR); L_DicomDeleteKey(ghServerDS, pDR); if (L_DicomGetChildKey(ghServerDS, pParentDR) == NULL) { DeletePatient(hDlg, pszPatientID); L_DicomDeleteKey(ghServerDS, pParentDR); TreeView_DeleteItem(hDicomDirCtl, hPatientDRItem); } else { DeleteStudy(hDlg, NULL, NULL, pszStudyInstanceUID); TreeView_DeleteItem(hDicomDirCtl, hStudyDRItem); } } else { DeleteSeries(hDlg, NULL, NULL, pszStudyInstanceUID, pszSeriesInstanceUID); TreeView_DeleteItem(hDicomDirCtl, hSeriesDRItem); } } else { DeleteImage(hDlg, NULL, NULL, pszStudyInstanceUID, pszSeriesInstanceUID, pszRefSOPInstanceUID); TreeView_DeleteItem(hDicomDirCtl, hSelectedDRItem); } } } } } SetFocus(hDicomDirCtl); } L_VOID CleanOpenDlgParam(LPOPENDLGPARAMS pFOParam) { int i=0; if(pFOParam!=NULL && pFOParam->pFileData!= NULL ) { for(i=0; i < pFOParam->nNumOfFiles; ++i ) { if(pFOParam->pFileData[i].pBitmap != NULL) { L_FreeBitmap(pFOParam->pFileData[i].pBitmap); GlobalFreePtr(pFOParam->pFileData[i].pBitmap); } if(pFOParam->pFileData[i].pThumbnail != NULL) { L_FreeBitmap(pFOParam->pFileData[i].pThumbnail); GlobalFreePtr(pFOParam->pFileData[i].pThumbnail); } if(pFOParam->pFileData[i].pFileInfo != NULL) { GlobalFreePtr(pFOParam->pFileData[i].pFileInfo); } } GlobalFreePtr(pFOParam->pFileData); pFOParam->pFileData =NULL; pFOParam->nNumOfFiles = 0; } } VOID OnImport(HWND hDlg) { L_INT nRet; L_CHAR szTemp[MAX_PATH]= "\0"; L_CHAR szFilename[MAX_PATH]; L_CHAR szOpenFilename[MAX_PATH]; BOOL bRet; OPENFILENAME ofn; HDICOMDS hDS=NULL; L_BOOL bFailed; L_CHAR* pszMessage, * pszSOPInstanceUID; pDICOMELEMENT pElement; ZeroMemory(szOpenFilename, sizeof(szOpenFilename)); ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hDlg; ofn.lpstrFilter = TEXT("DICOM Files (*.dic;*.dcm)\0*.dic;*.dcm\0All files (*.*)\0*.*\0"); ofn.nFilterIndex = 1; ofn.lpstrFile = szOpenFilename; ofn.nMaxFile = sizeof(szOpenFilename) / sizeof(TCHAR); ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST; bRet = GetOpenFileName(&ofn); if (bRet == TRUE) { // Load the data set hDS = L_DicomCreateDS(gszTempFilesFolder); if (!hDS) { MessageBox(hDlg, "Error importing DICOM DataSet", "Error", MB_OK); return; } nRet = L_DicomLoadDS(hDS,szOpenFilename, 0); if (nRet != DICOM_SUCCESS) { L_DicomFreeDS(hDS); MessageBox(hDlg, "Error loading DICOM DataSet", "Error", MB_OK); return; } gbImport = TRUE; bFailed = TRUE; pszMessage = "Error importing DICOM Data Set"; pElement = L_DicomFindFirstElement(hDS, NULL, TAG_SOP_INSTANCE_UID, FALSE); if (pElement) { pszSOPInstanceUID = L_DicomGetStringValue(hDS, pElement, 0, 1); if (lstrlen(pszSOPInstanceUID)) { wsprintf(szOpenFilename, "%s.dcm", pszSOPInstanceUID); nRet = InsertDataSet(hDlg, hDS, szOpenFilename); if (nRet == 2) // Already exists? { pszMessage = "Data Set already exists in Database!"; } else if (nRet == 0) { wsprintf(szFilename, "%s%s", gszImagesFolder, szOpenFilename); if (L_DicomSaveDS(hDS, szFilename, DS_METAHEADER_PRESENT | DS_GROUP_LENGTHS) == DICOM_SUCCESS) { bFailed = FALSE; InitServerDS(hDlg); } } } } L_DicomFreeDS(hDS); if (bFailed) { MessageBox(hDlg, pszMessage, "Error", MB_OK); } // Refresh the DICOM Directory display DisplayDICOMDir(hDlg); } } VOID OnServerConnections(HWND hDlg) { HMENU hMenu=NULL; UINT uState; hMenu = GetMenu(hDlg); uState = GetMenuState(hMenu, IDM_SERVER_CONNECTIONS, MF_BYCOMMAND|MF_CHECKED); if(uState&MF_CHECKED) { ShowWindow(GetDlgItem(hDlg, IDC_BUTTON4), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_TREE3), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_BUTTON2), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_BUTTON3), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_TREE1), SW_SHOW); if(gBitmap.Flags.Allocated) ShowWindow(GetDlgItem(hDlg, IDC_LEAD1), SW_SHOW); else ShowWindow(GetDlgItem(hDlg, IDC_TREE2), SW_SHOW); CheckMenuItem(hMenu, IDM_SERVER_CONNECTIONS, MF_BYCOMMAND|MF_UNCHECKED); } else { ShowWindow(GetDlgItem(hDlg, IDC_BUTTON4), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_TREE3), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_BUTTON2), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_BUTTON3), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_TREE1), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_LEAD1), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_TREE2), SW_HIDE); CheckMenuItem(hMenu, IDM_SERVER_CONNECTIONS, MF_BYCOMMAND|MF_CHECKED); } } VOID OnServerLoggingOptions(HWND hDlg) { DialogBox(ghInstance, MAKEINTRESOURCE(IDD_LOG), NULL, LogOptsDlgProc); } VOID OnCloseClient(HWND hDlg) { HWND hConnectionsCtrl; HTREEITEM hItem; TV_ITEM item; pCLIENTDATA pClientData; hConnectionsCtrl = GetDlgItem(hDlg, IDC_TREE3); hItem = TreeView_GetSelection(hConnectionsCtrl); if (!hItem) return; if (MessageBox(hDlg, "Forcefully close client?", "Warning", MB_YESNO) == IDYES) { memset(&item, 0, sizeof(TV_ITEM)); item.mask = TVIF_PARAM; item.hItem = hItem; TreeView_GetItem(hConnectionsCtrl, &item); pClientData = (pCLIENTDATA) item.lParam; // Send Abort L_DicomSendAbort(pClientData->hClient, PDU_ABORT_SOURCE_PROVIDER, PDU_ABORT_REASON_UNKNOWN); // Close client L_DicomClose(pClientData->hClient); L_DicomFreeNet(pClientData->hClient); // Remove from list TreeView_DeleteItem(hConnectionsCtrl, hItem); free(pClientData); } } L_VOID OnTimer(HWND hDlg, UINT nIDEvent) { HWND hConnectionsCtrl; HTREEITEM hItem, hTempItem; TV_ITEM item; pCLIENTDATA pClientData; if (nIDEvent == MOVE_TIMER_ID) { gnSecondsElapsed++; if (gnSecondsElapsed > giTimeOut * 60) { KillTimer(hDlg, MOVE_TIMER_ID); if (L_DicomIsConnected(ghClient)) { if (L_DicomIsAssociated(ghClient)) { L_DicomSendReleaseRequest(ghClient); } else { L_DicomClose(ghClient); } L_DicomSendCMoveResponse(ghMoveNet, gnMovePresentationID, guMoveMessageID, gszMoveClass, COMMAND_STATUS_PROCESSING_FAILURE, 0, 0, 0, 0, NULL); } } } else if (nIDEvent == CLIENTS_TIMER_ID) { hConnectionsCtrl = GetDlgItem(hDlg, IDC_TREE3); hItem = TreeView_GetRoot(hConnectionsCtrl); if (!hItem) { KillTimer(hDlg, CLIENTS_TIMER_ID); } else { while (hItem) { memset(&item, 0, sizeof(TV_ITEM)); item.mask = TVIF_HANDLE | TVIF_PARAM; item.hItem = hItem; TreeView_GetItem(hConnectionsCtrl, &item); pClientData = (pCLIENTDATA) item.lParam; if (pClientData->bEnableTimeout) { if (++pClientData->uSecondsElapsed > pClientData->uTimeout * 60) { L_DicomSendAbort(pClientData->hClient, PDU_ABORT_SOURCE_PROVIDER, PDU_ABORT_REASON_UNKNOWN); L_DicomClose(pClientData->hClient); LogEvent(hDlg, pClientData->szAETitle, "Timed out - Connection closed"); L_DicomFreeNet(pClientData->hClient); free(pClientData); hTempItem = hItem; hItem = TreeView_GetNextItem(hConnectionsCtrl, hItem, TVGN_NEXT); TreeView_DeleteItem(hConnectionsCtrl, hTempItem); continue; } } hItem = TreeView_GetNextItem(hConnectionsCtrl, hItem, TVGN_NEXT); } } } }