📄 codescandlg.cpp
字号:
//将解释部分输出来 "//的情况"
if(ch=='/')
{
fs.get(ch);
while((ch!='\n')&&(ch!=EOF))
{
word[i++]=ch;
// cout<<ch;
fs.get(ch);
}
word[i]='\0';
// of.write(word,strlen(word));
//AfxMessageBox(word);
// //of.write(space,1);
// cout.width(wh);
// cout<<"解释部分"<<endl;
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"解释部分");
}
// "/*"的情况
else
{
char c;
fs.get(ch);
c=ch;
fs.get(ch);
while((c!='*'||ch!='/'))
{
word[i++]=ch;
c=ch;
fs.get(ch);
}
word[i++]=c;
word[i++]=ch;
word[i]='\0';
// of.write(word,strlen(word));
//AfxMessageBox(word);
// //of.write(space,1);
// cout<<c<<ch;
// cout.width(wh);
// cout<<"解释部分"<<endl;
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"解释部分");
fs.get(ch);
}
}
//除号情况
else{
word[i]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
// n=m_ListCtrl.GetItemCount();
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"除号");
// cout.width(wh);
// cout<<"除号"<<endl;
// fs.get(ch);
}
break;
case '*':
//判断是乘号还是指针
//指针情况
word[i++]=ch;
word[i++]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
if(flag==1)
{
// n=m_ListCtrl.GetItemCount();
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"指针");
// cout<<"指针"<<endl;
// flag=0;
}
//如果是乘号
else{
// n=m_ListCtrl.GetItemCount();
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"乘号");
}
fs.get(ch);
break;
//减号情况
case '-':
word[i++]=ch;
word[i++]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
// n=m_ListCtrl.GetItemCount();
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"减号");
fs.get(ch);
break;
//加号情况
case '+':
word[i++]=ch;
word[i++]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
// n=m_ListCtrl.GetItemCount();
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"加号");
fs.get(ch);
break;
//字符串情况
case '"':
word[i++]=ch;
fs.get(ch);
while(ch!='"')
{
word[i++]=ch;
fs.get(ch);
}
word[i++]=ch;
word[i]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
//cout<<word;
// n=m_ListCtrl.GetItemCount();
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"字符串");
// cout.width(wh);
// cout<<"特殊符号"<<endl;
fs.get(ch);
break;
//除号情况
case '%':
word[i++]=ch;
word[i++]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"取余号");
// cout<<"取余号"<<endl;
fs.get(ch);
break;
//等号情况
case '=':
word[i++]=ch;
word[i++]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"等号");
fs.get(ch);
break;
//取反号情况
case '~':
word[i++]=ch;
word[i++]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"取反号");
fs.get(ch);
break;
case '|':
word[i++]=ch;
fs.get(ch);
//或号情况
if(ch=='|')
{
word[i++]=ch;
word[i]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
fs.get(ch);
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"或号");
// cout<<"或号"<<endl;
}
//特殊符号情况
else
{
word[i]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"特殊符号");
}
break;
case '&':
word[i++]=ch;
fs.get(ch);
//与号情况
if(ch=='&')
{
word[i++]=ch;
word[i]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
fs.get(ch);
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"与号");
// cout<<"与号"<<endl;
}
else
{
word[i]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"引用号");
}
break;
//单引号的时候
case 39:
word[i++]=ch;
fs.get(ch);
while(ch!=39)
{
word[i++]=ch;
fs.get(ch);
}
word[i++]=ch;
word[i]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"字符");
fs.get(ch);
break;
default:
word[i++]=ch;
word[i]='\0';
of.write(word,strlen(word));
//AfxMessageBox(word);
//of.write(space,1);
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"特殊符号");
fs.get(ch);
break;
}
}
}
fs.close();
delete []word;
}
/*初始化列表控件*/
void CCodeScanDlg::OnInitailListCtrl()
{
LV_COLUMN lvcol;
int i;
i=0;
lvcol.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
lvcol.fmt=LVCFMT_CENTER;//表列对齐方式为居中
lvcol.pszText=" 字符串";
lvcol.iSubItem=i;
lvcol.cx=150;
m_ListCtrl.InsertColumn(i++,&lvcol);
lvcol.pszText="解释结果";
lvcol.iSubItem=i;
lvcol.cx=180;
m_ListCtrl.InsertColumn(i++,&lvcol);
//设置列表控件显示方式为详细资料方式
LONG lStyle;
//获取当前窗口类型
lStyle=GetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE);
lStyle&=~LVS_TYPEMASK;
lStyle |=LVS_REPORT;
SetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE,lStyle);
}
void CCodeScanDlg::Num(char *word)
{
n=m_ListCtrl.GetItemCount();
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"数字");
}
bool CCodeScanDlg::KeyWord(char *word)
{
int k;
k=IsKey(word);
if(k==1)
{
n=m_ListCtrl.GetItemCount();
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"关键字");
// cout<<"关键字"<<endl;
return 1;
}
else
{
n=m_ListCtrl.GetItemCount();
m_ListCtrl.InsertItem(n,word);
m_ListCtrl.SetItemText(n,1,"标识符");
// cout<<"标识符"<<endl;
return 0;
}
}
//判断是否是关键字
int CCodeScanDlg::IsKey(char *word)
{
int i=0;
while(key[i]!=NULL)
{
if(strcmp(key[i],word)==0)
{
return 1;
}
i++;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -