#include "DP5ControlUtil.h" CDP5ControlUtil::CDP5ControlUtil(void) { } CDP5ControlUtil::~CDP5ControlUtil(void) { } int CDP5ControlUtil::OrderOut(int IndexIn) { if ((IndexIn >= DP5_CMD_MIN) && (IndexIn <= DP5_CMD_MAX)) { return IndexIn; } else { return -1; } } int CDP5ControlUtil::FindCboIdxExact(HWND hDlg, int cboDP5CtrlID, CString strVal) { int lRet; HWND m_cbo_hWnd; m_cbo_hWnd = GetDlgItem(hDlg,cboDP5CtrlID); if (m_cbo_hWnd == NULL) { return LB_ERR; } lRet = (int)SendMessage(m_cbo_hWnd, CB_FINDSTRINGEXACT, 0, (LPARAM)strVal.GetString()); return lRet; } int CDP5ControlUtil::FindCboIdx(HWND hDlg, int cboDP5CtrlID, CString strVal) { int lRet; HWND m_cbo_hWnd; m_cbo_hWnd = GetDlgItem(hDlg,cboDP5CtrlID); if (m_cbo_hWnd == NULL) { return LB_ERR; } lRet = (int)SendMessage(m_cbo_hWnd, CB_FINDSTRING, 0, (LPARAM)strVal.GetString()); return lRet; } void CDP5ControlUtil::SetCboIdxByStr(HWND hDlg, DP5_CONFIGURATION cfg) { int cboDP5CtrlID = cfg.ListCtrlID; CString strVal = cfg.Setting; int idx = FindCboIdx(hDlg,cboDP5CtrlID,strVal); HWND dlgItm = GetDlgItem(hDlg, cboDP5CtrlID); if (dlgItm != NULL) { CComboBox &cb = *(CComboBox *) dlgItm; cb.SetCurSel(idx); } } // test for the units in the value string int CDP5ControlUtil::FindUnitsInString(CString strValue, CString strUnits) { CString strValueUC; CString strUnitsUC; int iPos; strValueUC = strValue.MakeUpper(); strUnitsUC = strUnits.MakeUpper(); iPos = strValueUC.Find(strUnitsUC); return iPos; } // test if have units if so remove from text value string void CDP5ControlUtil::RemoveUnitsFromDecString(DP5_CONFIGURATION *cfg) { int iUnit; // unit position found, -1 if units not found CString strValue; if (cfg->Units.GetLength() > 0) { // has units, need to test iUnit = FindUnitsInString(cfg->Setting, cfg->Units); if (iUnit > -1) { cfg->bAppendUnits = TRUE; // append the usnits on save strValue = cfg->Setting.Left(iUnit); // remove the units cfg->Setting = strValue; } if ((cfg->CtrlType & dctCbo) > 0) { //has cbo val with possible units, must clear units to find cbo value iUnit = FindUnitsInString(cfg->ComboValue, cfg->Units); if (iUnit > -1) { cfg->bAppendUnits = TRUE; // append the usnits on save strValue = cfg->ComboValue.Left(iUnit); // remove the units cfg->ComboValue = strValue; } } if ((cfg->CtrlType & dctTxt) > 0) { // has text value iUnit = FindUnitsInString(cfg->TextValue, cfg->Units); if (iUnit > -1) { cfg->bAppendUnits = TRUE; // append the usnits on save strValue = cfg->TextValue.Left(iUnit); // remove the units cfg->TextValue = strValue; } } } } // test for the units in the value string CString CDP5ControlUtil::AppendUnitsToString(CString strValue, CString strUnits) { CString strValUnitsUC; strValUnitsUC = strValue.MakeUpper() + strUnits.MakeUpper(); if (strValUnitsUC.GetLength() > 10) { return strValue; } else { return strValUnitsUC; } return strValue; } // test if have units if so append void CDP5ControlUtil::AppendUnitsToSettingString(DP5_CONFIGURATION *cfg) { CString strValue; if (cfg->Units.GetLength() > 0) { // has units, need to test if (cfg->bAppendUnits) { // only append units if requested if (cfg->CtrlType == dctTxt) { // is text value only, can always append value cfg->Setting = AppendUnitsToString(cfg->Setting, cfg->Units); } else { // test cbo, if the value is numeric then append units if (IsAllNumericString(cfg->Setting)) { cfg->Setting = AppendUnitsToString(cfg->Setting, cfg->Units); } } } } } // test if have units if so append CString CDP5ControlUtil::GetValueWithUnitsString(DP5_CONFIGURATION cfg) { CString strValue; if (cfg.Units.GetLength() > 0) { // has units, need to test if (cfg.bAppendUnits) { // only append units if requested if ((cfg.CtrlType & dctTxt) > 0) { // is text value only, can always append value return AppendUnitsToString(cfg.TextValue, cfg.Units); } } } return cfg.TextValue; } void CDP5ControlUtil::UpdateSetting(DP5_CONFIGURATION *cfg) { if (cfg->CtrlType == dctCbo) { // is combo value only cfg->Setting = cfg->ComboValue; } else if (cfg->CtrlType == dctTxt) { // is text value only cfg->Setting = cfg->TextValue; } else if (cfg->CtrlType == dctCboTxt) { // is combo and text value if (cfg->ComboValue.Find('#') >= 0) { // this is the mask, use text cfg->Setting = cfg->TextValue; } else { // use combo value cfg->Setting = cfg->ComboValue; } } AppendUnitsToSettingString(cfg); // append units if any } void CDP5ControlUtil::UpdateSettingOsc(DP5_CONFIGURATION *cfg) { if (cfg->CtrlType == dctCbo) { // is combo value only cfg->Setting = cfg->ComboValue; } else if (cfg->CtrlType == dctTxt) { // is text value only cfg->Setting = cfg->TextValue; } else if (cfg->CtrlType == dctCboTxt) { // is combo and text value if (cfg->ComboValue.Find('#') >= 0) { // this is the mask, use text cfg->Setting = cfg->TextValue; } else { // use combo value cfg->Setting = cfg->ComboValue; } } } // test if have units if so remove from text value string BOOL CDP5ControlUtil::IsAllNumericString(CString strValue) { int iPos; // position Numeric Char Found int iPosCh; // position of character being tested CString strCh; // holds char to test for (iPosCh = 0; iPosCh -1) { // has all numeric characters return TRUE; } else { return FALSE; } }