惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
A
Arctic Wolf
S
Security Affairs
O
OpenAI News
SecWiki News
SecWiki News
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
T
Threat Research - Cisco Blogs
Hacker News: Ask HN
Hacker News: Ask HN
N
News | PayPal Newsroom
Google Online Security Blog
Google Online Security Blog
C
Cisco Blogs
The Hacker News
The Hacker News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
T
Tenable Blog
T
The Exploit Database - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Spread Privacy
Spread Privacy
人人都是产品经理
人人都是产品经理
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
T
The Blog of Author Tim Ferriss
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
The Cloudflare Blog
N
News and Events Feed by Topic
量子位
Google DeepMind News
Google DeepMind News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Attack and Defense Labs
Attack and Defense Labs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hacker News - Newest:
Hacker News - Newest: "LLM"
Apple Machine Learning Research
Apple Machine Learning Research
The Register - Security
The Register - Security
Microsoft Security Blog
Microsoft Security Blog
Know Your Adversary
Know Your Adversary
Webroot Blog
Webroot Blog

博客园 - chinese_submarine

QT项目性能调优小记 Windows下HG服务器的搭建 svn+tp-link+花生壳搭建外网服务器 udev介绍 极大极小博弈树的简洁(附Tic-Tac-Toe源码) 程序优化小记 Beating the Average------为什么要学习Lisp[转] 巧用qmake工具生成专业的makefile QT中拖拽的实现(附示例代码) 从QDataStream向QByteArray中写入数据时的注意点(QT) 如何保持GUI的响应流畅(QT平台) 也谈线程同步变量 windows7到期的问题 简述FPS的计算方法 QT中的View Model模型系列一 从农夫养牛问题推广到斐波那契数列 TimeZoneChange事件的捕获 浏览器扩展系列————异步可插入协议(pluggable protocol)的实现 浏览器扩展系列————给MSTHML添加内置脚本对象【包括自定义事件】
浏览器扩展系列————透明浏览器窗口的实现
chinese_submarine · 2009-04-26 · via 博客园 - chinese_submarine

首先先看一下效果图:

    本实现是基于WPF,VS版本2008 SP1。

    先说一下在Winform中的实现方法:很简单通过设置窗体的opacity来实现,或者还可以设置TransparentKey来实现某种颜色透明。但是在WPF中则如何实现呢?

通过设置窗体的opacity,那么得到结果就是webbrowser整体消失了。因为这里面涉及到WPF中“空域”的问题,相关的文章如下:

http://blogs.msdn.com/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.aspx

    由此看来通过直接设置透明度的方法是不行了,那么回到原来的问题,“将浏览器窗体背景成透明”,其实这里的透明只是一个视觉上的感觉,就是浏览器中网页的背景和整个窗体的背景想融合就可以。看到这里,各位看官可能已经想到了,将浏览器中页面的背景绘制成被浏览器控件所覆盖出的背景就可以了。确实,我的实现也是依照这种思路走的。

    这里主要用到了两个技术:

Mshtml操作网页中元素,通过给body标签添加行为来实现背景的绘制。

Code

下面是绘制部分的代码

Code

RenderTargetBitmap类用来给应用程序截图:

Code

在截图的时候这里使用了一个技巧就是,先将控件隐藏,然后截图,最后恢复控件的显示。 

最后说一下本实现的一些缺陷:

  1.  如果将应用程序的背景设置为透明,则浏览器的背景将呈现白色,因为本实现使用的是应用程序的背景来进行截图,如果应用程序背景被透明,则截图得到的也是一张透明的图片,绘制到页面上后并不能达到透明的效果。如果想在这种情况下实现透明,可以考虑对桌面背景进行截图。
  2. 如果网页过大出现滚动条,那么网页中未呈现的部分并不能透明,因为截图只能作用于已经显示的部分。所以本实现用于显示本地控制好大小的html页面有比较好的效果。

具体项目下载如下:

/Files/chinese-zmm/TransportWebBrowserDemo.rar 

posted on 2009-04-26 19:44  chinese_submarine  阅读(10592)  评论()    收藏  举报