在C++ Windows桌面应用程序中显示webview网页窗口。

问题描述 投票:0回答:1

我想在一个C++窗口应用程序中显示一个弹出式通知。该通知将显示我们网站的一个网页。我正在寻找类似于CEF的东西,但是要用原生的操作系统API来显示webview的内容。也许有一些类我可以和CreateWindowEx一起使用?

c++ webview chromium-embedded iwebbrowser2
1个回答
0
投票
  1. 创建一个空的C++项目
  2. 创建一个资源对话框。右键点击对话框,添加一个ActiveX->Microsoft Web Browser控件。调整它的大小,并移动到正确的位置。改变ID,这样你就可以在你的程序中识别它。enter image description here
  3. 添加一个类似内容的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.com";
        //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;
}

还有一个Edge控制器到Chromium Edge上WebView控制器

© www.soinside.com 2019 - 2024. All rights reserved.