delphi Webbrowser IE 窗口选择中,选中的文字内容  
官方Delphi 学习QQ群: 682628230(三千人)\n
频道

delphi Webbrowser IE 窗口选择中,选中的文字内容


Delphi Webbrowser IE 窗口选择中,选中的文字内容如何用API函数或delphi取出当前IE窗口已经选中的文本信息字符串?我的程序如下: 
var 
   Doc: IHtmlDocument2; 
   TxtRange: IHtmlTxtRange; 
   S:string; 
begin 
   Doc :=IE.Document as IHtmlDocument2;   //IE: IWebbrowser2; 
   TxtRange :=Doc.Selection.CreateRange as IHtmlTxtRange; 
   S:=TxtRange.Get_text; 
   ShowMEssage('选中的内容为:'+S); 
end; 

哪位高人知道哪里错了?应该如何才能取得文本信息? 
--------------------------------------------------------------- 

uses 
    msHtml, SHdocvw; 

var 
   I: Integer; 
   ShellWindow: IShellWindows; 
   IE: IWebbrowser2; 
   Doc: IHtmlDocument2; 
   TxtRange: IHtmlTxtRange; 
   S: string; 
   P: PChar; 
begin 
   ShellWindow := CoShellWindows.Create; 
   for I := 0 to ShellWindow.Count-1 do 
   begin 
     IE := ShellWindow.Item(I) as IWebbrowser2; 
     if IE <> nil then 
     begin 
       GetMem(P, MaxByte+1); 
       GetClassName(IE.HWND, P, MaxByte); 
       if SameText(P, 'IEFrame') then 
       begin 
         Doc := IE.Document as IHtmlDocument2; 
         if Doc.Selection <> nil then 
         begin 
           TxtRange := Doc.Selection.CreateRange as IHtmlTxtRange; 
           S := TxtRange.Get_text; 
           SHowMessage(S); 
         end; 
       end; 
       FreeMem(P); 
     end; 
   end; 
end;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.091356039047241 seconds