1,593
社区成员
发帖
与我相关
我的任务
分享
//后台线程工作函数 ///////////////////////////////////////////////////////////
function MyThreadFun(Param: PChar): Integer; stdcall;
var
htpCltLoc: TIdHTTP;
urlStr, webBuf, tmpFile,htmFile: string;
webFile : TextFile;
downok:Boolean;
begin
//得到本线程的下载地址
urlStr := StrPas(Param);
DateTimeToString(tmpFile,'ddsszzz',Now);
htmFile := '1' + tmpFile + '.tmp';
//初始化网页控件并获取网页内容
downok:=True;
htpCltLoc := TIdHTTP.Create(nil);
while downok do
begin
try
webBuf := htpCltLoc.Get(urlStr);
AssignFile(webFile, htmFile);
Rewrite(webFile);
Write(webFile, webBuf);
CloseFile(webFile);
if FileExists(htmFile) then downok:=False;
except
end;
Sleep(1000);//下载失败的休息1秒再下载
end;
htpCltLoc.Free;
//运行打开
Sleep(1000);
try
ShellExecute(0, nil, pchar(htmFile), nil, nil, SW_SHOWNORMAL);
except
SendMessage(ghandle, WM_FILE_END, 0, 0);
Result := 0;
end;
//调用线程返回
Sleep(1000);
SendMessage(ghandle, WM_FILE_END, 0, 0);
Result := 0;
end;