在 c++ windows 桌面应用程序中显示 webview/webpage window
show webview/webpage window in c++ windows desktop application
我想在 c++ windows 应用程序中显示 popup/notification。该通知将显示我们网站的网页。我正在寻找类似于 CEF 但本机 OS API 的东西来显示 webview 内容。也许有一些 class 可以与 CreateWindowEx 一起使用?
- 创建一个空的 C++ 项目
- 创建一个资源对话框。右键单击对话框并添加一个 ActiveX->Microsoft Web 浏览器控件。调整它的大小,并移动到正确的位置。更改 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.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 controller
我想在 c++ windows 应用程序中显示 popup/notification。该通知将显示我们网站的网页。我正在寻找类似于 CEF 但本机 OS API 的东西来显示 webview 内容。也许有一些 class 可以与 CreateWindowEx 一起使用?
- 创建一个空的 C++ 项目
- 创建一个资源对话框。右键单击对话框并添加一个 ActiveX->Microsoft Web 浏览器控件。调整它的大小,并移动到正确的位置。更改 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.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 controller