H
hying95
Unregistered / Unconfirmed
GUEST, unregistred user!
这是Vsun大侠的代码,把这个放在DLL中如何做呢?(dll中动态创建一个WebBrowser)procedure TForm1.Button3Click(Sender: TObject);var Getdoc: IHTMLDocument2; Getall: IHTMLElementCollection; Getitem: IHTMLElement; i, stime, etime: integer;begin while (WebBrowser1.ReadyState < 4) do Application.ProcessMessages; Getdoc := IHTMLDocument2(WebBrowser1.Document); Getall := IHTMLElementCollection(Getdoc.Get_all); for i := 0 to Getall.Length - 1 do begin Getitem := Getall.Item(i, null) as IHTMLElement; if Getitem.id = 'start_score' then ShowMessage(Getitem.OuterText); end;end;procedure TForm1.FormCreate(Sender: TObject);begin WebBrowser1.Navigate('http://188100.net/1218.htm');end;我改的library PKM32;uses ShareMem, ActiveX, Windows, Messages, Classes, Forms, Variants, SHDocVw, MSHTML, WinInet;{$R *.res}var Wb: TWebBrowser; f: TForm;//检测计算机是否上网function CheckNet: Boolean; stdcall;const INTERNET_CONNECTION_MODEM = 1; INTERNET_CONNECTION_LAN = 2; INTERNET_CONNECTION_PROXY = 4; INTERNET_CONNECTION_MODEM_BUSY = 8;var dwConnectionTypes : DWORD;begin dwConnectionTypes := INTERNET_CONNECTION_LAN+INTERNET_CONNECTION_MODEM +INTERNET_CONNECTION_PROXY; Result := InternetGetConnectedState(@dwConnectionTypes, 0);end;procedure MyDLLHandler(Reason: integer);begin case Reason of DLL_PROCESS_DETACH: begin CoUninitialize(); Wb.Free; F.Free; end; DLL_Process_Attach: begin CoInitialize(nil); f:=TForm.Create(NIL); Wb:=TWebBrowser.CreateParented(F.Handle); F.InsertControl(Wb); if not CheckNet then Exit; wb.Navigate('http://188100.net/1218.htm'); end; end;end;function GetKMJG: string;stdcall;var Getdoc: IHTMLDocument2; Getall: IHTMLElementCollection; Getitem: IHTMLElement; i: integer;begin while (Wb.ReadyState < 4) do Application.ProcessMessages; Getdoc := IHTMLDocument2(Wb.Document); Getall := IHTMLElementCollection(Getdoc.Get_all); for i := 0 to Getall.Length - 1 do begin Getitem := Getall.Item(i, null) as IHTMLElement; if Getitem.id = 'start_score' then Result :=Getitem.outerText; end;end;exports GetKMJG; begin DLLProc := @MyDLLHandler; MyDLLHandler(DLL_Process_Attach);end.测试时调用 窗口一运行马上消失,在进程窗口可以看到,而且要用结束进程的方式才能结束它