几个WebBrowser相关的函数

2024-02-14 07:18

本文主要是介绍几个WebBrowser相关的函数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


贴几个 TWebBrowser 编程相关的函数。
{ 去掉 TWebBrowser 的边框 }
procedure WB_Set3DBorderStyle(Sender: TWebBrowser; bValue: Boolean);
{ WebBrowser 从内存中读取 HTML 文件}
procedure WebBrowserLoadFromStream(WebBrowser: TWebBrowser; Stream: TStream);
procedure NavigateLoadFromStream(WebBrowser: TWebBrowser;   Stream:   TStream);
{ WebBrowser 从字符中读取 HTML 文件}
procedure WebBrowserLoadFromText(WebBrowser: TWebBrowser; HtmlText: String);
{ WebBrowser 保存成 Html 文件 }
function WebBrowserSaveHTMLCode(WebBrowser: TWebBrowser; const FileName: TFileName):   Boolean;
{ HTML 保存成流 }
procedure SaveDocumentSourceToStream(Document: IDispatch; Stream: TStream);
uses Axctrls, ActiveX, MSHTML, OleCtrls, SHDocVw
{ WB_Set3DBorderStyle }
procedure WB_Set3DBorderStyle(Sender: TWebBrowser; bValue: Boolean);
var
   Document: IHTMLDocument2;
   Element: IHTMLElement;
   StrBorderStyle: string;
begin
   //去掉边框
   try
Document := TWebBrowser(Sender).Document as IHTMLDocument2;
if Assigned(Document) then
begin
   Element := Document.Body;
   if Element <> nil then
   begin
       case BValue of
      False: StrBorderStyle := 'none';
      True: StrBorderStyle := '';
       end;
       Element.Style.BorderStyle := StrBorderStyle;
   end;
end;
   except
//..
   end;
end;
{ WebBrowserLoadFromText }
procedure WebBrowserLoadFromText(WebBrowser: TWebBrowser; HtmlText: String);
var
   v: Variant;
   IDoc: IHTMLDocument2;
begin
   WebBrowser.Navigate('about:blank');
   repeat
Application.ProcessMessages;
Sleep(0);
   until WebBrowser.ReadyState = READYSTATE_COMPLETE;
   IDoc := WebBrowser.Document as IHTMLDocument2;
   try
IDoc.designMode:='on';
while IDoc.readyState<>'complete' do
   Application.ProcessMessages;
v:=VarArrayCreate([0,0],VarVariant);
v[0]:= HtmlText;
IDoc.write(PSafeArray(System.TVarData(v).VArray));
IDoc.designMode:='off';
while IDoc.readyState<>'complete' do
   Application.ProcessMessages;
   finally
IDoc := nil;
   end;
end;
{ NavigateLoadFromStream }
procedure NavigateLoadFromStream(WebBrowser: TWebBrowser;   Stream:   TStream);
begin
   Stream.Seek(0, 0);
   if Assigned(WebBrowser.Document) then
(WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(Stream));
end;
{ WebBrowserLoadFromStream }
procedure WebBrowserLoadFromStream(WebBrowser: TWebBrowser;   Stream:   TStream);
begin
   WebBrowser.Navigate('about:blank');
   repeat
Application.ProcessMessages;
Sleep(0);
   until WebBrowser.ReadyState = READYSTATE_COMPLETE;
   NavigateLoadFromStream(WebBrowser, Stream);
end;
{ WebBrowserSaveHTMLCode }
function WebBrowserSaveHTMLCode(WebBrowser: TWebBrowser; const FileName: TFileName):   Boolean;
var
   ps: IPersistStreamInit;
   fs: TFileStream;
   sa: IStream;
begin
   ps := WebBrowser.Document as IPersistStreamInit;
   fs := TFileStream.Create(FileName, fmCreate);
   try
sa := TStreamAdapter.Create(fs, soReference) as IStream;
Result := Succeeded(ps.Save(sa, True));
   finally
fs.Free;
   end;
end;
{ SaveDocumentSourceToStream }
procedure SaveDocumentSourceToStream(Document: IDispatch; Stream: TStream);
var
   PersistStreamInit: IPersistStreamInit;
   StreamAdapter: IStream;
