Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
tools
vsnet.act
vsnet.debugging
vsnet.documentation
vsnet.enterprise.tools
vsnet.general
vsnet.ide
vsnet.jlca
vsnet.servicepacks
vsnet.setup
vsnet.vsip
vsnet.vss
vsnet.vstools.office
vstudio.development
vstudio.extensibility
vstudio.general
vstudio.helpauthoring
vstudio.setup
vstudio.sourcesafe
  
 
date: Mon, 21 Apr 2008 14:24:14 -0700,    group: microsoft.public.vstudio.development        back       


VS2008 Browser Navigation Does Not Display Page   
The following C++ code works in VS2005 but not in VS2008. All the return 
codes from the called functions are successful under VS2008 and even the 
Navigate2 function is successful, but the page does not display on the 
screen. Instead only a white background appears.

Here is the code snippet:

HWND hWnd;
DWORD dwCookie;
CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_spWebBrowser;
CComQIPtr<IOleCommandTarget, &IID_IOleCommandTarget> m_spOleCmdTarg;



HRESULT STDMETHODCALLTYPE PSXCIDView::Initialize(
IApexApplication* pAppInit, 
HWND hParentWnd, 
BOOL* pVal)
{
Trace trace(L"PSXCIDView::Initialize");

static WCHAR szAppName[] = TEXT ("PSXCIDView") ;
MSG msg = {0};
WNDCLASS wndclass = {0};

wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = ::GetModuleHandle(0);
wndclass.hIcon = 0; // LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW) ;
wndclass.hbrBackground = 0; // (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;

RegisterClass(&wndclass);

hWnd = CreateWindowEx(
WS_EX_TOPMOST,
szAppName,
TEXT("PSXCIDView"),
WS_POPUP,
0,
0,
1024,
768,
hParentWnd,
NULL,
GetModuleHandle(0),
this
);

if (!hWnd)
{
trace(DCM_ERROR) << L"Failed creating window for browser; Error = " << 
GetLastError() << endl;
*pVal = FALSE;
return E_FAIL;
}

ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);

CComPtr<IOleObject> spOleObject;

HRESULT hr = CoCreateInstance(
CLSID_WebBrowser, 
NULL, 
CLSCTX_INPROC, 
IID_IOleObject,
(void**)&spOleObject
);

if (hr != S_OK)
{
trace(DCM_ERROR) << L"CoCreateInstance failed; Error = " << hr << endl;
*pVal = FALSE;
return E_FAIL;
}

if (spOleObject->SetClientSite(this) != S_OK)
{
trace(DCM_ERROR, L"SetClientSite failed");
*pVal = FALSE;
return E_FAIL;
}

/* In-place activate the WebBrower control */

RECT rcClient = {0};
hr = spOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, &msg, this, 0, hWnd, 
&rcClient);

if (hr != S_OK)
{
trace(DCM_ERROR, L"DoVerb failed");
*pVal = FALSE;
return E_FAIL;
}

/* Get the pointer to the WebBrowser control. Note that setting a CComQIPtr
equal to a pointer of another type cause CComQIPtr to call QueryInterface. */
m_spWebBrowser = spOleObject;
_ASSERT(m_spWebBrowser);

if (!m_spWebBrowser)
{
trace(DCM_ERROR, L"Browser control pointer failed");
*pVal = FALSE;
return E_FAIL;
}

/* Set up the connection to the WebBrowser control to receive events. */
hr = AtlAdvise(m_spWebBrowser, GetUnknown(), DIID_DWebBrowserEvents2, 
&dwCookie);

if (FAILED(hr))
{
ATLTRACE(L"Failed to Advise\n");
trace(DCM_ERROR, L"Failed to Advise");
*pVal = FALSE;
return E_FAIL;
}

/* QI for the IOleCommandTarget interface that will be used later */
m_spOleCmdTarg = m_spWebBrowser;
_ASSERT(m_spOleCmdTarg);

/* Go to the user's home page */
m_spWebBrowser->GoHome();

CComVariant vtEmpty;
CComBSTR bstrURL(L"c:\temp\helloworld.htm");
m_spWebBrowser->Navigate2(bstrURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty);

*pVal = TRUE;

return S_OK;
}
date: Mon, 21 Apr 2008 14:24:14 -0700   author:   msdn_rookie

RE: VS2008 Browser Navigation Does Not Display Page   
"msdn_rookie" wrote:

> The following C++ code works in VS2005 but not in VS2008. All the return 
> codes from the called functions are successful under VS2008 and even the 
> Navigate2 function is successful, but the page does not display on the 
> screen. Instead only a white background appears.

I'm msdn_rookie's colleague on this particular project. I actually stumbled 
onto his post while searching for solutions to this problem. I thought I'd 
post an update in case it might help anyone, or help prompt a solution.

First of all, the following line was just a typo, I think: 

CComBSTR bstrURL(L"c:\temp\helloworld.htm");

The backspaces should have been escaped, but that's not the problem. If I 
put a message loop immediately after this code (GetMessage, TranslateMessage, 
DispatchMessage), the web page appears and I can interact with it. When I 
remove this message loop, however, the main message loop elsewhere in this 
application apparently isn't pumping the necessary messages to allow the 
browser control to correctly update and process inputs.

The main message loop is calling MsgWaitForMultipleObjects with an array of 
one event, with an INFINITE timeout, and the final two parameters are 
QS_ALLINPUT and 0. I can see and process the event notification, and when a 
message arrives I can call PeekMessage and process the message I need to 
catch, but calling TranslateMessage and DispatchMessage for the rest of the 
messages doesn't appear to feed the browser control whatever it's looking for.

PMP
date: Tue, 3 Jun 2008 11:57:01 -0700   author:   paulmooreparks

RE: VS2008 Browser Navigation Does Not Display Page   
I just found the problem. One or more of the messages I was catching in my 
main message loop apparently needed to be dispatched to the browser control 
and/or its host windows. I changed my message loop to dispatch those, and the 
control started working.
date: Tue, 3 Jun 2008 13:22:00 -0700   author:   paulmooreparks

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us