MFC : How to capture a link click event in a web browser control?

两盒软妹~` 提交于 2019-12-08 01:06:25

问题


I have an MFC application that has a webcontrol. When clickable links are clicked, it opens using IE, not the default browser. Questions :

  1. Is there a way to force it to open using the default browser?
  2. If not, how do I capture the Link Click event so I could just manipulate the click event later?

Thanks...


回答1:


  1. No, not as far as I know.
  2. Check out the articles on http://ehsanakhgari.org/article/visual-c/webbrowser-goodies . It has a number of articles that show how to set up an event sink using IDocHostUIHandler etc. to handle events like clicking of links. I'm not sure which interface to implement, it's been years since I last did this. Then, you use ShellExecute() with a url as the third parameter to open a url with the default browser.



回答2:


You can capture click events by using "HRESULT STDMETHODCALLTYPE Invoke" see MSDN for more details. And here's a great example that shows how to open your URL using the default browser in the same window, or opening a new window > http://www.codeproject.com/KB/IP/urlnewwindow.aspx



来源:https://stackoverflow.com/questions/2294636/mfc-how-to-capture-a-link-click-event-in-a-web-browser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!