在VC中它的CString比起Delphi的String功能还是差多了~~
不过还能凑合用~~~真不如自己来构造个String类方便~~~
void CAddressAssistDlg::OnManualRun()
{
// TODO: Add your control notification handler code here
int i,j;
int nLineCnt; //总行数
int nLineLength; //每行字符个数
int status = 0;
int cnt = 0;
int cmd = 0;
BYTE wd = 0;
WORD addr = 0;
DWORD data = 0;
CString strText,str, sstr;
unsigned char ch,tmp;
nLineCnt = m_SendArea.GetLineCount();//得到Edit控件内字符的行数
for(i=0; i<nLineCnt; i++)
{
nLineLength = m_SendArea.LineLength(m_SendArea.LineIndex(i));
m_SendArea.GetLine(i,strText.GetBuffer(nLineLength),nLineLength);
strText.ReleaseBuffer(nLineLength);//在用GetBuffer申请内存空间后,立即调用ReleaseBuffer
strText.TrimRight(' ');//去除右端空格
strText += ';';//附加结尾符
for(j=0; j<strText.GetLength(); j++)//对某行内的字符进行命令行解码
{
ch = strText.GetAt(j);//取出strText[j]的内容
switch(ch)
{
case 'i':
case 'I'://GetPort命令
if(status == 0)
{
status = 1;
cnt = 0;
cmd = 1;
wd = 0;
addr = 0;
data = 0;
}
break;
case 'o':
case 'O'://SetPort命令
if(status == 0)
{
status = 1;
cnt = 0;
cmd = 2;
wd = 0;
addr = 0;
data = 0;
}
break;
case 't':
case 'T'://Delay命令
if(status == 0)
{
status = 1;
cnt = 0;
cmd = 3;
addr = 0;
data = 0;
}
break;
case 'w':
case 'W'://Word命令
if((status == 3 && cmd == 1) || (status == 4 && cmd == 2))
{
wd = 1;
}
else
{
MessageBox("非法字符!!!");
status = 0;
}
break;
case ' '://间隔符
if(status > 0)
{
if(cnt != 1)
{
if(cmd==3) status = 3;
else status++;
cnt = 1;
}
}
break;
case ';'://结尾符,执行命令
switch(cmd)
{
case 1://GetPort
if ((status == 2 && wd == 0) || (status == 3 && wd == 1))
{
GetPortVal(addr, &data, wd + 1);//读出端口数据
if (wd == 0)
{
str.Format("端口[%04x]=%02x\r\n", addr, BYTE(data));
}
else
{
str.Format("端口[%04x]=%04x\r\n", addr, WORD(data));
}
m_RecvArea.GetWindowText(sstr);
m_RecvArea.SetWindowText(sstr + str);
}
break;
case 2://SetPort
if ((status == 3 && wd == 0) || (status == 4 && wd == 1))
{
SetPortVal(addr, data, wd + 1);//写入端口数据
}
break;
case 3://Delay
Delay(data);
break;
}
status = 0;//本行命令结束
break;
default://数字分析
if(ch >='0' && ch <='9')
{
tmp = ch-'0';
}
else if(ch >='a' && ch <='f')
{
tmp = ch-'a'+10;
}
else if(ch >='A' && ch <='F')
{
tmp = ch-'A'+10;
}
else
{
MessageBox("非法字符!!!");
status = 0;
}
switch(status)
{
case 1://command
status = 0;
MessageBox("命令符后应该跟空格!!!");
break;
case 2://addr
addr <<= 4;
addr += tmp;
cnt ++;
break;
case 3://data
if (cmd != 3)
{
data <<= 4;
data |= tmp;
}
else if(tmp < 10)
{
data *= 10;
data += tmp;
}
else
{
MessageBox("T参数只能是10进制uS数!!!");
}
cnt ++;
break;
}
break;
}
}
}
}
void CAddressAssistDlg::OnManualRun()
{
// TODO: Add your control notification handler code here
int i,j;
int nLineCnt; //总行数
int nLineLength; //每行字符个数
int status = 0;
int cnt = 0;
int cmd = 0;
BYTE wd = 0;
WORD addr = 0;
DWORD data = 0;
CString strText,str, sstr;
unsigned char ch,tmp;
nLineCnt = m_SendArea.GetLineCount();//得到Edit控件内字符的行数
for(i=0; i<nLineCnt; i++)
{
nLineLength = m_SendArea.LineLength(m_SendArea.LineIndex(i));
m_SendArea.GetLine(i,strText.GetBuffer(nLineLength),nLineLength);
strText.ReleaseBuffer(nLineLength);//在用GetBuffer申请内存空间后,立即调用ReleaseBuffer
strText.TrimRight(' ');//去除右端空格
strText += ';';//附加结尾符
for(j=0; j<strText.GetLength(); j++)//对某行内的字符进行命令行解码
{
ch = strText.GetAt(j);//取出strText[j]的内容
switch(ch)
{
case 'i':
case 'I'://GetPort命令
if(status == 0)
{
status = 1;
cnt = 0;
cmd = 1;
wd = 0;
addr = 0;
data = 0;
}
break;
case 'o':
case 'O'://SetPort命令
if(status == 0)
{
status = 1;
cnt = 0;
cmd = 2;
wd = 0;
addr = 0;
data = 0;
}
break;
case 't':
case 'T'://Delay命令
if(status == 0)
{
status = 1;
cnt = 0;
cmd = 3;
addr = 0;
data = 0;
}
break;
case 'w':
case 'W'://Word命令
if((status == 3 && cmd == 1) || (status == 4 && cmd == 2))
{
wd = 1;
}
else
{
MessageBox("非法字符!!!");
status = 0;
}
break;
case ' '://间隔符
if(status > 0)
{
if(cnt != 1)
{
if(cmd==3) status = 3;
else status++;
cnt = 1;
}
}
break;
case ';'://结尾符,执行命令
switch(cmd)
{
case 1://GetPort
if ((status == 2 && wd == 0) || (status == 3 && wd == 1))
{
GetPortVal(addr, &data, wd + 1);//读出端口数据
if (wd == 0)
{
str.Format("端口[%04x]=%02x\r\n", addr, BYTE(data));
}
else
{
str.Format("端口[%04x]=%04x\r\n", addr, WORD(data));
}
m_RecvArea.GetWindowText(sstr);
m_RecvArea.SetWindowText(sstr + str);
}
break;
case 2://SetPort
if ((status == 3 && wd == 0) || (status == 4 && wd == 1))
{
SetPortVal(addr, data, wd + 1);//写入端口数据
}
break;
case 3://Delay
Delay(data);
break;
}
status = 0;//本行命令结束
break;
default://数字分析
if(ch >='0' && ch <='9')
{
tmp = ch-'0';
}
else if(ch >='a' && ch <='f')
{
tmp = ch-'a'+10;
}
else if(ch >='A' && ch <='F')
{
tmp = ch-'A'+10;
}
else
{
MessageBox("非法字符!!!");
status = 0;
}
switch(status)
{
case 1://command
status = 0;
MessageBox("命令符后应该跟空格!!!");
break;
case 2://addr
addr <<= 4;
addr += tmp;
cnt ++;
break;
case 3://data
if (cmd != 3)
{
data <<= 4;
data |= tmp;
}
else if(tmp < 10)
{
data *= 10;
data += tmp;
}
else
{
MessageBox("T参数只能是10进制uS数!!!");
}
cnt ++;
break;
}
break;
}
}
}
}
雁塔菜农 2008-10-22 20:29
sealove518_112732726 2008-10-22 15:47
用户402930 2008-10-22 12:15
zwj-gg_818035047 2008-10-21 13:31