在C ++ Windows桌面应用程序中显示webview/webpage窗口

编程入门 行业动态 更新时间:2024-10-23 13:28:36
本文介绍了在C ++ Windows桌面应用程序中显示webview/webpage窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在c ++ Windows应用程序中显示弹出窗口/通知.该通知将显示我们网站上的网页.我正在寻找类似于CEF的东西,但要使用本机OS API来显示Webview内容.也许有些类可以与CreateWindowEx一起使用?

I want to display a popup/notification in a c++ windows application. The notification will display a webpage from our website. I am looking for something similar to CEF but native OS APIs to display the webview content. Maybe there is some class that I could use with CreateWindowEx?

推荐答案

  • 创建一个空的C ++项目
  • 创建资源对话框.右键单击对话框,然后添加ActiveX-> Microsoft Web Browser控件.调整大小,然后移到正确的位置.更改ID,以便您可以在程序中对其进行识别
  • 添加具有相似内容的C ++文件:
  • //#import #include <Windows.h> #include <Ole2.h> #include "resource.h" #include <iostream> #include <atlbase.h> //activex #include <atlwin.h> //windows #include <atlcom.h> //This will load the browser dll then library and will generate headers //All the declarations will be in the namespace SHDocVw #import "shdocvw.dll" using namespace std; class CMyDialog : public CAxDialogImpl<CMyDialog> { public: enum { IDD = IDD_DIALOG_COM}; BEGIN_MSG_MAP(CMyDialog) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnBnCancel) COMMAND_HANDLER(IDOK, BN_CLICKED, OnBnOk) END_MSG_MAP() CComPtr<SHDocVw::IWebBrowser2> ctrl; LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { // Do some initialization code HRESULT hr; //IDC_EXPLORER_TEST is the ID of your control GetDlgControl(IDC_EXPLORER_TEST, __uuidof(ctrl), (void**)&ctrl); _variant_t address = L"google"; //open a web page hr = ctrl->Navigate2(&address); LRESULT res = CAxDialogImpl<CMyDialog>::OnInitDialog(uMsg, wParam, lParam, bHandled); return 0; } public: LRESULT OnBnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { EndDialog(IDCANCEL); return 0; } LRESULT OnBnOk(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { EndDialog(IDOK); return 0; } }; CComModule _Module; int main() { CMyDialog dlg; dlg.DoModal(); return 0; }

    还有一个Chromium Edge的Edge控制器 WebView控制器

    Also there is an Edge controller to Chromium Edge WebView controller

    更多推荐

    在C ++ Windows桌面应用程序中显示webview/webpage窗口

    本文发布于:2023-11-11 10:38:16,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1578188.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:应用程序   桌面   窗口   Windows   webpage

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!