/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[] []*/ /*[] utils.c []*/ /*[]=====================================================================[]*/ #include "utils.h" #include /* Windows' header for common controls. */ extern HWND hTreeMsg; extern HWND hTreeDir; extern HWND hTreeKey; extern HWND hTreeSession; extern HWND hWndMainGlobal; extern HDICOMDS hDSGlobal; BOOL TV_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck) { TV_ITEM tvItem; tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.hItem = hItem; tvItem.stateMask = TVIS_STATEIMAGEMASK; // Since state images are one-based, 1 in this macro turns the check off, and 2 turns it on. tvItem.state = INDEXTOSTATEIMAGEMASK((fCheck ? 2 : 1)); return TreeView_SetItem(hwndTreeView, &tvItem); } BOOL TV_GetCheckState(HWND hwndTreeView, HTREEITEM hItem) { TV_ITEM tvItem; // Prepare to receive the desired information. tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.hItem = hItem; tvItem.stateMask = TVIS_STATEIMAGEMASK; // Request the information. TreeView_GetItem(hwndTreeView, &tvItem); // Return zero if it's not checked, or nonzero otherwise. return ((BOOL)(tvItem.state >> 12) -1); } UINT TV_GetItemState(HWND hTreeView, HTREEITEM hItem, UINT stateMask) { TV_ITEM tvItem; // Prepare to receive the desired information. tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.hItem = hItem; tvItem.stateMask = stateMask; // Request the information. TreeView_GetItem(hTreeView, &tvItem); return tvItem.state; } BOOL TV_SetItemState(HWND hTreeView, HTREEITEM hItem, UINT state, UINT stateMask) { TV_ITEM tvItem; tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.hItem = hItem; tvItem.stateMask = stateMask; tvItem.state = state; return TreeView_SetItem(hTreeView, &tvItem); } DWORD TV_GetItemData(HWND hTreeView, HTREEITEM hItem) { TV_ITEM tvItem; //Get lParam of hItem tvItem.mask = TVIF_HANDLE| TVIF_PARAM; tvItem.hItem = hItem; TreeView_GetItem(hTreeView, &tvItem); return (DWORD)tvItem.lParam; } L_VOID TV_GetItemText(HWND hTreeView, HTREEITEM hItem, L_CHAR *szText, L_INT nLen) { TV_ITEM tvItem; //Get lParam of hItem tvItem.mask = TVIF_HANDLE | TVIF_TEXT; tvItem.hItem = hItem; tvItem.pszText = szText; tvItem.cchTextMax = nLen; TreeView_GetItem(hTreeView, &tvItem); } L_CHAR *IntToString(UINT iVal, L_CHAR *szVal) { wsprintf(szVal, "%d", iVal); return szVal; } L_VOID LogClear() { TreeView_DeleteAllItems(hTreeMsg); } L_VOID InfoClear() { TreeView_DeleteAllItems(hTreeDir); TreeView_DeleteAllItems(hTreeKey); //TreeView_DeleteAllItems(hTreeSession); } L_VOID AllClear() { TreeView_DeleteAllItems(hTreeDir); TreeView_DeleteAllItems(hTreeKey); //TreeView_DeleteAllItems(hTreeSession); TreeView_DeleteAllItems(hTreeMsg); } L_INT GetAllCount() { L_INT nRet; nRet = TreeView_GetCount(hTreeMsg) + TreeView_GetCount(hTreeDir) + TreeView_GetCount(hTreeKey); //TreeView_GetCount(hTreeSession); return nRet; } L_INT GetLogCount() { return TreeView_GetCount(hTreeMsg); } //Treat szMsg as multiple strings delimted by '\n' //Add first string as parent, and remaining strings a children HTREEITEM LogMessage(L_UINT uMsgType, L_CHAR *szMsg) { HTREEITEM hTreeItem; L_CHAR szBuf[MAX_STRING_LEN]; TV_INSERTSTRUCT tv; L_INT nLen; //holds length of buffer containing message L_INT i; strcpy(szBuf, szMsg); nLen = strlen(szBuf); for (i=0; i 0) TreeView_InsertItem(hTreeMsg, &tv); } } TreeView_EnsureVisible(hTreeMsg, hTreeItem ); return hTreeItem; } HTREEITEM LogMessage1(L_UINT uMsgType, L_INT nRet, L_CHAR *szMsg) { L_CHAR szTmp[MAX_STRING_LEN]; wsprintf(szTmp,"[%d]%s", nRet, szMsg); return LogMessage(uMsgType, szTmp); } //Add an item to a tree view as a child of hRoot HTREEITEM LogMessageChild(HTREEITEM hRoot, L_CHAR *szMsg1, L_CHAR *szMsg2) { HTREEITEM hTreeItem; TV_INSERTSTRUCT tv; L_CHAR szTmp[MAX_STRING_LEN]; lstrcpy(szTmp, szMsg1); lstrcat(szTmp, szMsg2); tv.hInsertAfter= TVI_LAST; tv.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; //add items to tree view tv.hParent = hRoot; tv.item.pszText = szTmp; tv.item.iImage = MSG_NONE; tv.item.iSelectedImage = MSG_NONE; hTreeItem = TreeView_InsertItem(hTreeMsg, &tv); return hTreeItem; } L_VOID CopyTagKey(HDICOMDS hDSsrc, HDICOMDS hDSdst, pDICOMELEMENT pElement, L_CHAR *szKey, L_UINT32 nTag) { L_CHAR *pszKey; L_CHAR *pszValue; L_UINT32 nLength; pDICOMELEMENT pChild; pDICOMELEMENT pNew; pNew = L_DicomFindFirstElement(hDSdst, NULL, nTag, TRUE); if (pNew == NULL) { pNew = L_DicomInsertElement(hDSdst, NULL, FALSE, nTag, 0, FALSE, 0); if (pNew == NULL) { return; } } while (pElement != NULL) { pszKey = L_DicomGetValueKey(hDSsrc, pElement); if ((pszKey != NULL) && (lstrcmp(szKey,pszKey)==0)) { pChild = L_DicomGetChildElement(hDSsrc, pElement, TRUE); if (pChild == NULL) { break; } pChild = L_DicomFindFirstElement(hDSsrc,pChild, nTag, TRUE); if (pChild == NULL) { break; } nLength = L_DicomGetConvertValue(hDSsrc, pChild, NULL); if (nLength > 0) { pszValue = (L_CHAR *)malloc(nLength); if (pszValue == NULL) { break; } L_DicomGetConvertValue(hDSsrc, pChild, pszValue); L_DicomSetConvertValue(hDSdst, pNew, pszValue, 1); free(pszValue); } break; } pElement = L_DicomGetParentKey(hDSsrc, pElement); } } L_BOOL CheckAvailability(pDICOMELEMENT pImageDR) { pDICOMELEMENT pElement; L_CHAR* pszInstanceAvailability, * pszMessage; if (pImageDR) { pElement = L_DicomGetChildElement(hDSGlobal, pImageDR, TRUE); if (pElement) { pElement = L_DicomFindFirstElement(hDSGlobal, pElement, TAG_INSTANCE_AVAILABILITY, TRUE); if (pElement) { pszInstanceAvailability = L_DicomGetStringValue(hDSGlobal, pElement, 0, 1); if (pszInstanceAvailability) { if (lstrcmpi("OFFLINE", pszInstanceAvailability) == 0) { L_DicomFreeValue(hDSGlobal, pElement); MessageBox(hWndMainGlobal, "The instance is OFFLINE.", "Demo", MB_OK | MB_ICONEXCLAMATION); return FALSE; } else if (lstrcmpi("NEARLINE", pszInstanceAvailability) == 0) { L_DicomFreeValue(hDSGlobal, pElement); pszMessage = "The instance needs to be retrieved from relatively slow " \ "media such as optical disk or tape. Do you want to proceed?"; if (MessageBox(hWndMainGlobal, pszMessage, "Demo", MB_YESNO) == IDYES) { return TRUE; } else { return FALSE; } } } } } } return TRUE; } void Trim(char* pszString) { int iLength, i, j; if (!pszString) return; // Trim from left iLength = lstrlen(pszString); for (i = 0; i < iLength; i++) if (pszString[i] != ' ') break; if (i != 0) { j = 0; while (i < iLength) pszString[j++] = pszString[i++]; pszString[j] = '\0'; } // Trim from right iLength = lstrlen(pszString); for (i = iLength - 1; i >= 0; i--) if (pszString[i] != ' ') { pszString[i + 1] = '\0'; break; } }