html:xt自动,打开网页中的HTML

BOOL COpenSourceHTMLDlg::OpenSourceHTML()

{

UpdateData(TRUE);

CInternetSession session;

CInternetFile* file = NULL;

try

{

// 试着连接到指定URL

file = (CInternetFile*) session.OpenURL(m_strNetAddr);

}

catch (CInternetException* m_pException)

{

// 如果有错误的话,置文件为空

file = NULL;

m_pException->Delete();

return FALSE;

}

CString strTempLineInf;

m_strSourceHtml = "";

if (file)

{

// 读写网页文件,直到为空

while (file->ReadString(strTempLineInf) != NULL) //如果采用LPTSTR类型,读取最大个数nMax置0,使它遇空字符时结束

{

m_strSourceHtml += strTempLineInf;

m_strSourceHtml += "\r\n";

}

file->Close();

delete file;

}

else

{

m_strSourceHtml += _T("到指定服务器的连接建立失败...");

return FALSE;

}

UpdateData(FALSE);

return TRUE;

}