2007年11月4日星期日

가사검색

void CSearchLyricDlg::OnBnClickedSearch(void)
{
//AfxMessageBox("??");
UpdateData(TRUE);
m_nMarkIdx = -1;

CString strTmp;
m_edSearchWord->GetWindowText(strTmp);

if(strTmp == "")
{
/*CString strMsg;
strMsg.LoadString(IDS_MSG_10);
AfxMessageBox(strMsg);*/
AfxMessageBox(_T("请输入搜索的歌名和歌手名"));//IDS_MSG_10
return;
}

strTmp = ParseSearchWord(strTmp);

GenericHTTPClient httpRequest;
LPCTSTR szHTML;
CString strURL;
_UTF8 utf8;


strURL.Format(_T("%s/findlyrics/syncsong_searchlist_n.asp?strCode=%s&strSearchWord=%s"), SYNC_SERVER, m_strNCode, utf8.UTF8Encoding(strTmp));


//AfxMessageBox(strURL);

if(httpRequest.Request((LPCTSTR)strURL))
{
szHTML = httpRequest.QueryHTTPResponse();

/*CString str11;
str11.Format(("%s"),szHTML);

AfxMessageBox(str11);*/

strTmp.Format(_T("%s"), szHTML);
if(strTmp.Find(_T("<*||*>")) < 0)
{
AfxMessageBox("找不到歌词");//IDS_MSG_11
return;
}
}
else
{
LPVOID lpMsgBuffer;
DWORD dwRet=FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
httpRequest.GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast(&lpMsgBuffer),
0,
NULL);

MessageBox( reinterpret_cast(lpMsgBuffer), _T("ERROR"), MB_OK);
LocalFree(lpMsgBuffer);
}
httpRequest.Close();

CString str;
str = utf8.UTF2CHAR(szHTML);

if(str.Find(_T("<*||*>Lyric is not exist")) > -1)
{
CString strMsg;
strMsg.LoadString(IDS_MSG_11);
AfxMessageBox(strMsg);
//AfxMessageBox(_T("??? ??? ????."));//IDS_MSG_11
return;
}

//m_pMSSearchList->DeleteAllItems();
m_pMSSearchList->ClearList();

int nLoop = 0;
strTmp = "";

CString strTitle;
CString strArtist;
CString strPlayTime;
CString strWmiURL;
CString strLyric;
CString strSeq;

for(int j=0; str.Find(_T("
")) > 0; )
{
j = str.Find(_T("
"));

if(j < 0)
break;

int i=str.Find(_T("<*||*>"));
if(i<0)return;
strTitle = str.Mid(0,i);
str=str.Right(str.GetLength()-i-6);

i=str.Find(_T("<*||*>"));
if(i<0)return;
strArtist = str.Mid(0,i);
str=str.Right(str.GetLength()-i-6);

i=str.Find(_T("<*||*>"));
if(i<0)return;
strPlayTime = str.Mid(0,i);
str=str.Right(str.GetLength()-i-6);

i=str.Find(_T("<*||*>"));
if(i<0)return;
strWmiURL = str.Mid(0,i);
str=str.Right(str.GetLength()-i-6);

i=str.Find(_T("<*||*>
"));
if(i<0)return;
strSeq = str.Mid(0,i);
str=str.Right(str.GetLength()-i-10);

strTmp.Format(_T("%d"), nLoop);

m_pMSSearchList->AddSearchList(strTmp, strTitle, strArtist, strPlayTime, strWmiURL, m_strFileName, strSeq);

nLoop++;
}

UpdateData(FALSE);
}

没有评论: