/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 13 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2002 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #include /* Required for all Windows applications. */ #include /* Needed for message crackers. */ #include /* Windows' header for common dialog box. */ #include /* Standard C header files. */ #include #include /* Windows' header for common controls. */ #include #include "..\\..\\..\\include\\l_error.h" /* LEADTOOLS error definition header file. */ #include "..\\..\\..\\include\\ltdic.h" /* LEADTOOLS main header file. */ #include "..\\..\\..\\include\\ltlck.h" #include "..\\..\\..\\include\\ltdlg.h" #include "dicomdir.h" /* Application specific header file. */ #include "resource.h" #define LEAD_IMPLEMENTATION_CLASS_UID "1.2.840.114257.0.1" #define LEAD_IMPLEMENTATION_VERSION_NAME "LEADTOOLS Demo" #define LEAD_FILE_SET_ID "Example" /*---[WinMain]--------------------------------------------------------------- Syntax: int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) Parameters: hInstance Current instance. hPrevInstance previous instance. lpCmdLine command line. nCmdShow show-window type. Prototype: Windows.h Notes: Windows main function, calls initialization function and processes message loop. --------------------------------------------------------------------------*/ static CODETEXT m_Error[] = { { DICOM_SUCCESS, "Success" }, { DICOM_ERROR_LOCKED, "Support locked" }, { DICOM_ERROR_MEMORY, "Memory not available" }, { DICOM_ERROR_OPEN, "Open file error" }, { DICOM_ERROR_READ, "Read file error" }, { DICOM_ERROR_WRITE, "Write file error" }, { DICOM_ERROR_SEEK, "Seek file error" }, { DICOM_ERROR_END, "End-of-file" }, { DICOM_ERROR_FORMAT, "Wrong file format" }, { DICOM_ERROR_PARAMETER, "Wrong parameter passed" }, { DICOM_ERROR_IMAGE, "Wrong image" }, { DICOM_ERROR_COMPRESSION, "Wrong compression type for image" }, { DICOM_ERROR_PHOTOMETRIC, "Wrong photometric type for image" }, { DICOM_ERROR_CONVERSION, "The image cannot be converted" }, { DICOM_ERROR_RANGE, "Wrong range" }, { DICOM_ERROR_BITSPERPIXEL, "Wrong BitsPerPixel for image" }, { DICOM_ERROR_QFACTOR, "Wrong QFactor for image compression" }, { DICOM_ERROR_PDU_TYPE, "Wrong PDU's type" }, { DICOM_ERROR_PDU_LENGTH, "Wrong length for this PDU" }, { DICOM_ERROR_PDU_ID, "Wronk PDU's ID" }, { DICOM_ERROR_NET_FAILURE, "General failure" }, { DICOM_ERROR_NET_ACCESS, "Broadcast address" }, { DICOM_ERROR_NET_ADDRESS_IN_USE, "Address already in use" }, { DICOM_ERROR_NET_ADDRESS_NOT_AVAILABLE, "Address not available" }, { DICOM_ERROR_NET_ADDRESS_NOT_SUPPORTED, "Address family not supported" }, { DICOM_ERROR_NET_CONNECTION_ABORTED, "Connection aborted" }, { DICOM_ERROR_NET_CONNECTION_REFUSED, "Connection rejected" }, { DICOM_ERROR_NET_CONNECTION_RESET, "Connection reset by the remote side" }, { DICOM_ERROR_NET_DESTINATION_REQUIRED, "Destination address required" }, { DICOM_ERROR_NET_ARGUMENT_INCORRECT, "Argument incorrect" }, { DICOM_ERROR_NET_IN_PROGRESS, "Operation in progress" }, { DICOM_ERROR_NET_BLOCKING_CANCELED, "Blocking call canceled" }, { DICOM_ERROR_NET_INVALID, "Invalid connection" }, { DICOM_ERROR_NET_IS_CONNECTED, "Already connected" }, { DICOM_ERROR_NET_NO_MORE_FILE, "No more descriptors available" }, { DICOM_ERROR_NET_MESSAGE_SIZE, "The datagram is larger than the maximum supported" }, { DICOM_ERROR_NET_DOWN, "Network subsystem failed" }, { DICOM_ERROR_NET_RESET, "The connection must be reset" }, { DICOM_ERROR_NET_UN_REACH, "The network can't be reached from this host at this time" }, { DICOM_ERROR_NET_NO_BUFFERS, "No buffer space is available" }, { DICOM_ERROR_NET_NOT_CONNECTED, "Not connected" }, { DICOM_ERROR_NET_NOT_SOCKET, "Wrong descriptor" }, { DICOM_ERROR_NET_OPERATION_NOT_SUPPORTED, "Connection-oriented service not supported" }, { DICOM_ERROR_NET_PROTOCOL_NOT_SUPPORTED, "Protocol not supported" }, { DICOM_ERROR_NET_PROTOCOL_TYPE, "Wrong protocol type" }, { DICOM_ERROR_NET_SHUTDOWN, "Network shut down" }, { DICOM_ERROR_NET_SOCKET_NOT_SUPPORTED, "Type not supported in this address family" }, { DICOM_ERROR_NET_TIME_OUT, "Time out" }, { DICOM_ERROR_NET_WOULD_BLOCK, "Nonblocking connection and the requested operation would block" }, { DICOM_ERROR_NET_HOST_NOT_FOUND, "Host not found" }, { DICOM_ERROR_NET_NO_DATA, "No data record of requested type" }, { DICOM_ERROR_NET_NO_RECOVERY, "Nonrecoverable errors" }, { DICOM_ERROR_NET_NOT_INITIALISED, "System not initialized" }, { DICOM_ERROR_NET_SYSTEM_NOT_READY, "Not ready for network communication" }, { DICOM_ERROR_NET_TRY_AGAIN, "Host not found, or server faild" }, { DICOM_ERROR_NET_VERSION_NOT_SUPPORTED, "Version requested not supported" }, { DICOM_ERROR_USER_CLIENT_ADDRESS, "Rejected unknown client address" }, { DICOM_ERROR_USER_CLIENT_TITLE, "Rejected unknown client title" }, { DICOM_ERROR_USER_SERVER_TITLE, "Rejected unknown server title" }, }; int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcex; const L_CHAR* szClassName = "DICOMDIR_CLASS"; MSG Msg; BOOL bOk = FALSE; UNLOCKSUPPORT (); if(L_IsSupportLocked(L_SUPPORT_MEDICAL)) { MessageBox(NULL, "Medical-Express Support Must be unlocked for this demo!", "Error", MB_OK); return -1; } L_DlgInit (DLG_INIT_COLOR); Data.hInst = hInstance; m_bHighLevel = TRUE; InitCommonControls(); m_hDir = NULL; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)DicomDlgProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = DLGWINDOWEXTRA; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MAIN); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szClassName; wcex.hIconSm = NULL; Msg.wParam = 0; if(RegisterClassEx(&wcex) != (ATOM)0) { HWND hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAINAPP_DIALOG), NULL, NULL); if(hWnd != NULL) { while(GetMessage(&Msg, NULL, 0, 0) != 0) { if(IsDialogMessage(hWnd, &Msg) == 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } } bOk = TRUE; } UnregisterClass(szClassName, hInstance); } if(!bOk) { MessageBox(NULL, "Cannot create main window!", NULL, MB_ICONSTOP); } return Msg.wParam; } #define WM_MYINIT (WM_APP+1) LRESULT CALLBACK DicomDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HDC hDC=NULL; HCURSOR hOldCursor=NULL; switch(uMsg) { case WM_CREATE: PostMessage(hDlg, WM_MYINIT, 0, 0); return 0; case WM_MYINIT: Data.bLoaded = FALSE; Data.LoadFlags = 0; Data.SaveFlags = 0; Data.nSaveCompression = IMAGE_COMPRESSION_NONE; Data.nSavePhotometric = IMAGE_PHOTOMETRIC_RGB; Data.nSaveBitsPerPixel = 24; Data.nSaveQFactor = 2; Data.bAnimationLoop = TRUE; Data.bAnimationPlay = FALSE; Data.bChild = FALSE; Data.bSequence = FALSE; Data.bFit = FALSE; Data.Zoom = 100; Data.bImage = FALSE; Data.bHighLevel= FALSE; Data.pCurrentElement = NULL; Data.nCurrentModule = (L_UINT32)-1; Data.hDicomDS = L_DicomCreateDS(NULL); Data.hImageList = ImageList_LoadBitmap(Data.hInst, MAKEINTRESOURCE(IDB_BITMAP1), 16, 0, CLR_NONE); Data.lItemCount = 0; Data.pItems = NULL; m_bDICOMDir = FALSE; TreeView_SetImageList(GetDlgItem(hDlg, IDC_TREE1), Data.hImageList, TVSIL_NORMAL); Data.OldProc = (WNDPROC)GetWindowLong(GetDlgItem(hDlg, IDC_IMAGEBTN), GWL_WNDPROC); SetWindowLong(GetDlgItem(hDlg, IDC_IMAGEBTN), GWL_WNDPROC, 0); ShowWindow(GetDlgItem(hDlg, IDC_LIST), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_IMAGEBTN), SW_HIDE); Data.hBitmapList = NULL; L_CreateBitmapList(&Data.hBitmapList); if(!Data.hDicomDS) { MessageBox(hDlg, "Error Creating DataSet", "Error", MB_OK); PostMessage(hDlg, WM_CLOSE, 0, 0); return 0; } ShowWindow(hDlg, SW_SHOW); UpdateWindow(hDlg); return 0; case WM_NOTIFY: HandleNotify(hDlg, wParam, (LPNMHDR)lParam); return 0; case WM_DRAWITEM: DrawImageBtn(hDlg, (LPDRAWITEMSTRUCT)lParam); return 0; case WM_DESTROY: if (m_hDir != NULL) { L_DicomResetDS(m_hDir); L_DicomFreeDS(m_hDir); } SetWindowLong(GetDlgItem(hDlg, IDC_IMAGEBTN), GWL_WNDPROC, (long)(WNDPROC)Data.OldProc); if(Data.bLoaded) L_DicomResetDS(Data.hDicomDS); Data.bLoaded = FALSE; L_DicomFreeDS(Data.hDicomDS); if(Data.Bitmap.Flags.Allocated) L_FreeBitmap(&Data.Bitmap); if(Data.hBitmapList) L_DestroyBitmapList(Data.hBitmapList); L_DlgFree (); PostQuitMessage(0); return 0; case WM_COMMAND: if(Data.bAnimationPlay) Data.bAnimationPlay = FALSE; switch (GET_WM_COMMAND_ID(wParam, lParam)) { case IDC_BUTTON_BW: BrowseButton(hDlg); break; } return FALSE; return 0; } return DefWindowProc(hDlg, uMsg, wParam, lParam); } #define UIDLEN 64 TCHAR INSTANCEGUID[UIDLEN]; //Generate a UID void CreateGUID() { SYSTEMTIME SystemTime; FILETIME FileTime; DWORD Tick; DWORD HighWord; GetSystemTime(&SystemTime); SystemTimeToFileTime(&SystemTime,&FileTime); Tick=GetTickCount(); HighWord=FileTime.dwHighDateTime+0x146BF4; wsprintf( INSTANCEGUID, TEXT("1.2.840.114257.0.1%010u%05u%05u%05u%05u%05u%05u"), FileTime.dwLowDateTime, LOWORD(HighWord), HIWORD(HighWord |0x10000000), LOWORD(rand()), HIWORD(Tick), LOWORD(Tick), LOWORD(rand())); return ; } L_VOID InsertMetaHeader(HDICOMDS hDS) { pDICOMELEMENT pElement; // Add File Meta Information Version pElement = L_DicomFindFirstElement(hDS,NULL, TAG_FILE_META_INFORMATION_VERSION, FALSE); if (pElement == NULL) { pElement = L_DicomInsertElement(hDS,NULL, FALSE, TAG_FILE_META_INFORMATION_VERSION, VR_OB, FALSE, 0); } if(pElement) { L_CHAR cValue[2] = {0x00, 0x01}; L_DicomSetCharValue(hDS,pElement, cValue, 2); } // Media Storage SOP Instance UID pElement = L_DicomFindFirstElement(hDS,NULL, TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, FALSE); if (pElement == NULL) { pElement = L_DicomInsertElement(hDS,NULL, FALSE, TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, VR_UI, FALSE, 0); } if(pElement) { CreateGUID(); L_DicomSetConvertValue(hDS,pElement, INSTANCEGUID, 1); } // Implementation Class UID pElement = L_DicomFindFirstElement(hDS,NULL, TAG_IMPLEMENTATION_CLASS_UID, FALSE); if (pElement == NULL) { pElement = L_DicomInsertElement(hDS,NULL, FALSE, TAG_IMPLEMENTATION_CLASS_UID, VR_UI, FALSE, 0); } if(pElement) { L_DicomSetConvertValue(hDS,pElement, LEAD_IMPLEMENTATION_CLASS_UID, 1); } // Implementation Version Name pElement = L_DicomFindFirstElement(hDS,NULL, TAG_IMPLEMENTATION_VERSION_NAME, FALSE); if (pElement == NULL) { pElement = L_DicomInsertElement(hDS,NULL, FALSE, TAG_IMPLEMENTATION_VERSION_NAME, VR_SH, FALSE, 0); } if(pElement) { L_DicomSetConvertValue(hDS,pElement, LEAD_IMPLEMENTATION_VERSION_NAME , 1); } } /* L_BOOL GetFolder(char* szSelectedFolder, const char* lpszTitle, const HWND hwndOwner, const char* strRootFolder, const char* strStartFolder) { // Get the selected folder. L_CHAR szDisplayName[MAX_PATH]; LPITEMIDLIST lpID; //Contains parameters for the SHBrowseForFolder function and receives //information about the folder selected by the user. BROWSEINFOA bi; bi.hwndOwner = hwndOwner; if (strRootFolder == NULL) { bi.pidlRoot = NULL; } else { LPITEMIDLIST pIdl = NULL; IShellFolder* pDesktopFolder; char szPath[MAX_PATH]; OLECHAR olePath[MAX_PATH]; strcpy(szPath, (LPCTSTR)strRootFolder); if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder))) { //The MultiByteToWideChar function maps a character string to a wide-character (Unicode) string. //The character string mapped by this function is not necessarily from a multibyte character set. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH); } bi.pidlRoot = pIdl; } bi.hwndOwner = hwndOwner; bi.pszDisplayName = szDisplayName; bi.lpszTitle = lpszTitle; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; bi.lpfn = NULL; if (strStartFolder == NULL) { bi.lParam = FALSE; } else { bi.lParam = TRUE; } bi.iImage = 0; //Displays a dialog box that enables the user to select a shell folder. lpID = SHBrowseForFolderA(&bi); if (lpID != NULL) { BOOL bRet; //Converts an item identifier list to a file system path. bRet = SHGetPathFromIDList(lpID, szDisplayName); if (bRet == TRUE) { strcpy(szSelectedFolder, szDisplayName); return TRUE; } } else { szSelectedFolder = NULL; } return FALSE; } */ L_VOID BrowseButton(HWND hDlg) { GETDIRECTORYDLGPARAMS GetDirectoryParams; L_INT nRet; // Selected directory. L_CHAR szFolderPath[MAX_PATH]; if (m_hDir != NULL) { L_DicomResetDS(m_hDir); } ShowWindow(GetDlgItem(hDlg, IDC_LIST), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_IMAGEBTN), SW_HIDE); TreeView_DeleteAllItems(GetDlgItem(hDlg, IDC_LIST)); InvalidateRect(GetDlgItem(hDlg, IDC_LIST),NULL, TRUE); m_hDir = L_DicomCreateDS(NULL); // Init the DICOMDIR file. L_DicomInitDS(m_hDir, CLASS_BASIC_DIRECTORY, DS_METAHEADER_PRESENT|DS_LITTLE_ENDIAN|DS_EXPLICIT_VR|DS_GROUP_LENGTHS); InsertMetaHeader(m_hDir); //Choose a folder memset ( &GetDirectoryParams, 0, sizeof ( GETDIRECTORYDLGPARAMS ) ); GetDirectoryParams.uStructSize = sizeof ( GETDIRECTORYDLGPARAMS ); GetDirectoryParams.nBuffSize = _MAX_PATH; GetDirectoryParams.pszDirectory = szFolderPath; GetDirectoryParams.pszFilter = TEXT("DICOM Files\0*.dic\0\0"); GetDirectoryParams.nFilterIndex = 0; GetDirectoryParams.pszTitle = TEXT("Choose a Folder"); nRet = L_DlgGetDirectory(hDlg, &GetDirectoryParams); if(nRet == SUCCESS_DLG_OK) { if (strlen(szFolderPath) != 0) { TreeView_DeleteAllItems(GetDlgItem(hDlg, IDC_TREE)); TreeView_DeleteAllItems(GetDlgItem(hDlg, IDC_LIST)); strcpy(m_szPath, szFolderPath); // set the selected path in "IDC_SELECTED_DIR" control. SetDlgItemText(hDlg, IDC_SELECTED_DIR, szFolderPath); // Find the DICOM files in the selected directory. FindDICOMFiles(szFolderPath, hDlg); } } } L_BOOL FindDICOMFiles(L_CHAR *pszDir, HWND hDlg) { // Find the DICOM files in the selected directory. L_BOOL bRet, bFindDicomFile; HANDLE hFind; WIN32_FIND_DATA dataFind; //find data BOOL bMoreFiles = TRUE; L_INT nItem = 0; L_UINT32 uCount; // counter L_CHAR szPath[MAX_PATH], szTempPath[MAX_PATH]; // selected path if (pszDir == NULL) { return FALSE; } strcpy(szPath, pszDir); bRet = FALSE; bFindDicomFile = FALSE; uCount = 0; strcpy(szTempPath, szPath); strcat(szTempPath, "\\*.*"); //The FindFirstFile function searches a directory for a file whose name matches the specified file name. //FindFirstFile examines subdirectory names as well as file names. hFind = FindFirstFile(szTempPath, &dataFind); if (hFind != INVALID_HANDLE_VALUE) { // find the DICOM files. while (bMoreFiles) { if((dataFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) { L_INT nLength; nLength = strlen(pszDir); if(pszDir[nLength - 1] == '\\') { strcat(szPath, pszDir); } else { strcat(szPath, pszDir); strcat(szPath, "\\"); } strcat(szPath, dataFind.cFileName); //Adds information from DICOM file to DICOMDIR file. bRet = AddToDICOMDIR(m_hDir, szPath); if (bRet == TRUE) { bFindDicomFile = TRUE; uCount++; } DisplayStatus(szPath, hDlg); } szPath[0] = '\0'; //The FindNextFile function continues a file search from a //previous call to the FindFirstFile function. bMoreFiles = FindNextFile(hFind, &dataFind); } //The FindClose function closes the specified search handle. //The FindFirstFile and FindNextFile functions use the search handle to //locate files with names that match a given name. FindClose(hFind); } if (bFindDicomFile == TRUE) { L_CHAR szValue[MAX_PATH]; L_UINT16 nSaveRet; L_INT nRet; strcpy(szValue, m_szPath); strcat(szValue, "\\DICOMDIR"); nRet = IDYES; if (m_bDICOMDir == TRUE) { nRet = MessageBox(hDlg, "DICOMDIR already exists.\nDo you want to overwrite the old DICOMDIR now?", "Warning", MB_YESNO|MB_ICONQUESTION); } if (nRet == IDNO) { wsprintf(szValue, "%s %d %s", " Searching Complete. ", uCount, " file(s) were found"); // Fill tree items. FillTree(hDlg, m_hDir, TVI_ROOT, NULL); //Displays the status of the search operation. DisplayStatus(szValue, hDlg); return TRUE; } //Saves the Data Set to the specified file. nSaveRet = L_DicomSaveDS(m_hDir, szValue, 0); if (nSaveRet == DICOM_SUCCESS) { L_CHAR szValueDisp[64]; L_INT ret; DisplayStatus("Save DICOMDIR successful", hDlg); // Fill tree items. FillTree(hDlg, m_hDir, TVI_ROOT, NULL); ret = wsprintf(szValueDisp, "%s%s %d %s", " DICOMDIR created successfully and saved into: ",szValue, uCount, "file(s) were found."); //Displays the status of the search operation. DisplayStatus(szValueDisp, hDlg); } else { L_CHAR szError[256]; // Convert error code in message. ConvertError(nSaveRet, szError); //Displays the status of the search operation. DisplayStatus(szError, hDlg); bRet = FALSE; } } else { //Displays the status of the search operation. DisplayStatus(" Searching Complete. There are no DICOM files in the selected directory.", hDlg); } return bRet; } L_VOID DisplayStatus(L_CHAR *pszStatus, HWND hDlg) { // Display the aplication status. L_CHAR szValue[MAX_PATH]; strcpy(szValue, "Status: "); if (pszStatus != NULL) { strcat(szValue, pszStatus); } SetDlgItemText(hDlg, IDC_STATIC_MSG, (LPCTSTR)szValue); } L_BOOL AddToDICOMDIR(HDICOMDS hDir, L_CHAR *pszImagPath) { //Adds information from DICOM file to DICOMDIR file. L_BOOL bRet; L_INT16 nRet; HDICOMDS hDS; bRet = FALSE; hDS = L_DicomCreateDS(NULL); if (hDS == NULL) { MessageBox(NULL, "Cannot create the DICOM file", "Error", MB_OK); } //Loads the Data Set from the specified file. nRet = L_DicomLoadDS(hDS, pszImagPath, DS_LOAD_CLOSE); if (nRet == DICOM_SUCCESS) { L_UINT32 nClass; L_UINT16 nFlags; nClass = 0; L_DicomGetInfoDS(hDS, &nClass, &nFlags); if (nClass != CLASS_BASIC_DIRECTORY) { // Creates or appends the new DataSet to DICOMDIR. bRet = CreateDir(hDir, hDS, pszImagPath); } else { m_bDICOMDir = TRUE; } } else { bRet = FALSE; } //Removes all items from the Data Set. L_DicomFreeDS(hDS); return bRet; } L_BOOL CreateDir(HDICOMDS hDir, HDICOMDS hDS, L_CHAR *pszImag) { // Create DICOMDIR file and insert new key if it is necessary. L_BOOL bRet; pDICOMELEMENT pElementDir, pChildDir, pElement; pDICOMELEMENT pKey, pPatientKey, pStudyKey, pSeriesKey, pImageKey; L_CHAR *pszText; L_UINT32 nLength; L_CHAR szValue[MAX_PATH]; L_UINT16 nSaveRet; L_CHAR szPatientPath[MAX_PATH], szStudyPath[MAX_PATH], szSeriesPath[MAX_PATH]; L_INT nCount; L_UINT i, j; nSaveRet = 0; nCount = 0; i = 0; j = 0; pElement = NULL; pKey = NULL; bRet = FALSE; pszText = NULL; nLength = 0; szPatientPath[0] ='\0'; szStudyPath[0] = '\0'; szSeriesPath[0] = '\0'; szValue[0] = '\0'; nLength = strlen(pszImag); for (i = 0; i < nLength; i++) { if (pszImag[i] == '\\') { nCount = i; } } j = 0; for (i = nCount+1; i< nLength; i++) { szValue[j] = pszImag[i]; j++; } szValue[j] = '\0'; strcpy(pszImag, szValue); nCount = 0; pElement = L_DicomFindFirstElement(hDS, NULL, TAG_PATIENT_ID, FALSE); if (pElement != NULL) { nLength = L_DicomGetConvertValue(hDS, pElement, NULL); if (nLength == 0) { L_CHAR szMsg[256]; strcpy(szMsg, "In the "); strcat(szMsg, pszImag); strcat(szMsg, " file the Patient ID value is NULL \nIt cannot be added in the DICOMDIR file"); MessageBox(NULL, szMsg, "Warning", MB_OK|MB_ICONWARNING); return FALSE; } pszText = (L_CHAR *)malloc(nLength); if (pszText == NULL) { return FALSE; } L_DicomGetConvertValue(hDS, pElement, pszText); // Insert a new Patient Key if it is not exist. pKey = FindKey(hDir, pszText, NULL); if (pKey == NULL) { pElement = NULL; pElementDir = NULL; pKey = L_DicomInsertKey(hDir, NULL, "PATIENT", TRUE); if (pKey == NULL) { return FALSE; } pPatientKey = pKey; } else { pPatientKey = pKey; } // return the Patient Key //////////////////////////Copy the require elements from DataSet to DICOMDIR ///////////////////////// pChildDir = NULL; pElementDir = L_DicomGetChildElement(hDir, pKey, TRUE); pChildDir = L_DicomGetChildElement(hDir, pKey, TRUE); pElementDir = L_DicomFindFirstElement(hDir, pElementDir, TAG_PATIENT_ID, TRUE); L_DicomSetConvertValue(hDir, pElementDir, pszText, 1); CopyElement(pElementDir, hDir, hDS, TAG_PATIENT_NAME); CopyElement(pElementDir, hDir, hDS, TAG_RECORD_IN_USE_FLAG); CopyElement(pElementDir, hDir, hDS, TAG_DIRECTORY_RECORD_TYPE); CopyElement(pElementDir, hDir, hDS, TAG_SPECIFIC_CHARACTER_SET); ///////////////////////////////////////////////////////////////////////////////////////////////////// pElementDir = L_DicomFindFirstElement(hDir, pElementDir, TAG_RECORD_IN_USE_FLAG, TRUE); if (pElementDir == NULL) { L_BOOL bRet; pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_RECORD_IN_USE_FLAG, VR_US, FALSE, 0); bRet = L_DicomSetConvertValue(hDir, pElementDir, (L_CHAR *)(LPCTSTR)"65535", 1); } else { L_BOOL bRet; bRet = L_DicomSetConvertValue(hDir, pElementDir, (L_CHAR *)(LPCTSTR)"65535", 1); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// DeleteElement(hDir, pPatientKey, TAG_REFERENCED_FILE_ID); DeleteElement(hDir, pPatientKey, TAG_PRIVATE_RECORD_UID); DeleteElement(hDir, pPatientKey, TAG_REFERENCED_SOP_CLASS_UID_IN_FILE); DeleteElement(hDir, pPatientKey, TAG_REFERENCED_SOP_INSTANCE_UID_IN_FILE); DeleteElement(hDir, pPatientKey, TAG_REFERENCED_TRANSFER_SYNTAX_UID_IN_FILE); /////////////////////////////////////////////////////////////////////////////////////////////////////////// } if (pszText != NULL) { free(pszText); pszText = NULL; } // Insert a new Study Key if it is not exist. pElement = L_DicomFindFirstElement(hDS, NULL, TAG_STUDY_INSTANCE_UID, FALSE); if (pElement != NULL) { nLength = L_DicomGetConvertValue(hDS, pElement, NULL); pszText = (L_CHAR *)malloc(nLength); L_DicomGetConvertValue(hDS, pElement, pszText); pKey = FindKey(hDir, pszText, pPatientKey); if (pKey == NULL) { pElement = NULL; pElementDir = NULL; pKey = L_DicomInsertKey(hDir, pPatientKey, "STUDY", TRUE); if (pKey == NULL) { return FALSE; } pStudyKey = pKey; } else { pStudyKey = pKey; } //returns the Study Key pChildDir = NULL; pElementDir = L_DicomGetChildElement(hDir, pKey, TRUE); pChildDir = L_DicomGetChildElement(hDir, pKey, TRUE); pElementDir = L_DicomFindFirstElement(hDir, pElementDir, TAG_STUDY_INSTANCE_UID, TRUE); L_DicomSetConvertValue(hDir, pElementDir, pszText, 1); ////////////////////////////////////Copy the require elements from DataSet to DICOMDIR//////////////////// pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_REFERENCED_FILE_ID, TRUE); if (pElementDir == NULL) { L_BOOL bRet; pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_REFERENCED_FILE_ID, VR_CS, FALSE, 0); bRet = L_DicomSetConvertValue(hDir, pElementDir, szStudyPath, 0); } else { L_BOOL bRet; bRet = L_DicomSetConvertValue(hDir, pElementDir, szStudyPath, 0); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_RECORD_IN_USE_FLAG, TRUE); if (pElementDir == NULL) { L_BOOL bRet; pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_RECORD_IN_USE_FLAG, VR_US, FALSE, 0); bRet = L_DicomSetConvertValue(hDir, pElementDir, (L_CHAR *)(LPCTSTR)"65535", 1); } else { L_BOOL bRet; bRet = L_DicomSetConvertValue(hDir, pElementDir, (L_CHAR *)(LPCTSTR)"65535", 1); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// CopyElement(pElementDir, hDir, hDS, TAG_STUDY_ID); CopyElement(pElementDir, hDir, hDS, TAG_ACCESSION_NUMBER); CopyElement(pElementDir, hDir, hDS, TAG_STUDY_DATE); CopyElement(pElementDir, hDir, hDS, TAG_STUDY_DESCRIPTION); CopyElement(pElementDir, hDir, hDS, TAG_STUDY_TIME); CopyElement(pElementDir, hDir, hDS, TAG_RECORD_IN_USE_FLAG); CopyElement(pElementDir, hDir, hDS, TAG_SPECIFIC_CHARACTER_SET); /////////////////////////////////////////////////////////////////////////////////////////////////////////// DeleteElement(hDir, pStudyKey, TAG_REFERENCED_FILE_ID); DeleteElement(hDir, pStudyKey, TAG_PRIVATE_RECORD_UID); DeleteElement(hDir, pStudyKey, TAG_REFERENCED_SOP_CLASS_UID_IN_FILE); DeleteElement(hDir, pStudyKey, TAG_REFERENCED_SOP_INSTANCE_UID_IN_FILE); DeleteElement(hDir, pStudyKey, TAG_REFERENCED_TRANSFER_SYNTAX_UID_IN_FILE); ////////////////////////////////////////////////////////////////////////////////////////////////////////// } if (pszText != NULL) { free(pszText); pszText = NULL; } // Insert a new Series Key if it is not exist. pElement = L_DicomFindFirstElement(hDS, NULL, TAG_SERIES_INSTANCE_UID, FALSE); if (pElement != NULL) { nLength = L_DicomGetConvertValue(hDS, pElement, NULL); pszText = (L_CHAR *)malloc(nLength); L_DicomGetConvertValue(hDS, pElement, pszText); pChildDir = NULL; pKey = FindKey(hDir, pszText, pStudyKey); if (pKey == NULL) { pElement = NULL; pElementDir = NULL; pKey = L_DicomInsertKey(hDir, pStudyKey, "SERIES", FALSE); if (pKey == NULL) { return FALSE; } pSeriesKey = pKey; } else { pSeriesKey = pKey; } // returns Series Key ////////////////////////////////////Copy the require elements from DataSet to DICOMDIR//////////////////// pChildDir = L_DicomGetChildElement(hDir, pKey, TRUE); if (pChildDir == NULL) { return FALSE; } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_SERIES_INSTANCE_UID, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_SERIES_INSTANCE_UID, VR_UI, FALSE, 0); } if (pElementDir != NULL) { L_BOOL bRet; bRet = L_DicomSetConvertValue(hDir, pElementDir, pszText, 1); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_MODALITY, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_MODALITY, VR_CS, FALSE, 0); CopyElement(pElementDir, hDir, hDS, TAG_MODALITY); } else { CopyElement(pElementDir, hDir, hDS, TAG_MODALITY); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_SERIES_DESCRIPTION, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_SERIES_DESCRIPTION, VR_LO, FALSE, 0); CopyElement(pElementDir, hDir, hDS, TAG_SERIES_DESCRIPTION); } else { CopyElement(pElementDir, hDir, hDS, TAG_SERIES_DESCRIPTION); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_SERIES_NUMBER, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_SERIES_NUMBER, VR_IS, FALSE, 0); CopyElement(pElementDir, hDir, hDS, TAG_SERIES_NUMBER); } else { CopyElement(pElementDir, hDir, hDS, TAG_SERIES_NUMBER); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_RECORD_IN_USE_FLAG, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_RECORD_IN_USE_FLAG, VR_US, FALSE, 0); CopyElement(pElementDir, hDir, hDS, TAG_RECORD_IN_USE_FLAG); } else { CopyElement(pElementDir, hDir, hDS, TAG_RECORD_IN_USE_FLAG); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_SPECIFIC_CHARACTER_SET, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_SPECIFIC_CHARACTER_SET, VR_CS, FALSE, 0); CopyElement(pElementDir, hDir, hDS, TAG_SPECIFIC_CHARACTER_SET); } else { CopyElement(pElementDir, hDir, hDS, TAG_SPECIFIC_CHARACTER_SET); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_REFERENCED_FILE_ID, TRUE); if (pElementDir == NULL) { L_BOOL bRet; pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_REFERENCED_FILE_ID, VR_CS, FALSE, 0); bRet = L_DicomSetConvertValue(hDir, pElementDir, szSeriesPath, 0); } else { L_BOOL bRet; bRet = L_DicomSetConvertValue(hDir, pElementDir, szSeriesPath, 0); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// pElementDir = L_DicomFindFirstElement(hDir, pElementDir, TAG_RECORD_IN_USE_FLAG, TRUE); if (pElementDir == NULL) { L_BOOL bRet; pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_RECORD_IN_USE_FLAG, VR_US, FALSE, 0); bRet = L_DicomSetConvertValue(hDir, pElementDir, (L_CHAR *)(LPCTSTR)"65535", 1); } else { L_BOOL bRet; bRet = L_DicomSetConvertValue(hDir, pElementDir, (L_CHAR *)(LPCTSTR)"65535", 1); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// DeleteElement(hDir, pSeriesKey, TAG_REFERENCED_FILE_ID); DeleteElement(hDir, pSeriesKey, TAG_PRIVATE_RECORD_UID); DeleteElement(hDir, pSeriesKey, TAG_REFERENCED_SOP_CLASS_UID_IN_FILE); DeleteElement(hDir, pSeriesKey, TAG_REFERENCED_SOP_INSTANCE_UID_IN_FILE); DeleteElement(hDir, pSeriesKey, TAG_REFERENCED_TRANSFER_SYNTAX_UID_IN_FILE); ////////////////////////////////////////////////////////////////////////////////////////////////////////// } if (pszText != NULL) { free(pszText); pszText = NULL; } // Insert a new Image Key. pElement = L_DicomFindFirstElement(hDS, NULL, TAG_SOP_INSTANCE_UID, FALSE); if (pElement != NULL) { nLength = L_DicomGetConvertValue(hDS, pElement, NULL); pszText = (L_CHAR *)malloc(nLength); L_DicomGetConvertValue(hDS, pElement, pszText); pKey = FindKey(hDir, pszText, pSeriesKey); if (pKey == NULL) { pElement = NULL; pElementDir = NULL; pKey = L_DicomInsertKey(hDir, pSeriesKey, "IMAGE", FALSE); if (pKey == NULL) { return FALSE; } pImageKey = pKey; } else { pImageKey = pKey; } // returns Image Key pChildDir = L_DicomGetChildElement(hDir, pKey, TRUE); if (pChildDir == NULL) { return FALSE; } ////////////////////////////////////Copy the require elements from DataSet to DICOMDIR//////////////////// pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_SOP_INSTANCE_UID, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_SOP_INSTANCE_UID, VR_UI, FALSE, 0); } if (pElementDir != NULL) { L_BOOL bRet; bRet = L_DicomSetConvertValue(hDir, pElementDir, pszText, 1); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_SPECIFIC_CHARACTER_SET, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_SPECIFIC_CHARACTER_SET, VR_CS, FALSE, 0); CopyElement(pElementDir, hDir, hDS, TAG_SPECIFIC_CHARACTER_SET); } else { CopyElement(pElementDir, hDir, hDS, TAG_SPECIFIC_CHARACTER_SET); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_IMAGE_TYPE, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_IMAGE_TYPE, VR_CS, FALSE, 0); CopyElement(pElementDir, hDir, hDS, TAG_IMAGE_TYPE); } else { CopyElement(pElementDir, hDir, hDS, TAG_IMAGE_TYPE); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_INSTANCE_NUMBER, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_INSTANCE_NUMBER, VR_IS, FALSE, 0); CopyElement(pElementDir, hDir, hDS, TAG_INSTANCE_NUMBER); } else { CopyElement(pElementDir, hDir, hDS, TAG_INSTANCE_NUMBER); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_REFERENCED_SOP_CLASS_UID_IN_FILE, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_REFERENCED_SOP_CLASS_UID_IN_FILE, VR_UI, FALSE, 0); CopyElementEx(pElementDir, hDir, hDS, TAG_REFERENCED_SOP_CLASS_UID_IN_FILE, TAG_SOP_CLASS_UID); } else { CopyElementEx(pElementDir, hDir, hDS, TAG_REFERENCED_SOP_CLASS_UID_IN_FILE, TAG_SOP_CLASS_UID); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_REFERENCED_SOP_INSTANCE_UID_IN_FILE, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_REFERENCED_SOP_INSTANCE_UID_IN_FILE, VR_UI, FALSE, 0); CopyElementEx(pElementDir, hDir, hDS, TAG_REFERENCED_SOP_INSTANCE_UID_IN_FILE, TAG_SOP_INSTANCE_UID); } else { CopyElementEx(pElementDir, hDir, hDS, TAG_REFERENCED_SOP_INSTANCE_UID_IN_FILE, TAG_SOP_INSTANCE_UID); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_REFERENCED_TRANSFER_SYNTAX_UID_IN_FILE, TRUE); if (pElementDir == NULL) { pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_REFERENCED_TRANSFER_SYNTAX_UID_IN_FILE, VR_UI, FALSE, 0); CopyElementEx(pElementDir, hDir, hDS, TAG_REFERENCED_TRANSFER_SYNTAX_UID_IN_FILE, TAG_TRANSFER_SYNTAX_UID); } else { CopyElementEx(pElementDir, hDir, hDS, TAG_REFERENCED_TRANSFER_SYNTAX_UID_IN_FILE, TAG_TRANSFER_SYNTAX_UID); } pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_REFERENCED_FILE_ID, TRUE); if (pElementDir == NULL) { L_BOOL bRet; pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_REFERENCED_FILE_ID, VR_CS, FALSE, 0); bRet = L_DicomSetConvertValue(hDir, pElementDir, pszImag, 1); } else { L_BOOL bRet; bRet = L_DicomSetConvertValue(hDir, pElementDir, pszImag, 1); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// pElementDir = L_DicomFindFirstElement(hDir, pChildDir, TAG_RECORD_IN_USE_FLAG, TRUE); if (pElementDir == NULL) { L_BOOL bRet; pElementDir = L_DicomInsertElement(hDir, pChildDir, FALSE, TAG_RECORD_IN_USE_FLAG, VR_US, FALSE, 0); bRet = L_DicomSetConvertValue(hDir, pElementDir, (L_CHAR *)(LPCTSTR)"65535", 1); } else { L_BOOL bRet; bRet = L_DicomSetConvertValue(hDir, pElementDir, (L_CHAR *)(LPCTSTR)"65535", 1); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// DeleteElement(hDir, pImageKey, TAG_PRIVATE_RECORD_UID); ////////////////////////////////////////////////////////////////////////////////////////////////////////// bRet = TRUE; } if (pszText != NULL) { free(pszText); pszText = NULL; } return bRet; } L_VOID CopyElement(pDICOMELEMENT pElementDir, HDICOMDS hDir, HDICOMDS hDS, L_UINT32 nTag) { // Copy an element from DICOM file to DICOMDIR file. pDICOMELEMENT pElement; L_CHAR *pszText; L_UINT32 nLength; pszText = NULL; pElement = L_DicomFindFirstElement(hDS, NULL, nTag, FALSE); if (pElement != NULL) { nLength = pElement->nLength; if (nLength != 0) { pszText = (L_CHAR *)malloc(nLength + 1); if (pszText == NULL) { return; } pszText[nLength] = '\0'; //Updates a buffer with a binary value. L_DicomGetBinaryValue(hDS, pElement, pszText, nLength); } else { pszText = NULL; } if ((pElementDir != NULL) && (pszText != NULL)) { pElementDir = L_DicomFindFirstElement(hDir, pElementDir, nTag, TRUE); if (pElementDir != NULL) { //Sets the binary value of an element. L_DicomSetBinaryValue(hDir, pElementDir, pszText, nLength); } } if (pszText != NULL) { free(pszText); pszText = NULL; } } } pDICOMELEMENT FindKey(HDICOMDS hDir, L_CHAR *pszValue, pDICOMELEMENT pParent) { // Find a specify key into DICOMDIR file. pDICOMELEMENT pKey, pChild, pElement; L_CHAR *pszText; L_CHAR L_FAR *pVal=NULL; L_UINT32 nLength; pszText = NULL; nLength = 0; if (pszValue == NULL) { return NULL; } //Find a Patient Key if (pParent == NULL) { //Returns a pointer to the first item in the Dicom Dir Data Set. pKey = L_DicomGetFirstKey(hDir, NULL, TRUE); while (pKey != NULL) { //Returns a pointer to the item in the Data Set //that contains the first child of the specified item. pChild = L_DicomGetChildElement(hDir, pKey, TRUE); if (pChild != NULL) { //Returns a pointer to the first item in the Data Set with the specified tag. pElement = L_DicomFindFirstElement(hDir, pChild, TAG_PATIENT_ID, TRUE); if (pElement != NULL) { //Converts the value of an element to a string, and //returns the number of characters in that string. nLength = L_DicomGetConvertValue(hDir, pElement, NULL); pszText = (L_CHAR *)malloc(nLength); if (pszText == NULL) { return NULL; } L_DicomGetConvertValue(hDir, pElement, pszText); if (strcmp(pszText, pszValue) == 0) { if (pszText != NULL) { free(pszText); pszText = NULL; } return pKey; break; } } } //Returns a pointer to the next item in the Dicom Dir Data Set with a specific key element type. pKey = L_DicomFindNextKey(hDir, pKey, TRUE); } if (pszText != NULL) { free(pszText); pszText = NULL; } return pKey; } else { // Find patient key. pVal= NULL; pKey = NULL; //Returns the key element type of the specified key element. pVal = L_DicomGetValueKey(hDir, pParent); if (strcmp(pVal, "PATIENT") == 0) { pKey = L_DicomGetChildKey(hDir, pParent); if (pKey != NULL) { //Returns the key element type of the specified key element. pVal = L_DicomGetValueKey(hDir, pKey); if (strcmp(pVal,"STUDY") == 0) { //Returns a pointer to the first item in the Dicom Dir Data Set. pKey = L_DicomGetFirstKey(hDir, pKey, TRUE); while (pKey != NULL) { //Returns a pointer to the item in the Data Set //that contains the first child of the specified item. pChild = L_DicomGetChildElement(hDir, pKey, TRUE); if (pChild != NULL) { //Returns a pointer to the first item in the Data Set with the specified tag. pElement = L_DicomFindFirstElement(hDir, pChild, TAG_STUDY_INSTANCE_UID, TRUE); if (pElement != NULL) { nLength = L_DicomGetConvertValue(hDir, pElement, NULL); pszText = (L_CHAR *)malloc(nLength); if (pszText == NULL) { return NULL; } L_DicomGetConvertValue(hDir, pElement, pszText); if (strcmp(pszText, pszValue) == 0) { if (pszText != NULL) { free(pszText); pszText = NULL; } return pKey; break; } } } pKey = L_DicomFindNextKey(hDir, pKey, TRUE); } if (pszText != NULL) { free(pszText); pszText = NULL; } return pKey; } } } // Find study key. if (strcmp(pVal,"STUDY") == 0) { //Returns the key element type of the specified key element. pKey = L_DicomGetChildKey(hDir, pParent); if (pKey != NULL) { //Returns the key element type of the specified key element. pVal = L_DicomGetValueKey(hDir, pKey); if (strcmp(pVal, "SERIES") == 0) { //Returns a pointer to the first item in the Dicom Dir Data Set. pKey = L_DicomGetFirstKey(hDir, pKey, TRUE); while (pKey != NULL) { //Returns a pointer to the item in the Data Set //that contains the first child of the specified item. pChild = L_DicomGetChildElement(hDir, pKey, TRUE); if (pChild != NULL) { //Returns a pointer to the first item in the Data Set with the specified tag. pElement = L_DicomFindFirstElement(hDir, pChild, TAG_SERIES_INSTANCE_UID, TRUE); if (pElement != NULL) { nLength = L_DicomGetConvertValue(hDir, pElement, NULL); pszText = (L_CHAR *)malloc(nLength); L_DicomGetConvertValue(hDir, pElement, pszText); if (strcmp(pszText, pszValue) == 0) { if (pszText != NULL) { free(pszText); pszText = NULL; } return pKey; break; } } } pKey = L_DicomFindNextKey(hDir, pKey, TRUE); } if (pszText != NULL) { free(pszText); pszText = NULL; } return pKey; } } } // Find series key. if (strcmp(pVal, "SERIES") == 0) { pKey = L_DicomGetChildKey(hDir, pParent); if (pKey != NULL) { pVal = L_DicomGetValueKey(hDir, pKey); if (strcmp(pVal, "IMAGE") == 0) { pKey = L_DicomGetFirstKey(hDir, pKey, TRUE); while (pKey != NULL) { pChild = L_DicomGetChildElement(hDir, pKey, TRUE); if (pChild != NULL) { pElement = L_DicomFindFirstElement(hDir, pChild, TAG_SOP_INSTANCE_UID, TRUE); if (pElement != NULL) { nLength = L_DicomGetConvertValue(hDir, pElement, NULL); pszText = (L_CHAR *)malloc(nLength); L_DicomGetConvertValue(hDir, pElement, pszText); if (strcmp(pszText, pszValue) == 0) { if (pszText != NULL) { free(pszText); pszText = NULL; } return pKey; break; } } } pKey = L_DicomFindNextKey(hDir, pKey, TRUE); } if (pszText != NULL) { free(pszText); pszText = NULL; } return pKey; } } } if (pszText != NULL) { free(pszText); pszText = NULL; } return pKey; } } /**********************************************************************************************/ L_VOID FillTree(HWND hDlg, HDICOMDS hDir, HTREEITEM hParentTree, pDICOMELEMENT pParentElement) { // Fill tree items. pDICOMELEMENT pElement; HTREEITEM hItem; L_CHAR *pszText; L_UINT32 nClass; TV_INSERTSTRUCT tvis; L_DicomGetInfoDS(hDir, &nClass, NULL); if ((m_bHighLevel == FALSE) || (nClass != CLASS_BASIC_DIRECTORY)) { // Fill subtree items. FillSubTree(hDlg, hDir, hParentTree, pParentElement); return; } if (pParentElement == NULL) { pElement = L_DicomGetFirstKey(hDir, NULL, TRUE); } else { pElement = L_DicomGetChildKey(hDir, pParentElement); } while (pElement != NULL) { pszText = L_DicomGetValueKey(hDir, pElement); if (pszText == NULL) { strcpy(pszText, "Unknown"); } tvis.hParent = hParentTree; tvis.item.lParam = 0; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_IMAGE | TVIF_PARAM | TVIF_TEXT | TVIF_SELECTEDIMAGE; tvis.item.pszText = pszText; tvis.item.iImage = IMAGE_FOLDER_CLOSED; tvis.item.iSelectedImage = tvis.item.iImage; //Inserts a new item in a tree view control. hItem = TreeView_InsertItem(GetDlgItem(hDlg, IDC_TREE), &tvis); m_bHighLevel = FALSE; // Fill subtree items. FillSubTree(hDlg, hDir, hItem, pElement); m_bHighLevel = TRUE; if ((pElement->nLength == ELEMENT_LENGTH_MAX) && (L_DicomGetChildKey(hDir, pElement) != NULL)) { if (L_DicomGetChildKey(hDir, pElement) != NULL) { FillTree(hDlg, hDir, hItem, pElement); } } pElement = L_DicomGetNextKey(hDir, pElement, TRUE); } } L_VOID FillSubTree(HWND hDlg, HDICOMDS hDir, HTREEITEM hParentTree, pDICOMELEMENT pParentElement) { // Fill subtree items. L_UINT32 i; L_UINT32 j; L_UINT32 nCount; L_UINT32 nClass; L_UINT16 nFlags; pDICOMMODULE pModule; pDICOMELEMENT pElement; pDICOMIOD pIOD; HTREEITEM hItem; L_CHAR szName[256]; TV_INSERTSTRUCT tvis; if (m_bHighLevel == FALSE) { if (pParentElement == NULL) { pElement = L_DicomGetFirstElement(hDir, NULL, TRUE, TRUE); } else { pElement = L_DicomGetChildElement(hDir, pParentElement, TRUE); } while (pElement != NULL) { // Insert a new element in TreeControl. hItem = InsertTreeElement(hDlg, hParentTree, pElement); if ((pElement->nLength == ELEMENT_LENGTH_MAX) && (L_DicomGetChildElement(hDir, pElement, TRUE) != NULL)) { if (L_DicomGetChildElement(hDir, pElement, TRUE) != NULL) { FillSubTree(hDlg, hDir, hItem, pElement); } } pElement = L_DicomGetNextElement(hDir, pElement, TRUE, TRUE); } } else { if (pParentElement == NULL) { L_DicomGetInfoDS(hDir, &nClass, &nFlags); nCount = L_DicomGetCountModule(hDir); for (i = 0; i < nCount; i++) { pModule = L_DicomFindIndexModule(hDir, i); if (pModule != NULL) { //Returns a pointer to the item in the IOD Structure that contains //the IOD for the specified module in the specified class. pIOD = L_DicomFindModuleIOD(nClass, pModule->nModule); if (pIOD != NULL) { strcpy(szName, pIOD->pszName); } else { strcpy(szName, "Unknown"); } tvis.hParent = hParentTree; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_IMAGE | TVIF_PARAM | TVIF_TEXT | TVIF_SELECTEDIMAGE; tvis.item.lParam = 0; tvis.item.pszText = szName; tvis.item.iImage = IMAGE_FOLDER_CLOSED; tvis.item.iSelectedImage = tvis.item.iImage; // Insert a new element in TreeControl. hParentTree = TreeView_InsertItem(GetDlgItem(hDlg, IDC_TREE), &tvis); for (j = 0; j < pModule->nCount; j++) { // Insert a new element in TreeControl. hItem = InsertTreeElement(hDlg, hParentTree, pModule->pElement[j]); if (L_DicomGetChildElement(hDir, pModule->pElement[j], TRUE) != NULL) { FillSubTree(hDlg, hDir, hItem, pModule->pElement[j]); } } } } } else { pElement = L_DicomGetChildElement(hDir, pParentElement, TRUE); while (pElement != NULL) { // Insert a new element in TreeControl. hItem = InsertTreeElement(hDlg, hParentTree, pElement); if ((pElement->nLength == ELEMENT_LENGTH_MAX) && (L_DicomGetChildElement(hDir, pElement, TRUE) != NULL)) { if (L_DicomGetChildElement(hDir, pElement, TRUE) != NULL) { FillSubTree(hDlg, hDir, hItem, pElement); } } pElement = L_DicomGetNextElement(hDir, pElement, TRUE, TRUE); } } } } HTREEITEM InsertTreeElement(HWND hDlg, HTREEITEM hParentTree, pDICOMELEMENT pElement) { // Insert a new element in TreeControl. L_CHAR szName[MAX_PATH]; pDICOMTAG pTag; HTREEITEM hItem; TV_INSERTSTRUCT tvis; if (pElement == NULL) { return NULL; } pTag = L_DicomFindTag(pElement->nTag); wsprintf(szName, "%04X:%04X - %s", GETGROUP(pElement->nTag), GETELEMENT(pElement->nTag), (pTag != NULL) ? pTag->pszName : "Unknown"); if (pElement->nLength == ELEMENT_LENGTH_MAX) { tvis.hParent = hParentTree; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_IMAGE | TVIF_PARAM | TVIF_TEXT | TVIF_SELECTEDIMAGE; tvis.item.lParam = (LPARAM)pElement; tvis.item.pszText = szName; tvis.item.iImage = IMAGE_ITEM; tvis.item.iSelectedImage = tvis.item.iImage; hItem = TreeView_InsertItem(GetDlgItem(hDlg, IDC_TREE), &tvis); } else { tvis.hParent = hParentTree; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_IMAGE | TVIF_PARAM | TVIF_TEXT | TVIF_SELECTEDIMAGE; tvis.item.lParam = (LPARAM)pElement; tvis.item.pszText = szName; tvis.item.iImage = IMAGE_ITEM; tvis.item.iSelectedImage = tvis.item.iImage; hItem = TreeView_InsertItem(GetDlgItem(hDlg, IDC_TREE), &tvis); } return hItem; } L_VOID ShowValue(HWND hDlg, HDICOMDS hDir, HTREEITEM hItem) { // Display the element value. L_UINT32 i; L_UINT32 nCount=0; L_UINT32 nLength; L_CHAR *pszValue; L_CHAR *p; L_CHAR *q; pDICOMELEMENT pElement; TV_INSERTSTRUCT tvis; TV_ITEM item; L_CHAR szText[200]; TreeView_DeleteAllItems(GetDlgItem(hDlg, IDC_LIST)); InvalidateRect(GetDlgItem(hDlg, IDC_LIST),NULL, TRUE); if (hItem != NULL) { item.mask = TVIF_TEXT|TVIF_HANDLE|TVIF_PARAM; item.cchTextMax = sizeof(szText); item.hItem = hItem; item.pszText = szText; //Returns the 32-bit application-specific value associated with an item. TreeView_GetItem(GetDlgItem(hDlg, IDC_TREE), &item); Data.pCurrentElement = (pDICOMELEMENT)item.lParam; pElement = (pDICOMELEMENT)item.lParam; if (pElement == NULL) { hItem = NULL; return; } } if ((hItem == NULL) || (L_DicomExistsElement(hDir, pElement) == FALSE)) { //Deletes all items from the control. TreeView_DeleteAllItems(GetDlgItem(hDlg, IDC_LIST)); InvalidateRect(GetDlgItem(hDlg, IDC_LIST),NULL, TRUE); return; } nCount = L_DicomGetCountValue(hDir, pElement); L_DicomFreeValue(hDir, pElement); if (nCount == 0) { return; } nLength = L_DicomGetConvertValue(hDir, pElement, NULL); if (nLength == 0) { if(pElement->nVR == VR_DA) { L_CHAR szValue[256]; pVALUEDATE pDate=NULL; for (i = 0; i < nCount; i++) { pDate = L_DicomGetDateValue(hDir, pElement, i, 1); if(pDate) { wsprintf(szValue, "%d/%d/%d", pDate->nDay, pDate->nMonth, pDate->nYear); tvis.hParent = NULL; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_IMAGE | TVIF_PARAM | TVIF_TEXT | TVIF_SELECTEDIMAGE; tvis.item.lParam = (LPARAM)pElement; tvis.item.pszText = szValue; hItem = TreeView_InsertItem(GetDlgItem(hDlg, IDC_LIST), &tvis); } } } return; } pszValue = (L_CHAR *)malloc(nLength); if (pszValue == NULL) { return; } nLength = L_DicomGetConvertValue(hDir, pElement, pszValue); for (i = 0, p = pszValue; i < nCount; i++) { if (nCount > 1) { q = strchr(p, '\\'); if (q != NULL) { *q = 0; } } tvis.hParent = NULL; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_IMAGE | TVIF_PARAM | TVIF_TEXT | TVIF_SELECTEDIMAGE; tvis.item.lParam = (LPARAM)pElement; tvis.item.pszText = p; hItem = TreeView_InsertItem(GetDlgItem(hDlg, IDC_LIST), &tvis); p += strlen(p) + 1; } free(pszValue); } L_VOID HandleNotify(HWND hDlg, WPARAM idCtl, LPNMHDR pNMHDR) { TV_ITEM item; L_CHAR szText[200]; NM_TREEVIEW* pNMTreeView=NULL; if(idCtl == IDC_TREE) { pNMTreeView = (NM_TREEVIEW*)pNMHDR; switch(pNMHDR->code) { case TVN_SELCHANGED: ShowWindow(GetDlgItem(hDlg, IDC_LIST), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_IMAGEBTN), SW_HIDE); ListBox_ResetContent(GetDlgItem(hDlg, IDC_LIST)); if(Data.Bitmap.Flags.Allocated) L_FreeBitmap(&Data.Bitmap); L_GetBitmapListCount(Data.hBitmapList, &Data.BitmapListCount); if(Data.BitmapListCount > 0) L_DeleteBitmapListItems(Data.hBitmapList, 0, Data.BitmapListCount); Data.nCurrentModule = (L_UINT32)-1; item.mask = TVIF_TEXT|TVIF_HANDLE|TVIF_PARAM; item.cchTextMax = sizeof(szText); item.hItem = pNMTreeView->itemNew.hItem; item.pszText = szText; TreeView_GetItem(GetDlgItem(hDlg, IDC_TREE), &item); ////////////////////////////// Data.bHighLevel = m_bHighLevel; ShowValue(hDlg, m_hDir, pNMTreeView->itemNew.hItem); break; case TVN_ITEMEXPANDED: item.hItem = pNMTreeView->itemNew.hItem; item.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE; if((pNMTreeView->itemNew.state & TVIS_EXPANDED)==TVIS_EXPANDED) item.iImage = IMAGE_FOLDER_OPEN; else item.iImage = IMAGE_FOLDER_CLOSED; item.iSelectedImage = item.iImage; TreeView_SetItem(GetDlgItem(hDlg, IDC_TREE), &item); break; case NM_DBLCLK: ListBox_ResetContent(GetDlgItem(hDlg, IDC_LIST)); if(Data.Bitmap.Flags.Allocated) L_FreeBitmap(&Data.Bitmap); L_GetBitmapListCount(Data.hBitmapList, &Data.BitmapListCount); if(Data.BitmapListCount > 0) L_DeleteBitmapListItems(Data.hBitmapList, 0, Data.BitmapListCount); Data.nCurrentModule = (L_UINT32)-1; if (Data.pCurrentElement == NULL) { return; } DisplayImage(hDlg, Data.pCurrentElement, m_hDir); break; } } } L_VOID ConvertError(L_INT nError, L_CHAR *pszError) { // Convert error code in message. L_INT i; L_CHAR *p; for (i = 0, p = NULL; i < sizeof(m_Error) / sizeof(m_Error[0]); i++) { if (nError == m_Error[i].nCode) { p = m_Error[i].pszText; break; } } if (p == NULL) { wsprintf(pszError, "%d", nError); } else { pszError = p; } } L_VOID DrawImageBtn(HWND hDlg, LPDRAWITEMSTRUCT pds) { BITMAPHANDLE TmpBitmap; if(Data.BitmapListCount > 0) { /* Get a copy of the image's bitmap handle */ L_GetBitmapListItem(Data.hBitmapList, Data.BitmapListIndex, &TmpBitmap,sizeof(BITMAPHANDLE)); PaintBitmap(pds->hDC, &Data.rcDst, &TmpBitmap); return; } if(Data.Bitmap.Flags.Allocated) { PaintBitmap(pds->hDC, &Data.rcDst, &Data.Bitmap); return; } return; } L_VOID PaintBitmap(HDC hDC, LPRECT pDest, pBITMAPHANDLE pBitmap) { HPALETTE hPaintPal, hOldPal; HBRUSH hBrush, hOldBrush; HPEN hPen, hOldPen; RECT rcDest; hBrush = GetStockObject(GRAY_BRUSH); hPen = GetStockObject(BLACK_PEN); hOldBrush = SelectObject(hDC, hBrush); hOldPen = SelectObject(hDC, hPen); CopyRect(&rcDest, pDest); hPaintPal = L_CreatePaintPalette(hDC, pBitmap); if(hPaintPal) { hOldPal = SelectPalette(hDC, hPaintPal, FALSE); RealizePalette(hDC); } L_PaintDC(hDC, pBitmap, NULL, NULL, &rcDest, NULL, SRCCOPY); if(hPaintPal) { SelectPalette(hDC, hOldPal, FALSE); DeleteObject(hPaintPal); } SelectObject(hDC, hOldBrush); SelectObject(hDC, hOldPen); return; } L_VOID DisplayBitmap(HWND hDlg, pDICOMELEMENT pElement, HDICOMDS hDS) { HCURSOR hOldCursor=NULL; L_CHAR szCaption[L_MAXPATH+50]; L_UINT16 nRet; hOldCursor = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); ShowWindow(GetDlgItem(hDlg, IDC_LIST), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_IMAGEBTN), SW_SHOW); ListBox_ResetContent(GetDlgItem(hDlg, IDC_LIST)); Data.bImage = FALSE; if(Data.Bitmap.Flags.Allocated) L_FreeBitmap(&Data.Bitmap); L_GetBitmapListCount(Data.hBitmapList, &Data.BitmapListCount); if(Data.BitmapListCount > 0) L_DeleteBitmapListItems(Data.hBitmapList, 0, Data.BitmapListCount); /* get the value */ GetWindowText(hDlg, szCaption, sizeof(szCaption)); nRet = L_DicomGetImage( Data.hDicomDS, pElement, &Data.Bitmap, sizeof(BITMAPHANDLE), 0, 0, ORDER_BGR, DICOM_GETIMAGE_AUTO_APPLY_MODALITY_LUT | DICOM_GETIMAGE_AUTO_APPLY_VOI_LUT | DICOM_GETIMAGE_ALLOW_RANGE_EXPANSION , NULL, NULL); SetWindowText(hDlg, szCaption); if(nRet == DICOM_SUCCESS) { L_DicomFreeValue(Data.hDicomDS, Data.pCurrentElement); /* display the value */ SetRect(&Data.rcDst, 0, 0, Data.Bitmap.Width, Data.Bitmap.Height); Data.Width = Data.Bitmap.Width; Data.Height = Data.Bitmap.Height; Data.bFit = TRUE; Data.Zoom = 100; // UpdateScrollBars(hDlg); Data.bImage = TRUE; // UpdateMenuStatus(hDlg); InvalidateRect(GetDlgItem(hDlg, IDC_IMAGEBTN), NULL, TRUE); UpdateWindow(GetDlgItem(hDlg, IDC_IMAGEBTN)); } else MessageBox(hDlg, "Error reading bitmap!", "Error", MB_OK); SetCursor(hOldCursor); } L_VOID DisplayImage(HWND hDlg, pDICOMELEMENT pElement, HDICOMDS hDir) { // Displays the selected image L_CHAR *pKeyValue, *pszText; pDICOMELEMENT pKey; L_UINT32 nLength; L_CHAR szPath[MAX_PATH]; nLength = 0; if (pElement == NULL) { return; } pKey = L_DicomGetParentKey(hDir, pElement); pKeyValue = (LPSTR)L_DicomGetValueKey(hDir, pElement); if ((pElement->nTag != TAG_REFERENCED_FILE_ID) || (strcmp("IMAGE", pKeyValue) != 0)) { return; } if (pElement != NULL) { nLength = L_DicomGetConvertValue(hDir, pElement, NULL); if (nLength == 0) { return; } pszText = (L_CHAR *)malloc(nLength); if (pszText == NULL) { return; } L_DicomGetConvertValue(hDir, pElement, pszText); strcpy(szPath, m_szPath); strcat(szPath, "\\"); strcat(szPath, pszText); L_DicomResetDS(Data.hDicomDS); L_DicomLoadDS(Data.hDicomDS, szPath, 0); Data.bLoaded = TRUE; Data.pCurrentElement = L_DicomFindFirstElement(Data.hDicomDS, NULL, TAG_PIXEL_DATA, FALSE); if (pElement == NULL) { return; } DisplayBitmap(hDlg, Data.pCurrentElement, hDir); UpdateScrollBars(hDlg); InvalidateRect(hDlg, NULL, TRUE); } } L_VOID UpdateScrollBars(HWND hDlg) { L_INT nWidth, nHeight, nVScroll, nHScroll; DWORD dwStyle; RECT rcClient; GetClientRect(GetDlgItem(hDlg, IDC_IMAGEBTN), &rcClient); if(Data.bFit) { nWidth = 0; nHeight = 0; } else { nWidth = MulDiv (Data.Width, Data.Zoom, 100); nHeight = MulDiv (Data.Height, Data.Zoom, 100); } Data.cxClient = RECTWIDTH(&rcClient); Data.cyClient = RECTHEIGHT(&rcClient); dwStyle = GetWindowLong(GetDlgItem(hDlg, IDC_IMAGEBTN), GWL_STYLE); nVScroll = GetSystemMetrics (SM_CXVSCROLL) - GetSystemMetrics(SM_CXBORDER); nHScroll = GetSystemMetrics (SM_CYHSCROLL) - GetSystemMetrics(SM_CYBORDER); if (WS_VSCROLL & dwStyle) Data.cxClient += nVScroll; if (WS_HSCROLL & dwStyle) Data.cyClient += nHScroll; if (Data.cxClient < nWidth) { Data.cyClient -= nHScroll; if (Data.cyClient < nHeight) Data.cxClient -= nVScroll; } else if (Data.cyClient < nHeight) { Data.cxClient -= nVScroll; if (Data.cxClient < nWidth) Data.cyClient -= nHScroll; } Data.nHScrollStep = max (1, Data.cxClient / SCROLL_RATIO); Data.nVScrollStep = max (1, Data.cyClient / SCROLL_RATIO); Data.nVScrollMax = max (0, (nHeight - Data.cyClient)); Data.nVScrollPos = max (0, min (Data.nVScrollPos, Data.nVScrollMax)); Data.nHScrollMax = max (0, (nWidth - Data.cxClient)); Data.nHScrollPos = max (0, min (Data.nHScrollPos, Data.nHScrollMax)); if(Data.bFit) { SetRect(&Data.rcDst, 0, 0, Data.cxClient, Data.cyClient); MatchAspectRatio (&Data.rcDst, MulDiv(Data.Width, Data.Zoom, 100), MulDiv(Data.Height, Data.Zoom, 100)); } else { SetRect (&Data.rcDst, 0, 0, nWidth, nHeight); OffsetRect (&Data.rcDst, -Data.nHScrollPos, -Data.nVScrollPos); } SetScrollRange (GetDlgItem(hDlg, IDC_IMAGEBTN), SB_HORZ, 0, Data.nHScrollMax, FALSE); SetScrollPos (GetDlgItem(hDlg, IDC_IMAGEBTN), SB_HORZ, Data.nHScrollPos, TRUE); SetScrollRange (GetDlgItem(hDlg, IDC_IMAGEBTN), SB_VERT, 0, Data.nVScrollMax, FALSE); SetScrollPos (GetDlgItem(hDlg, IDC_IMAGEBTN), SB_VERT, Data.nVScrollPos, TRUE); } L_VOID MatchAspectRatio (LPRECT pRect, L_INT nWidth, L_INT nHeight) { L_INT cxRect, cyRect; cyRect = RECTHEIGHT (pRect); cxRect = MulDiv (cyRect, nWidth, nHeight); if (cxRect > RECTWIDTH (pRect)) { cxRect = RECTWIDTH (pRect); cyRect = MulDiv (cxRect, nHeight, nWidth); } pRect->bottom = pRect->top + cyRect; pRect->right = pRect->left + cxRect; return; } L_VOID DeleteElement(HDICOMDS hDir, pDICOMELEMENT pKey, L_UINT32 nTag) { // Deletes the selected element. pDICOMELEMENT pChild, pElement; pChild = NULL; pElement = NULL; if (pKey == NULL) { return; } pChild = L_DicomGetChildElement(hDir, pKey, TRUE); if (pChild == NULL) { return; } pElement = L_DicomFindFirstElement(hDir, pChild, nTag, TRUE); if (pElement != NULL) { L_DicomDeleteElement(hDir, pElement); } } L_VOID CopyElementEx(pDICOMELEMENT pElementDir, HDICOMDS hDir, HDICOMDS hDS, L_UINT32 nTagDir, L_UINT32 nTagDS) { // Copy an element from DICOM file to DICOMDIR file. //This function is used when the tag number is not the same. pDICOMELEMENT pElement; L_CHAR *pszText; L_UINT32 nLength; pszText = NULL; pElement = L_DicomFindFirstElement(hDS, NULL, nTagDS, FALSE); if (pElement != NULL) { nLength = pElement->nLength; if (nLength != 0) { pszText = (L_CHAR *)malloc(nLength + 1); if (pszText == NULL) { return; } pszText[nLength] = '\0'; //Updates a buffer with a binary value. L_DicomGetBinaryValue(hDS, pElement, pszText, nLength); } else { pszText = NULL; } if ((pElementDir != NULL) && (pszText != NULL)) { pElementDir = L_DicomFindFirstElement(hDir, pElementDir, nTagDir, TRUE); if (pElementDir != NULL) { //Sets the binary value of an element. L_DicomSetBinaryValue(hDir, pElementDir, pszText, nLength); } } if (pszText != NULL) { free(pszText); pszText = NULL; } } }