Sample program running
After setting the download URL, the program downloads and saves the webpage, and keeps displaying it during the running of the villain.
Basic components:
Use the WinInet class to directly open the session, read and save the webpage to the relevant files. The GetSourceHtml function provided in this article encapsulates this function. You only need to provide the URL and save the file name to complete all operations. The specific function is as follows:
BOOL GetSourceHtml (CString theUrl, CString Filename)
{
CInternetSession session;
CInternetFile * file = NULL;
Try
{
// Try to connect to the specified URL
File = (CInternetFile *) session. OpenURL (theUrl );
}
Catch (CInternetException * m_pException)
{
// If any error occurs, leave the file blank.
File = NULL;
M_pException-> Delete ();
Return FALSE;
}
// Use dataStore to save the webpage Files Read
CStdioFile dataStore;
If (file)
{
CStringSomecode;// You can also use the LPTSTR type. The carriage return in the text will not be deleted.
BOOL bIsOk = dataStore. Open (strPath + "\" + Filename,
CFile: modeCreate
| CFile: modeWrite
| CFile: shareDenyWrite
| CFile: typeText );
If (! BIsOk)
Return FALSE;
// Read and write the webpage file until it is empty
While (file-> ReadString (somecode )! = NULL) // If the LPTSTR type is used, the maximum number of nMax reads is set to 0, so that it ends when it encounters a NULL character.
{
DataStore. WriteString (somecode );
& Nbs