예제 #1
0
BOOL CALLBACK DlgProc(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam)
{
	IWebBrowser2* iWebBrowser;
	VARIANT varMyURL;
	CAxWindow WinContainer;
	LPOLESTR pszName = OLESTR("shell.Explorer.2");
	RECT rc;
	BOOL result = FALSE;


	switch(Msg)
	{
	case WM_INITDIALOG:
		browserEventListener.setUnloaded();
		GetClientRect(hwnd, &rc);
		WinContainer.Create(hwnd, rc, 0,WS_CHILD |WS_VISIBLE);
		WinContainer.CreateControl(pszName);
		WinContainer.QueryControl(__uuidof(IWebBrowser2),(void**)&iWebBrowser); 
		VariantInit(&varMyURL);
		varMyURL.vt = VT_BSTR; 
		varMyURL.bstrVal = SysAllocString(OLESTR("about:blank"));
		browserEventListener.Advise(hwnd, iWebBrowser);
		iWebBrowser-> Navigate2(&varMyURL,0,0,0,0);

		VariantClear(&varMyURL);
		iWebBrowser-> Release(); 
		result = TRUE;
		break;
	case WM_HTML_ACTION:
		switch (wParam)
		{
		case ACTION_COMMIT:
			EndDialog(hwnd, ACTION_COMMIT);
			result = TRUE;
			break;
		case ACTION_RETURN:
			EndDialog(hwnd, ACTION_RETURN);
			result = TRUE;
			break;
		}
		break;
	case WM_COMMAND:
		switch(wParam)
		{
		case IDCANCEL:
			EndDialog(hwnd, ACTION_RETURN);
			result = TRUE;
		}
		break;
	}

	return result;
}
bool Win32WebControl::createWebView(
    const std::function<bool (const std::string &)> &shouldStartLoading,
    const std::function<void (const std::string &)> &didFinishLoading,
    const std::function<void (const std::string &)> &didFailLoading,
    const std::function<void (const std::string &)> &onJsCallback)
{
    bool ret = false;
    IConnectionPointContainer *container = NULL;
    do
    {
        HWND hwnd = cocos2d::Director::getInstance()->getOpenGLView()->getWin32Window();
        _winContainer.Create(hwnd, NULL, NULL, WS_CHILD | WS_VISIBLE);

        HRESULT hr;
        hr = _winContainer.CreateControl(L"shell.Explorer.2");
        CC_BREAK_IF(FAILED(hr));

        hr = _winContainer.QueryControl(__uuidof(IWebBrowser2), (void **)&_webBrowser2);
        CC_BREAK_IF(FAILED(hr) || _webBrowser2 == NULL);

        _webBrowser2->put_Silent(VARIANT_TRUE);

        VARIANT var;
        VariantInit(&var);
        var.vt = VT_BSTR;
        var.bstrVal = SysAllocString(L"about:blank");
        hr = _webBrowser2->Navigate2(&var, NULL, NULL, NULL, NULL);
        SysFreeString(var.bstrVal);
        VariantClear(&var);
        CC_BREAK_IF(FAILED(hr));

        hr = _webBrowser2->QueryInterface(IID_IConnectionPointContainer, (void **)&container);
        CC_BREAK_IF(FAILED(hr));

        hr = container->FindConnectionPoint(DIID_DWebBrowserEvents2, &_connectionPoint);
        CC_BREAK_IF(FAILED(hr));

        hr = _connectionPoint->Advise(this, &_cookie);
        CC_BREAK_IF(FAILED(hr));

        hr = _webBrowser2->get_Document(&_htmlDoc);
        CC_BREAK_IF(FAILED(hr));

        ret = true;
    } while (0);

    if (!ret)
    {
        removeWebView();
    }
    if (container != NULL)
    {
        container->Release();
        container = NULL;
    }

    _shouldStartLoading = shouldStartLoading;
    _didFinishLoading = didFinishLoading;
    _didFailLoading = didFailLoading;
    _onJsCallback = onJsCallback;
    return ret;
}