The WebBrowser Control gives you control over what it downloads,
displays, and executes. To gain this control, you need to implement
your host's IDispatch so it handles DISPID_AMBIENT_DLCONTROL.
When the WebBrowser Control is instantiated, it will call your
IDispatch::Invoke with this ID. Set pvarResult to a combination
of following flags, using the bitwise OR operator, to indicate
your preferences.
STDMETHODIMP CAtlBrCon::Invoke(DISPID dispidMember, REFIID riid,
LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams,
VARIANT* pvarResult,
EXCEPINFO* pExcepInfo,
UINT* puArgErr)
{
switch (dispidMember)
{
case DISPID_AMBIENT_DLCONTROL:
pvarResult->vt = VT_I4;
pvarResult->lVal = DLCTL_DLIMAGES | DLCTL_VIDEOS | DLCTL_NO_SCRIPTS;
break;
default:
return DISP_E_MEMBERNOTFOUND;
}
return S_OK;
}
как вышесказанное МСДН'ом добавить в ниже приведённую прогу
(я новичок, просто этот пример поможет разобраться с основным)
СПАСИБО!!
int main( int argc, char ** argv )
{
printf( "I started!\n" );
IWebBrowser2* m_pBrowser;
HRESULT hr ;
BSTR m_string=NULL;
CoInitialize(NULL);
hr = CoCreateInstance (CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER,IID_IWebBrowser2, (LPVOID *)&m_pBrowser);
if(hr!=S_OK) {
m_pBrowser=NULL;
}
VARIANT_BOOL bOffline = true;
m_pBrowser->put_Offline( bOffline );
IOleControl * pOleControl;
hr = m_pBrowser->QueryInterface( __uuidof( IOleControl ), (void**)&pOleControl );
if ( SUCCEEDED( hr ) ) {
pOleControl->OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL);
pOleControl->Release();
}
char * url = "http://host/";
_variant_t v_url;
_variant_t null;
v_url.SetString( url );
hr = m_pBrowser->Navigate2( &v_url, &null, &null, &null, &null );
BOOL bReady=FALSE;
while(bReady==FALSE) {
READYSTATE state;
m_pBrowser->get_ReadyState(&state);
if(state==READYSTATE_COMPLETE) {
VARIANT_BOOL b;
m_pBrowser->get_Busy(&
;
if (b==VARIANT_FALSE)
bReady=TRUE;
else {
printf( "Sleeping inner ELSE\n" );
Sleep(1000);
}
}
else {
printf( "Sleeping outer ELSE\n" );
Sleep(1000);
}
}
IDispatch* pmDisp;
IDispatch* ret_pDisp=NULL;
hr = m_pBrowser->get_Document(&pmDisp);
if (pmDisp == NULL )
printf( "Error while m_pBrowser->get_Document(&pmDisp)\n" );
IHTMLDocument2* pHTMLDocument2;
hr = pmDisp->QueryInterface( IID_IHTMLDocument2,(void**)&pHTMLDocument2 );
if (hr != S_OK)
return NULL;
IHTMLElement * p;
hr = pHTMLDocument2->get_body(&p);
if (hr != S_OK)
return NULL;
BSTR astr;
hr = p->get_innerHTML(&astr);
wprintf( L"result=\"%s\"\n", astr );
pHTMLDocument2->Release();
pmDisp->Release();
m_pBrowser->Release();
printf( "I stoped!\n" );
return 0;
}