📄 网页减肥程序的编制.txt
字号:
网页减肥程序的编制
作者:杨勇
对于一个网页设计者,网页浏览的速度是非常重要的,因而出现的一些网页减肥工具,本文将简单
的介绍一下它的编制方法。
一、单个网页的减肥
首先假设生成的减肥后的网页放在E盘123子目录下,定义如下CString变量。
m_FilePathName="e:\\123\\";
m_FilePathNameDir="e:\\123";
m_tempDirectory=m_FilePathName;
其次设计减肥函数。
CString CRetuDoc::GetFileName(LPCTSTR lpszFileName)//参数为需减肥的网页名
{
if (lpszFileName != NULL) {
_splitpath(lpszFileName, m_szDrive, m_szDir, m_szFname, m_szExt);
}
// Just return the file name + extension.
CString str; str.Format(_T("%s%s"), m_szFname, m_szExt);
return str;
}
void CRetuDoc::MaxZip(LPCTSTR lpszPathName)//参数为需减肥的网页名
{
CStdioFile file1,file2;
CString str,name;
file1.Open(lpszPathName,CFile::modeRead|CFile::typeText);
name=m_tempDirectory+GetFileName(lpszPathName);
file2.Open(name,CFile::modeCreate|CFile::modeWrite|CFile::typeText);
CString strHR;
strHR.Format("\n");
while(file1.GetPosition()!=file1.GetLength())
{
file1.ReadString(str);
str.TrimRight();
str.TrimLeft();
if(str.GetLength()!=0)
{
str+=strHR;
file2.WriteString(str);
}
}
file1.Close();
file2.Close();
DeleteFile(lpszPathName);
MoveFile(name,lpszPathName);
}
二、目录及其子目录下所有文件的减肥。
BOOL CRetuDoc::ZipDirectory(LPCTSTR DirName)
{
CFileFind tempFind;
char tempFileFind[_MAX_PATH];
sprintf(tempFileFind,"%s\\*.*",DirName);
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[_MAX_PATH];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(_MAX_PATH));
if(tempFind.IsDirectory())
{
char tempDir[_MAX_PATH];
sprintf(tempDir,"%s\\%s",DirName,foundFileName);
m_tempDirectory=tempDir;
m_tempDirectory.Replace(m_WebPathName,m_FilePathNameDir);
CreateDirectory(m_tempDirectory,NULL);
ZipDirectory(tempDir);
}
else
{
m_tempDirectory=DirName;
m_tempDirectory.Replace(m_WebPathName,m_FilePathName);
char tempFileName[_MAX_PATH];
sprintf(tempFileName,"%s\\%s",DirName,foundFileName);
CString tempFileExt=GetFileExt(tempFileName);
tempFileExt.MakeLower();
if(tempFileExt==".htm"||tempFileExt==".html"||tempFileExt==".asp")
MaxZip(tempFileName);
}
}
}
tempFind.Close();
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -