做了个通用版本的
设置了一下 :右键解决方案->属性->常规->使用多字节字符集
改过一以后烦人的”不能将参数 2 从 CString 转换为“const char *“的问题解决了 但是界面变得好丑陋了
下面开源,首先是读取时间标签和记录歌词部分:
复制内容到剪贴板
代码:
void C歌词显示Dlg::OnBnClickedButton1()
{
FILE *fp;
char *cRowLrc=new char[255];
char cCh;
char cCh1;
int nLrcTime = 0, nCount = 0, nPFirst = 0,nPFirst1=0,nRowLrc=0,nTimeCount=0,i=0;
bool bTimeTrue=true,bGoFind=true;
pLrcFirst = pLrcNext = (PLRC)malloc(LENLRC);
pTimeFirst = pTimeNext = (PTIME)malloc(LENTIME);
pHeadTime=NULL;
pHeadLrc=NULL;
nSec=0;
if((fp = fopen(cLrcPath, "r"))!=NULL){
cCh = fgetc(fp);
while (!feof(fp)){
cCh1=fgetc(fp);
while(bGoFind==true){
cCh=cCh1;
cCh1= fgetc(fp);
while (cCh != ']'){
if (bTimeTrue==true){
nCount = nCount + 1;
switch (nCount){
case 1:
if(cCh >= '0' && cCh <= '9'){
nLrcTime = ((cCh - '0') * 10 * 60) + nLrcTime;}
else{bTimeTrue=false;}
break;
case 2:if(cCh >= '0' && cCh <= '9'){
nLrcTime = ((cCh - '0') * 60) + nLrcTime;}
else{bTimeTrue=false;}
break;
case 3:if(cCh!=':'){
bTimeTrue=false;}
break;
case 4:if(cCh >= '0' && cCh <= '9'){
nLrcTime = ((cCh - '0') * 10) + nLrcTime;}
else{bTimeTrue=false;}
break;
case 5:if(cCh >= '0' && cCh <= '9'){
nLrcTime = (cCh - '0') + nLrcTime;}
else{bTimeTrue=false;}
break;
}
}
cCh=cCh1;
cCh1= fgetc(fp);
}
if (bTimeTrue==true){
nTimeCount++;
if(nPFirst==0){
pTimeFirst -> nTime = nLrcTime;
pHeadTime = pTimeFirst;
nPFirst=1;
}
else{
pTimeNext->pTimeSelf =pTimeFirst;
pTimeNext = pTimeFirst;
pTimeFirst = (PTIME)malloc(LENTIME);
pTimeFirst->nTime = nLrcTime;
}
}
nCount = 0;
nLrcTime=0;
if(cCh1!='['){
bGoFind=false;}
else{
cCh=cCh1;
cCh1 = fgetc(fp);
}
}
cCh=cCh1;
cCh1 = fgetc(fp);
while (cCh != '\n'){
if (bTimeTrue==true){
*cRowLrc = cCh;
cRowLrc++;
nRowLrc++;
}
if(cCh1!=EOF){
cCh=cCh1;
cCh1 = fgetc(fp);
}
else{
cCh=cCh1;
break;
}
}
if(bTimeTrue==true){
*cRowLrc = '\0';
for(i=1;i<=nTimeCount;i++){
if(nPFirst1==0){
pLrcFirst->cLrc = cRowLrc-nRowLrc;
pHeadLrc = pLrcFirst;
nPFirst1=1;
}
else{
pLrcNext->pLrcSelf = pLrcFirst;
pLrcNext = pLrcFirst;
pLrcFirst = (PLRC)malloc(LENLRC);
pLrcFirst->cLrc = cRowLrc-nRowLrc;
}
}
cRowLrc=cRowLrc-nRowLrc;
cRowLrc=new char[255];
nRowLrc=0;
nTimeCount=0;
i=0;
}
cCh=cCh1;
bTimeTrue=true;
bGoFind=true;
}
}
else{
m_Lrc="file failed";
UpdateData(false);
}
fclose(fp);
pLrcNext->pLrcSelf = pLrcFirst;
pTimeNext->pTimeSelf =pTimeFirst;
pLrcNext = pLrcFirst;
pTimeNext = pTimeFirst;
pTimeNext->pTimeSelf = NULL;
pLrcNext->pLrcSelf = NULL;
SetTimer(1,1000,NULL);
}接着是显示歌词部分:
复制内容到剪贴板
代码:
void C歌词显示Dlg::OnTimer(UINT_PTR nIDEvent)
{
if(nIDEvent==1){
nSec++;
pLrcOut=pHeadLrc;
pTimeOut=pHeadTime;
while(pLrcOut!=NULL){
if(pTimeOut -> nTime == nSec){
m_Lrc=pLrcOut->cLrc;
UpdateData(false);
}
pLrcOut=pLrcOut->pLrcSelf;
pTimeOut=pTimeOut->pTimeSelf;
}
}
return;
CDialog::OnTimer(nIDEvent);
}选择文件部分:
复制内容到剪贴板
代码:
void C歌词显示Dlg::OnBnClickedButton2()
{
CFileDialog LrcFile(TRUE);
LrcFile.DoModal();
cLrcPath="";
cLrcPath=LrcFile.GetPathName();
return;
}[
本帖最后由 Sruing1.0 于 2008-9-17 22:40 编辑 ]