예제 #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;
}
HWND CIETabProcControl::CreateControlWindow(HWND hwndParent, RECT &rcPos)
{
    CAxWindow axWin;
    HWND hwndCtrl;
    HWND hwndIE;

    hwndCtrl = Create(hwndParent, rcPos, NULL, WS_CHILD|WS_VISIBLE);

    hwndIE = axWin.Create(hwndCtrl, rcPos, L"{8856F961-340A-11D0-A96B-00C04FD705A2}", WS_CHILD|WS_VISIBLE);
    ::SetWindowPos(hwndIE, hwndCtrl, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER);

    g_hwndApp = hwndCtrl;

    axWin.QueryControl(IID_IWebBrowser2, (void**)&m_spInnerWebBrowser);
    if (m_spInnerWebBrowser)
    {
        WCHAR wszUrl[2048] = {0};

        m_spInnerWebBrowser->QueryInterface(IID_IOleInPlaceActiveObject, 
                                            (void**)&g_pIOleInPlaceActiveObject);

        CComPtr<IConnectionPointContainer> spConnectionPointContainer;
        m_spInnerWebBrowser->QueryInterface(IID_IConnectionPointContainer,(void**)&spConnectionPointContainer);
        if (spConnectionPointContainer)
        {
            spConnectionPointContainer->FindConnectionPoint(DIID_DWebBrowserEvents2,&m_spCP);
            if (m_spCP)
            {
                m_spCP->Advise((IDispatch*)this,&m_dwCookie);
            }
        }

        if (ExpandEnvironmentStrings(L"%programfiles%\\multiloginhelper\\help.htm", 
                                     wszUrl, 2048))
        {
            m_spInnerWebBrowser->Navigate(wszUrl, NULL, NULL, NULL, NULL);
        }
        else
        {
            m_spInnerWebBrowser->Navigate(L"www.live.com", NULL, NULL, NULL, NULL);
        }
    }

    return hwndCtrl;
}
예제 #3
0
LRESULT CHTMLDialogEx::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    RECT rect = {0, 0, 0, 0};

    SetWindowPos(NULL, 0, 0, m_cx, m_cy, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
    GetClientRect(&rect);
    ModifyStyleEx(WS_EX_APPWINDOW|WS_EX_CONTROLPARENT/*dwRemove*/, 0/*dwAdd*/);

    // Create the web browser control
    CAxWindow wnd;
    wnd.Create(m_hWnd, rect, m_strURL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL, 0/*WS_EX_CLIENTEDGE*/, ID_HTMLCONTROL);
    HRESULT hr = wnd.SetExternalDispatch(m_pDispatch);
    //{
    //	m_hWndCtrl = wnd.m_hWnd;
    //	ATLASSERT(::IsWindow(m_hWndCtrl));
    //	CHTMLDialogEx::m_wpOrigHtmlProc = (WNDPROC) ::SetWindowLong(m_hWndCtrl,
    //		GWL_WNDPROC, (LONG) CHTMLDialogEx::HtmlCtrlSubclassProc);
    //}

    if (m_pBrowser)
        m_pBrowser.Release();

    m_pBrowser = NULL;
    if (SUCCEEDED(hr))
    {
        hr = wnd.QueryControl(&m_pBrowser);
        if (m_pBrowser)
        {
            hr = m_pBrowser->put_RegisterAsDropTarget(VARIANT_FALSE);
            Connect(m_pBrowser);
        }
    }

    DragAcceptFiles(false);
    wnd.DragAcceptFiles(false);

    //if (m_bModal && m_pDocWnd)
    //	m_pDocWnd->SetHTMLDlgHWND(m_hWnd);

    CenterWindow();
    ShowWindow(SW_SHOW);

    return IDOK;  // Let the system set the focus
}
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;
}