怎么利用webkit内核加载一个网页并显示出来,其中窗口为HWND m_window?
//创建网页其中m_webview是WKViewRef类型create(RECTwebViewRect,HWNDm_window){staticWKContextRefc...
//创建网页其中m_webview是WKViewRef类型
create(RECT webViewRect, HWND m_window)
{
static WKContextRef context = WKContextCreate();
m_webView = WKViewCreate(webViewRect, context, 0, m_window);
WKPageUIClient uiClient = {
kWKPageUIClientCurrentVersion,
parentWindow,
0, showPage, closePage, 0, 0, 0,
runJavaScriptAlert,
runJavaScriptConfirm,
runJavaScriptPrompt,
setStatusText, 0,
0, 0, 0, 0,0, 0,0, 0, 0, 0,0, 0, 0,0, 0,
0, 0,0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0,
createNewPage,
mouseDidMoveOverElement,
0, 0, 0, 0,
};
WKPageSetPageUIClient(WKViewGetPage(m_webView), &uiClient);
WKViewSetIsInWindow(m_webView, true);
}
//加载网页
goToURL(const std::wstring& urlString)
{
CFStringRef string = CFStringCreateWithCharacters(0, (const UniChar*)urlString.data(), urlString.size());
CFStringRef escapedString = CFURLCreateStringByAddingPercentEscapes(0, string, 0, 0, kCFStringEncodingUTF8);
CFRelease(string);
CFURLRef cfURL = CFURLCreateWithString(0, escapedString, 0);
CFRelease(escapedString);
WKURLRef url = WKURLCreateWithCFURL(cfURL);
CFRelease(cfURL);
WKPageRef page = WKViewGetPage(m_webView);
WKPageLoadURL(page, url);
WKRelease(url);
}
PS:这样写的结果,加载后显示为空白!!希望能给出原因或其他实现方法的代码!! 展开
create(RECT webViewRect, HWND m_window)
{
static WKContextRef context = WKContextCreate();
m_webView = WKViewCreate(webViewRect, context, 0, m_window);
WKPageUIClient uiClient = {
kWKPageUIClientCurrentVersion,
parentWindow,
0, showPage, closePage, 0, 0, 0,
runJavaScriptAlert,
runJavaScriptConfirm,
runJavaScriptPrompt,
setStatusText, 0,
0, 0, 0, 0,0, 0,0, 0, 0, 0,0, 0, 0,0, 0,
0, 0,0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0,
createNewPage,
mouseDidMoveOverElement,
0, 0, 0, 0,
};
WKPageSetPageUIClient(WKViewGetPage(m_webView), &uiClient);
WKViewSetIsInWindow(m_webView, true);
}
//加载网页
goToURL(const std::wstring& urlString)
{
CFStringRef string = CFStringCreateWithCharacters(0, (const UniChar*)urlString.data(), urlString.size());
CFStringRef escapedString = CFURLCreateStringByAddingPercentEscapes(0, string, 0, 0, kCFStringEncodingUTF8);
CFRelease(string);
CFURLRef cfURL = CFURLCreateWithString(0, escapedString, 0);
CFRelease(escapedString);
WKURLRef url = WKURLCreateWithCFURL(cfURL);
CFRelease(cfURL);
WKPageRef page = WKViewGetPage(m_webView);
WKPageLoadURL(page, url);
WKRelease(url);
}
PS:这样写的结果,加载后显示为空白!!希望能给出原因或其他实现方法的代码!! 展开
展开全部
可以参考 webkit tool 里的 WinLauncher 工程:
standardPreferences->setAcceleratedCompositingEnabled(TRUE);
HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, reinterpret_cast<void**>(&gWebView));
if (FAILED(hr))
goto exit;
hr = gWebView->QueryInterface(IID_IWebViewPrivate, reinterpret_cast<void**>(&gWebViewPrivate));
if (FAILED(hr))
goto exit;
gWebHost = new WinLauncherWebHost();
gWebHost->AddRef();
hr = gWebView->setFrameLoadDelegate(gWebHost);
if (FAILED(hr))
goto exit;
gPrintDelegate = new PrintWebUIDelegate;
gPrintDelegate->AddRef();
hr = gWebView->setUIDelegate(gPrintDelegate);
if (FAILED (hr))
goto exit;
hr = gWebView->setHostWindow(reinterpret_cast<OLE_HANDLE>(hMainWnd));
if (FAILED(hr))
goto exit;
hr = gWebView->initWithFrame(clientRect, 0, 0);
if (FAILED(hr))
goto exit;
IWebFrame* frame;
hr = gWebView->mainFrame(&frame);
if (FAILED(hr))
goto exit;
standardPreferences->setAcceleratedCompositingEnabled(TRUE);
HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, reinterpret_cast<void**>(&gWebView));
if (FAILED(hr))
goto exit;
hr = gWebView->QueryInterface(IID_IWebViewPrivate, reinterpret_cast<void**>(&gWebViewPrivate));
if (FAILED(hr))
goto exit;
gWebHost = new WinLauncherWebHost();
gWebHost->AddRef();
hr = gWebView->setFrameLoadDelegate(gWebHost);
if (FAILED(hr))
goto exit;
gPrintDelegate = new PrintWebUIDelegate;
gPrintDelegate->AddRef();
hr = gWebView->setUIDelegate(gPrintDelegate);
if (FAILED (hr))
goto exit;
hr = gWebView->setHostWindow(reinterpret_cast<OLE_HANDLE>(hMainWnd));
if (FAILED(hr))
goto exit;
hr = gWebView->initWithFrame(clientRect, 0, 0);
if (FAILED(hr))
goto exit;
IWebFrame* frame;
hr = gWebView->mainFrame(&frame);
if (FAILED(hr))
goto exit;
追问
谢谢!!
你说的我也试过了,有关于CLSID_WebView和_IID_IWebView错误,添加了相应的.h文件和.lib文件后还是报错
报错为:
无法解析的外部符号 _CLSID_WebView
无法解析的外部符号 _IID_IWebView
另外,我是仿照minibrowser写的,这样写有问题吗??
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询