C++, win32 api: How to create an html rendering window so that your application would get callbacks from JS calls?

╄→尐↘猪︶ㄣ 提交于 2019-12-10 10:18:59

问题


What I need is simple: we have a console app project. We want to have such a function that would open a simple window with nothing but html (default system based) html + js rendering window that would read some default html+js string (form string or const char*). we want to have our own api joined with default js api so that when JS calls some our.function(argument); we would have our C++ application performe some function and for example cout argument. How to create such thing on windows?


回答1:


  1. CoCreate the MSHTML com object for HTML Documents:

    CComPtr spDoc; HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (void**)&spDoc);

  2. Do something like this to read your HTML string and make the document render it.

  3. Depending on what you need in terms of callbacks, you can use the COM DOM Interfaces to traverse the tree, and then sink the appropriate DispInterfaces to get events on the elements you're interested in. I would recommend this.

  4. If what I suggest in #3 isn't good enough for you (and I'd like to hear why) then you can implement your own ActiveX control and have script on your page call methods on it as suggested by raj.




回答2:


Brushing aside any security / cross browser/platforms concerns you can use implement an ActiveX object in your C++ that you can invoked from javascript.

http://msdn.microsoft.com/en-us/library/7sw4ddf8(v=vs.94).aspx




回答3:


The host for the WebBrowser control can provide an object that will be accessible to scripts via the external object.

See http://msdn.microsoft.com/en-us/library/aa770041.aspx#GetExternal



来源:https://stackoverflow.com/questions/6479116/c-win32-api-how-to-create-an-html-rendering-window-so-that-your-application

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