#include "StrMain.h" #include "..\..\..\include\ltdlg.h" // Registry location #define REGISTRY_LOCATION "SOFTWARE\\LEAD Technologies, Inc.\\API_DicomSTR" L_CHAR gszServerName[64] = ""; L_CHAR gszPeerIP[64] = ""; L_CHAR gszClientName[64] = ""; L_UINT guServerPort; L_UINT guCompression; L_UINT guTimeOut; pCURFILE gpFiles; HINSTANCE hGlobInstance; LRESULT CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM); extern LRESULT CALLBACK OptionsDlgProc(HWND, UINT, WPARAM, LPARAM); extern LRESULT CALLBACK ProgressDlgProc(HWND, UINT, WPARAM, LPARAM); L_INT Store(HWND hMainDlg); L_VOID ReadDataFromRegistry(HWND hDlg); L_VOID ShowFileDlg(HWND hDlg); L_VOID ShowDICOMDIRDlg(HWND hDlg); L_VOID FillListSingleFile(HWND hDlg, L_CHAR* pszFileName); L_VOID GetAllReferncedFiles(HWND hDlg, L_CHAR* pszFileName); L_VOID RemoveAllFiles(); L_INT AddFile(L_CHAR* pszFilename); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int iCmdShow) { INITCOMMONCONTROLSEX InitCtrl; // Unlock support UNLOCKSUPPORT(); if (L_IsSupportLocked(L_SUPPORT_MEDICAL_NET)) { MessageBox(NULL, TEXT("Medical Support must be unlocked for this demo!"), TEXT("Demo"), MB_OK | MB_ICONERROR); return 0; } // This is for the IP Address Control InitCtrl.dwSize = sizeof(INITCOMMONCONTROLSEX); InitCtrl.dwICC = ICC_LISTVIEW_CLASSES | ICC_INTERNET_CLASSES; InitCommonControlsEx(&InitCtrl); // Display the main dialog hGlobInstance = hInstance; DialogBox(hGlobInstance, MAKEINTRESOURCE(IDD_CLDSTR32_DLG), GetDesktopWindow(), (DLGPROC) MainDlgProc); return 0; } /*------------------------- The Main Dialog Procedure -------------------------*/ LRESULT CALLBACK MainDlgProc(HWND hMainDlg, UINT uiMessage, WPARAM wParam, LPARAM lParam) { HWND hListView; L_INT nRet; L_CHAR szText[256]; LVCOLUMN lvc; L_INT iCol; L_INT nPos; L_CHAR szCurFileName[MAX_PATH]; switch (uiMessage) { case WM_INITDIALOG: // Set the icon for the dialog SendMessage(hMainDlg, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon(hGlobInstance, TEXT("LEADIcon"))); // Initialize the list view colomns hListView = GetDlgItem(hMainDlg, IDC_LIST_DICOM_FILES); ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; // Add the columns. for (iCol = 0; iCol < 6; iCol++) { lvc.iSubItem = iCol; lvc.pszText = szText; lvc.fmt = LVCFMT_LEFT; // left-aligned column switch (iCol) { case 0: lvc.cx = 100; lstrcpy(szText,"Patient Name"); break; case 1: lvc.cx = 100; lstrcpy(szText,"Patient ID"); break; case 2: lvc.cx = 80; lstrcpy(szText,"Study ID"); break; case 3: lvc.cx = 80; lstrcpy(szText,"Modality"); break; case 4: lvc.cx = 100; lstrcpy(szText,"Transfer Syntax"); break; case 5: lvc.cx = 162; lstrcpy(szText,"File Path"); break; } ListView_InsertColumn(hListView, iCol, &lvc); } // Start the dicom network nRet = L_DicomStartUp(); if (nRet != DICOM_SUCCESS) { MessageBox(NULL, "StartUp() failed", "Storage SCU", MB_OK | MB_ICONEXCLAMATION); EndDialog(hMainDlg, 0); return 0; } // Read data from registry ReadDataFromRegistry(hMainDlg); return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BUT_CLOSE: EndDialog(hMainDlg, 0); return 0; case IDC_BUT_STORE: // Empty status edit box SetDlgItemText(hMainDlg, IDC_EDIT_STATUS, ""); hListView = GetDlgItem(hMainDlg, IDC_LIST_DICOM_FILES); if (ListView_GetSelectedCount(hListView) == 0) { // No selected item MessageBox(NULL, "Please select an image (or a set of images) from the list to be stored!", "Storage SCU", MB_OK|MB_ICONEXCLAMATION); return 0; } // Free the structure RemoveAllFiles(); // Add all the files selected nPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED); while (nPos != -1) { ListView_GetItemText(hListView, nPos, 5, szCurFileName, sizeof(szCurFileName)); AddFile(szCurFileName); nPos = ListView_GetNextItem(hListView, nPos, LVNI_SELECTED); } // Start the Storage Store(hMainDlg); break; case IDC_BUT_ADD_FILE: ShowFileDlg(hMainDlg); break; case IDC_BUT_ADD_DICOMDIR: ShowDICOMDIRDlg(hMainDlg); break; case IDC_BUT_OPTIONS: DialogBox(hGlobInstance, MAKEINTRESOURCE(IDD_DLG_CONNECT), hMainDlg, (DLGPROC) OptionsDlgProc); break; case IDC_BUT_CLEARALL: // Clear the listview and the status edit box SetDlgItemText(hMainDlg, IDC_EDIT_STATUS, ""); ListView_DeleteAllItems(GetDlgItem(hMainDlg, IDC_LIST_DICOM_FILES)); break; } return 0; case WM_DESTROY: RemoveAllFiles(); // shut down the network L_DicomShutDown(); return 0; case WM_CLOSE: EndDialog(hMainDlg, 0); return 0; } return 0; } L_VOID RemoveAllFiles() { pCURFILE pNextFile; while (gpFiles) { pNextFile = gpFiles->pNextFile; free(gpFiles); gpFiles = pNextFile; } } L_INT AddFile(L_CHAR* pszFilename) { pCURFILE pNewFile, pNextFile; if (!pszFilename) return DICOM_ERROR_PARAMETER; if (gpFiles) { pNextFile = gpFiles; while (pNextFile) { if (!pNextFile->pNextFile) break; pNextFile = (CURFILE*) pNextFile->pNextFile; } pNextFile->pNextFile = malloc(sizeof(CURFILE)); pNewFile = (CURFILE*) pNextFile->pNextFile; } else { gpFiles = (CURFILE*) malloc(sizeof(CURFILE)); pNewFile = gpFiles; } if (!pNewFile) return DICOM_ERROR_MEMORY; pNewFile->pNextFile = NULL; lstrcpyn(pNewFile->szFilename, pszFilename, sizeof(pNewFile->szFilename)); return DICOM_SUCCESS; } L_VOID ShowFileDlg(HWND hDlg) { OPENFILENAME OpenFileName; L_CHAR szFile[MAX_PATH] = ""; L_CHAR szOpenFileFilter[] = "All Files\0*.*\0"; HCURSOR hOldCurs; memset(&OpenFileName, 0, sizeof(OPENFILENAME)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.lpstrFile = szFile; OpenFileName.nMaxFile = sizeof(szFile); OpenFileName.lpstrFilter = szOpenFileFilter; OpenFileName.nFilterIndex = 1; OpenFileName.lpstrTitle = "Open DICOM File"; OpenFileName.Flags = OFN_FILEMUSTEXIST; OpenFileName.hwndOwner = hDlg; if(GetOpenFileName(&OpenFileName)) { hOldCurs = SetCursor(LoadCursor(NULL, IDC_WAIT)); FillListSingleFile(hDlg, OpenFileName.lpstrFile); SetCursor(hOldCurs); } } L_VOID ShowDICOMDIRDlg(HWND hDlg) { OPENFILENAME OpenFileName; L_CHAR szFile[MAX_PATH] = "DICOMDIR"; L_CHAR szOpenFileFilter[] = "All Files\0*.*\0"; HCURSOR hOldCurs; memset(&OpenFileName, 0, sizeof(OPENFILENAME)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.lpstrFile = szFile; OpenFileName.nMaxFile = sizeof(szFile); OpenFileName.lpstrFilter = szOpenFileFilter; OpenFileName.nFilterIndex = 1; OpenFileName.lpstrTitle = "Open DICOMDIR File"; OpenFileName.Flags = OFN_FILEMUSTEXIST; OpenFileName.hwndOwner = hDlg; if(GetOpenFileName(&OpenFileName)) { hOldCurs = SetCursor(LoadCursor(NULL, IDC_WAIT)); GetAllReferncedFiles(hDlg, OpenFileName.lpstrFile); SetCursor(hOldCurs); } } L_INT Store(HWND hMainDlg) { // Validation of data // Server Name if (lstrlen(gszServerName) == 0) { MessageBox(NULL, "Server name field should have a value!", "Storage SCU", MB_OK | MB_ICONEXCLAMATION); return -1; } // Server IP if (lstrlen(gszPeerIP) == 0) { MessageBox(NULL, "Server IP field should have a value!", "Storage SCU", MB_OK | MB_ICONEXCLAMATION ); return -1; } // Client Name if (lstrlen(gszClientName) == 0) { MessageBox(NULL, "Client name field should have a value!", "Storage SCU", MB_OK | MB_ICONEXCLAMATION ); return -1; } DialogBox(hGlobInstance, MAKEINTRESOURCE(IDD_FILE), hMainDlg, (DLGPROC) ProgressDlgProc); return DICOM_SUCCESS; } // Read data from the registry L_VOID ReadDataFromRegistry(HWND hDlg) { HKEY hNewKey; DWORD dwLength; // Initial values lstrcpy(gszServerName,""); lstrcpy(gszPeerIP,"0.0.0.0"); guServerPort = 104; lstrcpy(gszClientName,""); guCompression = 0; guTimeOut = 0; if(RegOpenKeyEx(HKEY_CURRENT_USER, REGISTRY_LOCATION, 0, KEY_QUERY_VALUE, &hNewKey) != ERROR_SUCCESS) return; // Server Name dwLength = sizeof(gszServerName); if (RegQueryValueEx(hNewKey, TEXT("sServerName"), NULL, NULL, (LPBYTE) gszServerName, &dwLength) != ERROR_SUCCESS) { lstrcpy(gszServerName,""); } // Server IP dwLength = sizeof(gszPeerIP); if (RegQueryValueEx(hNewKey, "dwServerIP", NULL, NULL, (LPBYTE)gszPeerIP, &dwLength) != ERROR_SUCCESS) { lstrcpy(gszPeerIP,"0.0.0.0"); } // Server port number dwLength = sizeof(guServerPort); if (RegQueryValueEx(hNewKey, "uServerPort", NULL, NULL, (LPBYTE) &guServerPort, &dwLength) != ERROR_SUCCESS) { guServerPort = 104; } // Client Name dwLength = sizeof(gszClientName); if (RegQueryValueEx(hNewKey, TEXT("sClientName"), NULL, NULL, (LPBYTE)gszClientName, &dwLength) != ERROR_SUCCESS) { lstrcpy(gszClientName,""); } // Time out (Seconds) dwLength = sizeof(guTimeOut); if (RegQueryValueEx(hNewKey, "uTimeOut", NULL, NULL, (LPBYTE) &guTimeOut, &dwLength) != ERROR_SUCCESS) { guTimeOut = 0; } // Compression dwLength = sizeof(guCompression); if (RegQueryValueEx(hNewKey, "uCompression", NULL, NULL, (LPBYTE) &guCompression, &dwLength) != ERROR_SUCCESS) { guCompression = 0; } RegCloseKey(hNewKey); } L_VOID FillListSingleFile(HWND hDlg, L_CHAR* pszFileName) { HWND hListView; L_INT nResult; L_UINT uRowsCount; pDICOMELEMENT pElement; L_CHAR *pszText; LV_ITEM lvItem; HDICOMDS hCurDS; hListView = GetDlgItem(hDlg, IDC_LIST_DICOM_FILES); // Create the Data Set hCurDS = L_DicomCreateDS(NULL); if (!hCurDS) { MessageBox(NULL, "Failed to open the file", "DICOM ERROR", MB_ICONSTOP); return; } nResult = L_DicomLoadDS(hCurDS, pszFileName, 0); if (nResult != DICOM_SUCCESS) { L_DicomFreeDS(hCurDS); MessageBox(NULL, "Failed to open the file", "DICOM ERROR", MB_ICONSTOP); return; } uRowsCount = ListView_GetItemCount(hListView); // Patient Name lvItem.mask = LVIF_TEXT; lvItem.iItem = uRowsCount; lvItem.iSubItem = 0; pElement = L_DicomFindFirstElement(hCurDS ,NULL, TAG_PATIENT_NAME, FALSE); if (pElement != NULL) { pszText = L_DicomGetStringValue(hCurDS, pElement, 0, 1); lvItem.pszText = pszText; uRowsCount = ListView_InsertItem(hListView, &lvItem); L_DicomFreeValue(hCurDS, pElement); } // Patient ID pElement = L_DicomFindFirstElement(hCurDS, NULL, TAG_PATIENT_ID, FALSE); if (pElement != NULL) { pszText = L_DicomGetStringValue(hCurDS, pElement,0,1); lvItem.pszText = pszText; lvItem.iSubItem++; lvItem.iItem = uRowsCount; ListView_SetItem(hListView, &lvItem); L_DicomFreeValue(hCurDS, pElement); } // Study ID pElement = L_DicomFindFirstElement(hCurDS, NULL, TAG_STUDY_ID, FALSE); if (pElement != NULL) { pszText = L_DicomGetStringValue(hCurDS, pElement,0,1); lvItem.pszText = pszText; lvItem.iSubItem++; lvItem.iItem = uRowsCount; ListView_SetItem(hListView, &lvItem); L_DicomFreeValue(hCurDS, pElement); } // Modality pElement = L_DicomFindFirstElement(hCurDS, NULL, TAG_MODALITY, FALSE); if (pElement != NULL) { pszText = L_DicomGetStringValue(hCurDS, pElement,0,1); lvItem.pszText = pszText; lvItem.iSubItem++; lvItem.iItem = uRowsCount; ListView_SetItem(hListView, &lvItem); L_DicomFreeValue(hCurDS, pElement); } // Transfer syntax pszText = "Implicit VR Little Endian"; pElement = L_DicomFindFirstElement(hCurDS, NULL, TAG_TRANSFER_SYNTAX_UID, FALSE); if (pElement != NULL) { pszText = L_DicomGetStringValue(hCurDS, pElement,0,1); if (pszText) { pDICOMUID pUID; pUID = L_DicomFindUID(pszText); if (pUID) pszText = pUID->pszName; } L_DicomFreeValue(hCurDS, pElement); } lvItem.pszText = pszText; lvItem.iSubItem++; lvItem.iItem = uRowsCount; ListView_SetItem(hListView, &lvItem); // File Path lvItem.pszText = pszFileName; lvItem.iSubItem++; lvItem.iItem = uRowsCount; ListView_SetItem(hListView, &lvItem); L_DicomFreeDS(hCurDS); } L_VOID GetAllReferncedFiles(HWND hDlg, L_CHAR* pszFileName) { L_INT nResult; L_CHAR szPath[MAX_PATH]; L_CHAR szFile[MAX_PATH]; HDICOMDS hCurDS; pDICOMELEMENT pElement; L_CHAR* pszText; L_CHAR* pdest; L_INT ch = '\\'; L_INT result; pdest = strrchr(pszFileName, ch); result = lstrlen(pszFileName) - lstrlen(pdest) ; lstrcpyn(szPath, pszFileName, result + 2); // Create the Data Set hCurDS = L_DicomCreateDS(NULL); if (!hCurDS) { MessageBox(NULL, "Failed to open the file", "DICOM ERROR", MB_ICONSTOP); return; } nResult = L_DicomLoadDS(hCurDS, pszFileName, 0); if (nResult != DICOM_SUCCESS) { L_DicomFreeDS(hCurDS); MessageBox(NULL, "Failed to open the file", "DICOM ERROR", MB_ICONSTOP); return; } // Get first refernced file ID pElement = L_DicomFindFirstElement(hCurDS ,NULL, TAG_REFERENCED_FILE_ID, FALSE); // Loop over all refernced file IDs in DICOMDIR file while (pElement != NULL) { pszText = L_DicomGetStringValue(hCurDS, pElement, 0, 1); if (pszText) { wsprintf(szFile, "%s%s", szPath, pszText); FillListSingleFile(hDlg, szFile); } L_DicomFreeValue(hCurDS, pElement); pElement = L_DicomFindNextElement(hCurDS, pElement, FALSE); } L_DicomFreeDS(hCurDS); }