begin
   Stream.Size   :=   0;
   Stream.Position   :=   0;
   if Document.QueryInterface(IPersistStreamInit, PersistStreamInit) = S_OK then
   begin
StreamAdapter := TStreamAdapter.Create(Stream, soReference);
PersistStreamInit.Save(StreamAdapter, False);
StreamAdapter := nil;
   end;
end;

        
        



        







        
          
            
            评论这张
          
        


          
            
               几个WebBrowser相关的函数 - yyimen - yyimen的博客
            
            转发至微博
          
        

这篇关于几个WebBrowser相关的函数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/707855

相关文章

Python函数返回多个值的多种方法小结

《Python函数返回多个值的多种方法小结》在Python中,函数通常用于封装一段代码,使其可以重复调用,有时,我们希望一个函数能够返回多个值,Python提供了几种不同的方法来实现这一点,需要的朋友... 目录一、使用元组(Tuple):二、使用列表(list)三、使用字典(Dictionary)四、 使

PyTorch中cdist和sum函数使用示例详解

《PyTorch中cdist和sum函数使用示例详解》torch.cdist是PyTorch中用于计算**两个张量之间的成对距离(pairwisedistance)**的函数,常用于点云处理、图神经网... 目录基本语法输出示例1. 简单的 2D 欧几里得距离2. 批量形式(3D Tensor)3. 使用不

MySQL 字符串截取函数及用法详解

《MySQL字符串截取函数及用法详解》在MySQL中,字符串截取是常见的操作,主要用于从字符串中提取特定部分,MySQL提供了多种函数来实现这一功能,包括LEFT()、RIGHT()、SUBST... 目录mysql 字符串截取函数详解RIGHT(str, length):从右侧截取指定长度的字符SUBST

Kotlin运算符重载函数及作用场景

《Kotlin运算符重载函数及作用场景》在Kotlin里,运算符重载函数允许为自定义类型重新定义现有的运算符(如+-…)行为,从而让自定义类型能像内置类型那样使用运算符,本文给大家介绍Kotlin运算... 目录基本语法作用场景类对象数据类型接口注意事项在 Kotlin 里,运算符重载函数允许为自定义类型重

解决tomcat启动时报Junit相关错误java.lang.ClassNotFoundException: org.junit.Test问题

《解决tomcat启动时报Junit相关错误java.lang.ClassNotFoundException:org.junit.Test问题》:本文主要介绍解决tomcat启动时报Junit相... 目录tomcat启动时报Junit相关错误Java.lang.ClassNotFoundException

Pandas中统计汇总可视化函数plot()的使用

《Pandas中统计汇总可视化函数plot()的使用》Pandas提供了许多强大的数据处理和分析功能,其中plot()函数就是其可视化功能的一个重要组成部分,本文主要介绍了Pandas中统计汇总可视化... 目录一、plot()函数简介二、plot()函数的基本用法三、plot()函数的参数详解四、使用pl

Maven中引入 springboot 相关依赖的方式(最新推荐)

《Maven中引入springboot相关依赖的方式(最新推荐)》:本文主要介绍Maven中引入springboot相关依赖的方式(最新推荐),本文给大家介绍的非常详细,对大家的学习或工作具有... 目录Maven中引入 springboot 相关依赖的方式1. 不使用版本管理(不推荐)2、使用版本管理(推

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

Python正则表达式语法及re模块中的常用函数详解

《Python正则表达式语法及re模块中的常用函数详解》这篇文章主要给大家介绍了关于Python正则表达式语法及re模块中常用函数的相关资料,正则表达式是一种强大的字符串处理工具,可以用于匹配、切分、... 目录概念、作用和步骤语法re模块中的常用函数总结 概念、作用和步骤概念: 本身也是一个字符串,其中

shell编程之函数与数组的使用详解

《shell编程之函数与数组的使用详解》:本文主要介绍shell编程之函数与数组的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录shell函数函数的用法俩个数求和系统资源监控并报警函数函数变量的作用范围函数的参数递归函数shell数组获取数组的长度读取某下的