C++,win32 api:如何创建 html 渲染窗口,以便您的应用程序从 JS 调用中获取回调?

发布于 2024-11-17 04:28:58 字数 265 浏览 8 评论 0原文

我需要的很简单:我们有一个控制台应用程序项目。我们希望有这样一个函数,它可以打开一个简单的窗口,只有 html(基于默认系统)html + js 渲染窗口,该窗口将读取一些默认的 html+js 字符串(表单字符串或 const char*)。我们希望将我们自己的 api 与默认的 js api 结合起来,这样当 JS 调用一些 our.function(argument); 时,我们会让我们的 C++ 应用程序执行一些函数,例如 cout 参数。如何在windows上创建这样的东西?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七月上 2024-11-24 04:28:58
  1. 为 HTML 文档共同创建 MSHTML com 对象:

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

  2. 执行类似this 的操作来读取 HTML 字符串并使文档呈现

  3. 根据回调方面的需要,您可以使用 COM DOM Interfaces 遍历树,然后下沉相应的DispInterfaces 获取您的元素上的事件我会推荐这个。

  4. 如果我在 #3 中的建议对您来说不够好(我想听听为什么),那么您可以实现自己的 ActiveX 控件,并按照 raj 的建议在页面上调用脚本。

  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.

别把无礼当个性 2024-11-24 04:28:58

抛开任何安全/跨浏览器/平台问题,您可以使用 C++ 实现一个可以从 javascript 调用的 ActiveX 对象。

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

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

江南烟雨〆相思醉 2024-11-24 04:28:58

WebBrowser 控件的宿主可以提供一个对象,脚本可以通过external 对象访问该对象。

请参阅 http://msdn.microsoft.com/en-us/library/ aa770041.aspx#GetExternal

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文