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;

相关阅读 >>

Delphi ascii 码对照表

Delphi通过idsmtp发送邮件的简单代码

Delphi 更改消息对话框中的按钮标题

Delphi 控制窗口显示隐藏

Delphi 取当前目录下所有文件夹名和文件名

Delphi如何判断一个combobox是否处于下拉状态

Delphi 全局的鼠标钩子 使用钩子函数数据传递

Delphi 判断当前网络连接方式

Delphi firemonkey 学习笔记 �c tpopup 控件的使用

Delphi获取其它进程窗口句柄的三种方法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...