Posts tagged MSHTML
Extend a webbrowser control using ICustomQueryInterface
- 20 March 2023
This article is written with the help of ChatGPT. I want to see how far ChatGPT can go solve this and if any correction needs to be made. ChatGPT went pretty far but still made some mistakes.
To extend a WebBrowser control using ICustomQueryInterface, you can create a new class that implements the ICustomQueryInterface interface and then use the SetSite method of the WebBrowser control to set the new class as the site for the control. Here are the steps you can follow:
How To Determine When a Page Is Done Printing in WebBrowser Control
- 24 March 2021
Note this post is originally written in 2012. It was lost when moving my web site from Windows Live Spaces to WordPress. I found a dead link to my web site on Stackoverflow and found an archive from archive.org. So here it is the old article, with dead link updated of course.
The printing from a WebBrowser control can be customized by using custom headers and footers (https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/267240, archived from http://support.microsoft.com/kb/267240) or replacing the default print template. However, using such techniques conflicts with the PRINT_WAITFORCOMPLETION flag, which is used for synchronous printing.
Howto: Ignoring web browser certificate errors in a webbrowser host
- 17 July 2013
Download Example Code: jiangsheng/Samples.
Many applications host webbrowser controls to display web pages inside. Before production the web page is often in an internal server that do not have a valid certificate. This article let you skip the certificate error and continue testing your application
Howto: reset IE security zone settings programmatically
- 26 November 2012
Internet Explorer 7 introduced the IInternetZoneManagerEx2 interface, which has a FixUnsecureSettings method to reset all security zone settings. Like all other IInternetZoneManager* interfaces, you can query this interface from the internet zone manager object:
There’s another CoInternetCreateZoneManager function to get the zone manager object’s IInternetZoneManager interface.
Choosing formats when putting data on clipboard
- 21 March 2012
The topic is from a forum discussion at https://web.archive.org/web/20131020094354/http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/94bb2db4-3ca2-4cd8-9f7c-6dd9aab6fd18/need-help-to-complete-gdi-program-to-loadsave-to-clipboard?forum=windowssdk
Generally an application should provide data in as many formats as possible so more applications can recognize the data. For example, IE stores text data in CF_UNICODETEXT, CF_TEXT and CF_HTML formats.
Application crash when forcing IE8 rendering mode in webbrowser host
- 17 November 2010
User stephench is reporting that when setting webbrowser rendering mode to IE8 via FEATURE_BROWSER_EMULATION, the app would crash. The web site crashes IE8 too, but IE8 is able to recover and automatically switch to IE7 mode, while a webbrowser host crash in WinInet when switching to the compatibility mode (Note the ReloadInCompatView function on the call stack). My guess is that reloading requires a WinInet helper process which a webbrowser host app does not have. The call stack is the following urlmon.dll!UUIDToWSTR() + 0x1f bytes urlmon.dll!GUIDToWSTR() + 0x1a bytes urlmon.dll!GUIDToWSTRCch() + 0x16 bytes urlmon.dll!CInPrivateBrowserModeFilter::_EnsureCLSID() + 0x20 bytes urlmon.dll!CSessionBrowserModeFilter::_GetDataStream() + 0x27 bytes urlmon.dll!CBrowserModeFilter::_EnsureBrowserModeFilter() + 0x1d84 bytes urlmon.dll!CBrowserModeFilter::IsIE7Mode() + 0x2e bytes mshtml.dll!CMarkup::ReloadInCompatView() + 0xd0 bytes mshtml.dll!CCssPageLayout::CalcSizeVirtual() + 0x120416 bytes mshtml.dll!CLayout::CalcSize() + 0x164 bytes mshtml.dll!CLayout::DoLayout() + 0x113 bytes mshtml.dll!CView::ExecuteLayoutTasks() - 0x1e376 bytes mshtml.dll!CView::EnsureView() + 0x567 bytes mshtml.dll!CView::EnsureViewCallback() + 0x66 bytes mshtml.dll!GlobalWndOnMethodCall() + 0xcc bytes mshtml.dll!GlobalWndProc() + 0xae bytes user32.dll!_InternalCallWinProc@20() + 0x28 bytes user32.dll!_UserCallWinProcCheckWow@32() + 0xb7 bytes user32.dll!_CallWindowProcAorW@24() + 0x51 bytes user32.dll!_CallWindowProcA@20() + 0x1b bytes mfc100.dll!_AfxActivationWndProc(HWND__ * hWnd=0x00150a28, unsigned int nMsg=32770, unsigned int wParam=0, long lParam=0) Line 471 + 0x11 bytes C++ user32.dll!_InternalCallWinProc@20() + 0x28 bytes user32.dll!_UserCallWinProcCheckWow@32() + 0xb7 bytes user32.dll!_DispatchMessageWorker@8() + 0xdc bytes user32.dll!_DispatchMessageA@4() + 0xf bytes > mfc100.dll!AfxInternalPumpMessage() Line 183 C++ mfc100.dll!CWinThread::Run() Line 629 + 0x7 bytes C++ mfc100.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00152348, int nCmdShow=1) Line 47 + 0x7 bytes C++
How to force popup window to navigate in the same window in a webbrowser control
- 22 November 2009
When clicking on an link that targets a new window, the default behavior of a webbrowser control host application is to open a new window in Internet Explorer. User ben_lai wants to know how to handle the click and navigate to the same window.
There are three events that notifies a new window, NewWindow (The current documentation of this event is wong, check http://support.microsoft.com/kb/185538/EN-US/ for the parameters of the event), NewWindow2 and NewWindow3, each one has a cancel parameter to stop the new window being created, though for NewWindow2, it requires cooperation of BeforeNavigate2 to get the url of the new window. After getting the url, the navigation can be carried out in the original window by calling Navigate2. The obsolete NewWindow Event has the url right in the parameter so you can cancel the navigation and call the navigation methods of the webbrowser control with the new url.
Intercept the download dialog in webbrowser control
- 04 November 2009
User rsd102 looks already find the solution to his question when he posted the question to CSDN, except for one missing piece. The sample he found is for overriding the global download manager, and what he need is a process wide override.
It looks like rsd102 is loving research. He found more than he can understand initially. After being suggested twice with the vague IE SDK documentation he decided to post the sample code he was working on. And when the final answer was given he had problem adopting it.
How to change the user agent and download control flags in a webbrowser control host
- 09 October 2009
User vnetvvv wants to know how to change the user agent string in a VB6 webbrowser control.
The knowledge base article PRB: WebBrowser Control Clients Share Global Settings provides the necessary code for changing the user agent of the webbrowser control when the webbrowser ask for it. But how to have the webbrowser control ask for the user agent?
How to disable navigation sound in webbrowser control
- 06 July 2009
User kill211 does not like the click sound when he calls WebBrowser.Navigate. He wonders if there is a way to disable it without modifying HKEY_CURRENT_USER\AppEvents\Schemes\Apps\Explorer\Navigating, which has effect on other applications.
Unfortunately, the API for disabling sound is introduced in IE7. The FEATURE_DISABLE_NAVIGATION_SOUNDS feature can be toggled using registry or the CoInternetSetFeatureEnabled API.
Walkaround for Error : An add-on for this website failed to run. When opening Visual C++’s Add Variable Wizard after IE 8 is installed
- 24 March 2009
Update: it looks like a lot of people are hitting this page by mistake. If you don’t write software for a living then this page is not for you.
The program is lost, but what it does is basically copying the entries from the restricted zone to the 1000 zone (custom zone of VC++ Wizards engine). In addition it has a REG_DWORD value set to 0 for name “1207”. IE security zone settings are stored in the registry path HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet SettingsZones
AutoComplete with DataSource
- 06 August 2007
Download Sample code: jiangsheng/Samples
.Net 2.0 introduced autocompletion in TextBox and ComboBox. It is obvious that autocomplete is not very useful when the number of options is small. However, when the number of option becomes too many, pre-filling of all options to an AutoCompleteStringCollection becomes impractical, especially when the data is coming from a remote computer. An alternative is to replace the AutoCompleteCustomSource in a TextChanged event, however, users are getting random AccessViolationException when trying to replace it. In this article I will demonstrate another alternative, using a BindingSource as the data source of options, bypassing the .Net Framework and call the underline Windows API directly.
Handle NewWindow3 and ShowModalDialog in CHtmlView
- 03 July 2007
CHTMLView does not support NewWindow3 as of MFC 9.0. It is relatively easy to add this support, given the event sink code in atlmfcsrcviewhtml.cpp
Add the following into the declaration of the derived CHtmlView class (named CHtmlViewTestView in this example)
Memory Leak in the Internet Explorer WebBrowser Control
- 28 February 2007
For automated applications such as parsers, the WebBrowser control may not be appropriate. Under IE4 there were several memory leak problems manifested when the control was repeatedly instantiated and destroyed and also, on occasions, when the control was merely navigated from page to page. Almost all of these problems were fixed and incorporated in the IE5 release. However new memory leaks were introduced in the script engine, the URL navigation history, and the security system. There is no word at this time on when these problems will be fixed. Unfortunately, some leaks ( the travel log that enable you to go back, for example) have been declared to be “by design” by the development team. For those applications where this is not possible it may be necessary for the customer to use a WebBrowser control from a non-Microsoft vendor that is designed for the type of long term continuous real-time activity that your are developing for.
If you need a similar interface, try the Mozilla ActiveX Control (I know little about it, so I am not sure it leaks memory or not) at https://web.archive.org/web/20010920144243/http://www.iol.ie/~locka/mozilla/control.htm. Apparently, you need to have Mozilla installed to use this Activex control. A hosting sample can be found at https://web.archive.org/web/20030422065641/www.codeproject.com/useritems/iemozilla.asp .
Visual Studio 2005 Untrusted by IE7
- 11 November 2006
Today I upgraded one of my development machine to IE7. Everything looks fine, except I have to change the FileDownload event handler to make my code compile.
However, suddenly I found Visual Studio 2005 is complaining:
Conclusion:
Visual Studio is based on WebBrowser control (Is this news story?)
Upgrade to IE7 may break some applications (Again, is this a news story?)
Everything else works fine so far…
Error: Unable to cast COM object of type ‘mshtml.HTMLDocumentClass’ to interface type ‘ICustomDoc’
- 23 October 2006
This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{3050F3F0-98B5-11CF-BB82-00AA00BDCE0B}’ failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
My first reaction was:”What the hell? HTMLDocumentClass is the managed wrapper of MSHTML, and MSHTML is supposed to support the ICustomDoc interface!” Now I started wondering why the interfaces don’t work I created a sandbox project and tried to cast interface there, but it works smoothly. I played with strong name and found no luck. Finally, I found out that it is the frame document that does not support this interface.
PRB: ::SetUIHandler Causes Changes in Save As Dialog
- 21 April 2006
For the description of this problem, see http://support.microsoft.com/kb/330441.
A workaround is delegating DHTML commands to the origional webbrowser object through its IOleCommandTarget interface. A sample can be found at http://www.codeproject.com/atl/popupblocker.asp:
创建和自动化Internet Explorer和资源管理器窗口
- 20 October 2005
下载示例工程 - 34 Kb jiangsheng/Samples
我在很久之前就开始用程序自动化Shell窗口——主要对象是IE窗口。有时浏览器控件或者MFC类CHTMLView可以满足我的需要,但是很多时候我需要从头嵌入浏览器控件并且尽可能模拟IE的行为,例如实现IDocHostUIHandler来启用自动完成功能。一个很自然的替代方案是直接操作IE窗口。
在使用浏览器控件的程序中判断HTTP错误
- 07 April 2005
在自动化浏览器控件提交表单之后,浏览器控件可能会在浏览超时时重定向到一个错误页面。有时需要用代码控制页面返回之后重新提交表单。
IE6.0之前的版本浏览器控件没有获得HTTP状态的接口。一个很依赖于网站设置的方法是,捕获TitleChange事件,在页面标题包含”找不到页面”或者”Page Not Found”之类的字符串时,认为浏览失败。另一个方法是处理BeforeNavigate2事件,用winhttp api单独和服务器连接,使用HttpQueryInfo来查询,相应参数是HTTP_QUERY_STATUS_CODE。在这之前,你可能要在打开URL时用INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS标志来防止服务器的重定向。
如何: 通过HTML文档对象模型访问文档中的ActiveX控件的属性
- 13 July 2004
111222的CSDN文档中心文章 用 MSHTML 的一点经验(https://web.archive.org/web/20051126180205/http://dev.csdn.net/develop/article/10/10456.shtm) 说明了如何访问在HTML文档对象模型中的网页的元素、内容。但是,有时候开发者实际上需要访问的是网页中ActiveX控件的属性、方法和事件。例如,你在网页载入之后需要修改/获取MediaPlayer的媒体源,以及控制MediaPlayer的播放。
为获得ActiveX控件的接口,我们需要访问文档对象模型。获得文档接口的方法多种多样,比如CHtmlView::GetHtmlDocument,IWebBrowser2::get_Document,IHTMLWindow2::get_document等等,参见111222的文档。这里我直接用一个函数GetDHtmlDocument表示获得这个接口的函数。你可以自己实现这个函数。
别了,北京 Time To Say Goodbye
- 07 July 2004
docs/blogs/2004/enable_autocomplete_forms_webbrowser_control.rst 今天把MSN昵称改成“别了,北京 Time To Say Goodbye”之后,询问的信息纷至沓来,这肯定是我的聊天工具最忙的一天,同时有人开始组织欢送计划——当然是计划掏我的腰包……。
“该走的总是要走的,一路顺风”。
在应用程序中集成浏览器控件(Update)(Subjet to change without notice)
- 06 July 2004
浏览器控件是一个提供浏览器绝大部分功能的ActiveX控件,随Microsoft? Internet Explorer 4.0(IE)或者更高版本发行。实际上,IE可以认为是一个集成浏览器控件的程序。
怎么给用户提供丰富的内容一直是程序员们努力的目标。尽管各种各样的界面库可能使你眼花缭乱,但是这些也是美工和程序员的恶梦——要自定义界面上的每个元素的外观并不是一件容易的事情,而且有时候需要比较复杂的技术,例如自定义程序中出现的滚动条的颜色。
在应用程序中添加宏支持的注意事项 (Update)
- 27 June 2004
用笔记本用多了,PC键盘用起来不是很习惯了。
在我的一篇文章脚本化浏览器中描述了如何在应用程序中添加宏支持。在添加支持的时候需要注意的是,宏的运行环境——VBS脚本引擎——目前只支持变体数据类型。这造成的一个结果就是当你的应用程序触发一个事件的时候,如果其参数并不都是变体数据类型,那么你编写的宏不是总会被调用。解决的方法是总是声明你的事件参数为变体数据类型。
编程删除IE历史
- 01 April 2004
明天出发去西雅图参加微软全球最有价值专家年会了,暂停更新一段时间。
在你调用IUrlHistoryStg:DeleteUrl 之后, 这个URL项目仍旧会出现在IE历史纪录目录中。
在浏览器中粘贴时替换剪贴板数据
- 20 March 2004
在某些时候,可能需要覆盖剪贴板的数据,例如过滤聊天时在输入窗口粘贴非文字格式的信息。对于浏览器控件的编辑模式,浏览器提供了IDocHostUIHandler接口来支持粘贴时提供一个替代的数据源来覆盖剪贴板的数据。下面的代码描述了如何过滤除了CF_TEXT之外的剪贴板格式
使用IE5内建的进度对话框
- 12 February 2004
本来想自己写一个的,但是发现codeproject上面已经有了(https://web.archive.org/web/20000604080517/http://www.codeproject.com/miscctrl/iprogressdialog.asp)
下面是微软知识库里面的一个示例
CDHtmlDialog&NewWindow2
- 12 February 2004
Class ID Default Interface Default Event Interface —————– —————– ———————– CLSID_WebBrowser IWebBrowser2 DWebBrowserEvents2 CLSID_WebBrowser_V1 IWebBrowser DWebBrowserEvets
CDHtmlDialog捕获了DWebBrowserEvets事件,并将其转发到虚函数,而没有捕获DWebBrowserEvents2;所以在按Ctrl+N触发DWebBrowserEvents2事件的时候,执行默认操作——打开新的IE窗口。这可能不是你预料之中的行为。
在浏览器控件中启用自动完成功能
- 09 January 2004
自动完成功能在浏览器控件中默认是禁用的(但是没有任何文档提到这一点……),但是可以通过实现IDocHostUIHandler,在GetHostInfo方法中在填充DOCHOSTUIINFO结构的dwFlags成员时设置DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE标识位来启用。
关于如何实现IDocHostUIHandler,可以参考 https://web.archive.org/web/20030218020128/http://msdn.microsoft.com/workshop/browser/hosting/wbcustomization.asp ,示例工程在https://github.com/jiangsheng/Samples/tree/master/IEAutomation
问题:Internet Explorer中的控件在可见之前没有被创建
- 23 October 2003
Q195188 PRB: ActiveX Control Window Is Not Created Until Visible in Internet Explorer 使用知识库里面的方法
在Windows XP中,可以在任务栏上看到控件的窗口,很是不雅观
浏览器程序中添加宏支持
- 23 October 2003
这个教程提供在浏览器程序中添加宏支持的方法,你会看到如何给MFC的程序添加宏支持。这篇文章也讨论了如何扩展VC6中的CHtmlView的功能,如何实现MDI结构的浏览器,以及如何分析DHTML的文档结构。
单击 jiangsheng/Samples 下载本文的代码
写篇文章真累
- 23 October 2003
最近一篇文章(浏览器集成教学–在浏览器程序中添加宏支持)长长短短,写了两个礼拜吧。
写这篇文章的主要原因是想把网页分析做得更加灵活。这篇文章的基础是我以前为一个EBS游戏写的外挂,可以自动修改网页内容(主要是表单)和定时submit表单(有的网站的submit有时间限制)。