在C ++ Windows桌面应用程序中显示webview/webpage窗口 [英] show webview/webpage window in c++ windows desktop application

查看:102
本文介绍了在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?

推荐答案

  1. 创建一个空的C ++项目
  2. 创建资源对话框.右键单击对话框,然后添加ActiveX-> Microsoft Web Browser控件.调整大小,然后移到正确的位置.更改ID,以便您可以在程序中对其进行识别
  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;
}

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

Also there is an Edge controller to Chromium Edge WebView controller

这篇关于在C ++ Windows桌面应用程序中显示webview/webpage窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