?? 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 + -