Downloads bits from the Internet and saves them to a file.SyntaxHRESULT URLDownloadToFile( LPUNKNOWN pCaller, LPCTSTR szURL, LPCTSTR szFileName, DWORD dwReserved, LPBINDSTATUSCALLBACK lpfnCB ); ParameterspCaller Pointer to the controlling IUnknown interface of the calling Microsoft® ActiveX® component (if the caller is an ActiveX component). If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a Component Object Model (COM) object that is contained in another component (such as an ActiveX control within the context of an HTML page). This parameter represents the outermost IUnknown of the calling component. The function attempts the download within the context of the ActiveX client framework and allows the caller's container to receive callbacks on the progress of the download. szURL Pointer to a string value containing the URL to be downloaded. Cannot be set to NULL. szFileName Pointer to a string value containing the name of the file to create for bits that come from the download. dwReserved Reserved. Must be set to 0. lpfnCB Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called. Implementing IBindStatusCallback::OnProgress allows a caller to implement a user interface or other progress monitoring functionality. It also allows the download operation to be canceled by returning E_ABORT from the IBindStatusCallback::OnProgress call. This can be set to NULL. Return ValueReturns one of the following values.E_OUTOFMEMORY The buffer length is invalid or there was insufficient memory to complete the operation. S_OK The operation succeeded. ResThe client can choose to be notified of progress through a notification callback.Function InformationHeader Urlmon.h Import library Urlmon.lib Minimum availability Internet Explorer 3.0 Minimum operating systems Windows NT 4.0, Windows 95
begin
ShellExecute(0, 'open', 'http://www9.pconline.com.cn/pcgames/gamedown.php?id=14446', '', '', SW_SHOW);
end;—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
用法可以查看MSND给分吧
LPCTSTR szURL,
LPCTSTR szFileName,
DWORD dwReserved,
LPBINDSTATUSCALLBACK lpfnCB
);
ParameterspCaller
Pointer to the controlling IUnknown interface of the calling Microsoft® ActiveX® component (if the caller is an ActiveX component). If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a Component Object Model (COM) object that is contained in another component (such as an ActiveX control within the context of an HTML page). This parameter represents the outermost IUnknown of the calling component. The function attempts the download within the context of the ActiveX client framework and allows the caller's container to receive callbacks on the progress of the download.
szURL
Pointer to a string value containing the URL to be downloaded. Cannot be set to NULL.
szFileName
Pointer to a string value containing the name of the file to create for bits that come from the download.
dwReserved
Reserved. Must be set to 0.
lpfnCB
Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called. Implementing IBindStatusCallback::OnProgress allows a caller to implement a user interface or other progress monitoring functionality. It also allows the download operation to be canceled by returning E_ABORT from the IBindStatusCallback::OnProgress call. This can be set to NULL.
Return ValueReturns one of the following values.E_OUTOFMEMORY The buffer length is invalid or there was insufficient memory to complete the operation.
S_OK The operation succeeded.
ResThe client can choose to be notified of progress through a notification callback.Function InformationHeader Urlmon.h
Import library Urlmon.lib
Minimum availability Internet Explorer 3.0
Minimum operating systems Windows NT 4.0, Windows 95
例如,你要下载某一网址内存到一文件,可以这样写
URLDownloadToFile(szURL,szFileName,0,nil);我没试过,应该是这样如果不行,你把nil改为NULL就行了保证能用
:
function GetInetFile (const fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD; f: File;
sAppName: string;
begin
Result:=False;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
hURL := InternetOpenURL(hSession, PChar(fileURL), nil,0,0,0);
try
AssignFile(f, FileName); Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen)
until BufferLen = 0;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSession)
end
end;
***********************************
var
FileOnNet, LocalFileName: string
begin
FileOnNet:= 'http://delphi.about.com/library/netfile.zip';
LocalFileName:='netfile.zip';
if GetInetFile(FileOnNet,LocalFileName)=True then
ShowMessage('下载成功!')
else
ShowMessage('下载失败!')
end;
:
function GetInetFile (const fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD; f: File;
sAppName: string;
begin
Result:=False;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
hURL := InternetOpenURL(hSession, PChar(fileURL), nil,0,0,0);
try
AssignFile(f, FileName); Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen)
until BufferLen = 0;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSession)
end
end;
***********************************
var
FileOnNet, LocalFileName: string
begin
FileOnNet:= 'http://delphi.about.com/library/netfile.zip';
LocalFileName:='netfile.zip';
if GetInetFile(FileOnNet,LocalFileName)=True then
ShowMessage('下载成功!')
else
ShowMessage('下载失败!')
end;
:
function GetInetFile (const fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD; f: File;
sAppName: string;
begin
Result:=False;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
hURL := InternetOpenURL(hSession, PChar(fileURL), nil,0,0,0);
try
AssignFile(f, FileName); Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen)
until BufferLen = 0;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSession)
end
end;
***********************************
var
FileOnNet, LocalFileName: string
begin
FileOnNet:= 'http://delphi.about.com/library/netfile.zip';
LocalFileName:='netfile.zip';
if GetInetFile(FileOnNet,LocalFileName)=True then
ShowMessage('下载成功!')
else
ShowMessage('下载失败!')
end;
下次不给回答了KAO
要用到那个单元呀?