📄 genericinput.cpp
字号:
}
}
BEGIN_MESSAGE_MAP(CGenericInput, CDialog)
ON_BN_CLICKED(ID_BUTTON_MAKEBUFFER, OnBnClickedButtonMakebuffer)
ON_NOTIFY(LVN_ENDLABELEDIT,IDC_LIST_DATASET_DETAILS,ListDropEditHandler)
ON_WM_WINDOWPOSCHANGING()
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_DATASET_DETAILS, OnLvnItemchangedListDatasetDetails)
ON_BN_CLICKED(IDC_BUTTON_ONCLOSE, OnBnClickedButtonOnclose)
END_MESSAGE_MAP()
int CGenericInput::DataSetValidationRoutine()
{
for(int i =0; i< dataset_details.GetItemCount();i++)
{
if(!(dataset_details.GetItemText(i,3).GetLength()))
return 0;
}
return 1;
}
// CGenericInput message handlers
void CGenericInput::OnBnClickedButtonMakebuffer()
{
CData dataobj;
CString WindowText;
CString WindowText1;
int response;
/*dataSet validation*/
if(DataSetValidationRoutine() == 0)
{
response = AfxMessageBox(IDS_STRING_ASK_FOR_DEFAULT_VAL_USE,MB_YESNO);
if(response == IDNO) /*want to have ur own values then fill, them*/
return;
}
CDataList datalist = GetFormatForMessage(OutGoingMsgPtr)->GetDataList();
for(POSITION pos = datalist.GetData().GetHeadPosition();pos!=NULL;)
{
dataobj = datalist.GetData().GetNext(pos);
if(dataobj.GetName().CompareNoCase(datalist.GetDefault()))
break;
}
data_set_to_be_sent.SetName(datalist.GetDefault());
data_set_to_be_sent.SetFrequency(dataobj.GetFrequency());
data_set_to_be_sent.SetTimer(dataobj.GetFrequency());
CList<CValue,CValue&>& default_vallist = dataobj.GetValueList();
int item_no = 0;
for(pos = default_vallist.GetHeadPosition(); item_no<dataset_details.GetItemCount();item_no++) /*common to new & old dataset*/
{
CValue val,val1;
val1 = default_vallist.GetNext(pos);
val.SetName(dataset_details.GetItemText(item_no,1));
if(!dataset_details.GetItemText(item_no,3).CompareNoCase(_T("")))
val.SetSourceValue(val1.GetSourceValue());
else
val.SetSourceValue(dataset_details.GetItemText(item_no,3));
val.SetSourceType(val1.GetSourceType());
val.SetValueSize(val1.GetValueSize());
val.SetCount(val1.GetCount());
data_set_to_be_sent.AddValue(val);
}
CDialog::OnOK();
// TODO: Add your control notification handler code here
}
void CGenericInput:: ListDropEditHandler(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO *plvDispInfo = (LV_DISPINFO *)pNMHDR;
LV_ITEM *plvItem = &plvDispInfo->item;
unsigned long number;
int returncode;
if(plvItem->pszText!=NULL)
{
CString datatype = dataset_details.GetItemText(plvItem->iItem,0);
if(!(datatype.CompareNoCase(_T("char"))))
{
int text_length = CString(plvItem->pszText).GetLength();
if((text_length == 1) &&((CString(plvItem->pszText).GetAt(0)>= 'a') &&(CString(plvItem->pszText).GetAt(0)<= 'z') ))
{
dataset_details.SetItemText(plvItem->iItem,plvItem->iSubItem,plvDispInfo->item.pszText);
}
else
{
returncode = ConvertToNumber(plvItem->pszText,&number);
if(returncode == -1)
{
if(number <= 255 )
{
dataset_details.SetItemText(plvItem->iItem,plvItem->iSubItem,plvDispInfo->item.pszText);
}
else
AfxMessageBox(IDS_STRING_RNG_INDICATION);
}
}
}
else if(!(datatype.CompareNoCase(_T("int"))))
{
returncode= ConvertToNumber(plvItem->pszText, &number);
if(returncode == -1)
{
if(number<= 2147483648 )
{
dataset_details.SetItemText(plvItem->iItem,plvItem->iSubItem,plvDispInfo->item.pszText);
}
else
AfxMessageBox(IDS_STRING_RNG_INDICATION);
}
}
else if(!(datatype.CompareNoCase(_T("short"))))
{
returncode = ConvertToNumber(plvItem->pszText, &number);
if(returncode == -1)
{
if(number<= ((2*SHRT_MAX)+1) )
{
dataset_details.SetItemText(plvItem->iItem,plvItem->iSubItem,plvDispInfo->item.pszText);
}
else
AfxMessageBox(IDS_STRING_RNG_INDICATION);
}
}
else
{
dataset_details.SetItemText(plvItem->iItem,plvItem->iSubItem,plvDispInfo->item.pszText);
}
}
}
int CGenericInput::ConvertToNumber(LPWSTR newstring, unsigned long *sum)
{
LPWSTR copyofnewstring = newstring;
int counter=0;
*sum = 0;
while(*copyofnewstring!='\0')
{
if((*copyofnewstring>='0' && *copyofnewstring<='9')&& counter <10)
{
int numericval;
numericval = (*copyofnewstring -48);
(*sum) = ((*sum)*10) + numericval;
copyofnewstring++;
counter++;
}
else
break;
}
if(*copyofnewstring == '\0')
return(-1);
else if(counter ==10)
{
OutPutMessage(TooLongAValue,newstring);
return(TooLongAValue);
}
else
{
OutPutMessage(ImproperInput,newstring);
return(ImproperInput);
}
}
void CGenericInput::OutPutMessage(Error_Type et,LPWSTR newstring)
{
CString MessageToBeDisplayed ;
switch(et)
{
case TooLongAValue:
AfxFormatString1(MessageToBeDisplayed,IDS_STRING_LONG_VAL_INDICATION,newstring);
AfxMessageBox(MessageToBeDisplayed);
break;
case ImproperInput:
AfxFormatString1(MessageToBeDisplayed,IDS_STRING_IMPROPER_VAL_INDICATION,newstring);
AfxMessageBox(MessageToBeDisplayed);
//AfxMessageBox(s);
break;
}
}
void CGenericInput::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
if (lpwndpos->cx == -1)
if (lpwndpos->cy == -1) // is init time
{
lpwndpos->x = 257; // change here if you want to move left or right the window.
lpwndpos->y = 41; // change here if you want to move top or bottom the window.
CDialog::OnWindowPosChanging(lpwndpos);
}
}
void CGenericInput::OnLvnItemchangedListDatasetDetails(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CGenericInput::OnBnClickedButtonOnclose()
{
CDialog::OnOK();
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -