show webview/webpage window in c++ windows desktop application

2.7k Views Asked by At

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

There are 1 best solutions below

3
armagedescu On BEST ANSWER
  1. Create an empty C++ project
  2. Create a resource dialog. Right click on dialog and add an ActiveX->Microsoft Web Browser control. Resize it, and move to right place. Change the ID so you can identify it in your program enter image description here
  3. Add a C++ file with similar content:
//#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;
}

Also there is an Edge controller to Chromium Edge WebView controller