delphi 控制IE |
|
pgdennis
資深會員 發表:41 回覆:526 積分:443 註冊:2002-05-23 發送簡訊給我 |
1.這是小弟從http://community.borland.com/article/0,1410,26574,00.html
及http://www.applevb.com/art/control_ie.txt的資料參考修改,
本來是想寫一個IE外掛,用來轉換簡繁體網頁(aLibar這個軟體的功能),但
我從網路上下載的轉換程式碼,在轉換為簡體後,貼到memo上(字元集改gb)能正常顯示,但我如果貼到word上,都會有亂碼,這好像是要轉成unucide的簡體才行,做到這邊我就停住了,不只怎麼轉碼.
我現在只能控制 >.
我有試過用 class="code">
unit mailIE; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,mshtml, SHDocVw_TLB, OleServer, StdCtrls,comobj,//,word2000
OleCtrls; type
TForm1 = class(TForm)
ListBox1: TListBox;
Memo1: TMemo;
Button1: TButton;
InternetExplorer1: TInternetExplorer;
ShellWindows1: TShellWindows;
procedure Button1Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
//取得瀏覽窗口包含我的電腦,IE或KKman..等
for i:=0 to ShellWindows1.Count-1 do begin
//將InternetExplorer1與瀏覽窗口接起來
InternetExplorer1.ConnectTo(shellwindows1.item(i) as IWebBrowser2 );
//判斷是否為IE
if Pos('IEXPLORE.EXE',InternetExplorer1.FullName)>0 then
listbox1.Items.Add(InternetExplorer1.LocationURL); end; end; procedure TForm1.ListBox1DblClick(Sender: TObject);
var
i:integer;
Doc: IHTMLDocument2;
ElementCollection: IHTMLElementCollection;
HtmlElement: IHTMLElement; {Word : OleVariant;
S: OleVariant; }
begin
//取得網頁的document
Doc := InternetExplorer1.Document as IHTMLDocument2; try
{Word := CreateOLEObject('Word.Application');
Word.Visible := true;
Word.Documents.Add;
S :=Word.Selection ;
Word.Selection.WholeStory;
S.Range.TCSCConverter(wdTCSCConverterDirectionTCSC);
Doc.title:=(S.Range.Text);} if Doc = nil then
raise Exception.Create('Couldn''t convert the '
'FInternetExplorer.Document to an IHTMLDocument2');
// 取得網頁所有的elements
ElementCollection := Doc.all;
for I := 0 to ElementCollection.length - 1 do
begin
// 取得目前element
HtmlElement := ElementCollection.item(I,'') as IHTMLElement; //也可處理其他tag ,大小寫有差
try
if HTMLElement.tagName = 'A' then //只處理超連結
begin //本來用WORD將繁體字轉成簡體字後在丟回IE,但速度很慢-__-
{ S :=Word.Selection ;
S.delete;
S.typetext(HtmlElement.innerText);
Word.Selection.WholeStory;
S.Range.TCSCConverter(wdTCSCConverterDirectionTCSC);
HtmlElement.innerText:=S.Range.Text;}
memo1.Lines.Add(HtmlElement.innerText); end;
except
null;
end; end;
finally
{ Word.ActiveDocument.ActiveWindow.Close(wdDoNotSaveChanges, EmptyParam);
Word.Quit;
S:=null;}
end;
end; end.
< >< >< >< >
------
星期一,二...無窮迴圈@@ |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |