Click here to Skip to main content
15,891,184 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSimple http command prompt client Pin
conrad107812-Feb-06 16:05
conrad107812-Feb-06 16:05 
AnswerRe: Simple http command prompt client Pin
Ryan Binns2-Feb-06 17:24
Ryan Binns2-Feb-06 17:24 
QuestionHow to load a url or a html document? Pin
shertay2-Feb-06 15:21
shertay2-Feb-06 15:21 
AnswerRe: How to load a url or a html document? Pin
EXTEIDE2-Feb-06 15:47
EXTEIDE2-Feb-06 15:47 
GeneralRe: How to load a url or a html document? Pin
shertay2-Feb-06 15:54
shertay2-Feb-06 15:54 
GeneralRe: How to load a url or a html document? Pin
EXTEIDE2-Feb-06 16:22
EXTEIDE2-Feb-06 16:22 
GeneralRe: How to load a url or a html document? Pin
shertay2-Feb-06 21:29
shertay2-Feb-06 21:29 
AnswerRe: How to load a url or a html document? Pin
Stephen Hewitt3-Feb-06 1:31
Stephen Hewitt3-Feb-06 1:31 
Try this. It uses ATL. It extracts the text from google and prints it in a message box. I wipped it up pretty quickly so it's not perfect, but it works.
---

// Only needed if you're using an old SDK that hasn't got this. Remove
// if it clashes with your SDK.
MIDL_INTERFACE("3050f613-98b5-11cf-bb82-00aa00bdce0b")
HTMLDocumentEvents2 : public IDispatch
{
};

// Class to wait for the ready state to change to "complete"
// while running a message loop.
class ATL_NO_VTABLE CReadyStateComplete :
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatch
{
public:
CReadyStateComplete() : m_spDoc2(NULL)
{
m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
}

~CReadyStateComplete()
{
CloseHandle(m_hEvent);
}

void SetDocument(IHTMLDocument2* pDoc2)
{
m_spDoc2 = pDoc2;
}

DECLARE_NO_REGISTRY()

BEGIN_COM_MAP(CReadyStateComplete)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

void Wait()
{
AtlWaitWithMessageLoop(m_hEvent);
}

public:
STDMETHOD(GetTypeInfoCount)(UINT* pctinfo)
{
return E_NOTIMPL;
}

STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
{
return E_NOTIMPL;
}

STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
LCID lcid, DISPID* rgdispid)
{
return E_NOTIMPL;
}

STDMETHOD(Invoke)(
/*[in]*/ DISPID dispIdMember,
/*[in]*/ REFIID riid,
/*[in]*/ LCID lcid,
/*[in]*/ WORD wFlags,
/*[in, out]*/ DISPPARAMS * pDispParams,
/*[out]*/ VARIANT * pVarResult,
/*[out]*/ EXCEPINFO * pExcepInfo,
/*[out]*/ UINT * puArgErr)
{
if ( dispIdMember == DISPID_READYSTATECHANGE )
{
CComBSTR State;
if ( SUCCEEDED(m_spDoc2->get_readyState(&State)) )
{
if ( wcscmp(State, L"complete")==0 )
{
SetEvent(m_hEvent);
}
}

return S_OK;
}

return DISP_E_MEMBERNOTFOUND;
}

private:
CComPtr<IHTMLDocument2> m_spDoc2;
HANDLE m_hEvent;
};

void ExtractText()
{
HRESULT hr;

// Get a stream on the URL.
CComPtr<IMoniker> spMk;
hr = CreateURLMoniker(NULL, OLESTR("http://www.google.com/"), &spMk);
if ( FAILED(hr) )
{
return;
}
CComPtr<IBindCtx> spCtx;
hr = CreateBindCtx(0, &spCtx);
if ( FAILED(hr) )
{
return;
}
CComPtr<IStream> spStream;
hr = spMk->BindToStorage(spCtx, 0, IID_IStream, (void**)&spStream);
if ( FAILED(hr) )
{
return;
}

// Create the HTMLDocument object.
CComPtr<IUnknown> spUnk;
hr = spUnk.CoCreateInstance(CLSID_HTMLDocument);
if ( FAILED(hr) )
{
return;
}
CComQIPtr<IPersistStreamInit> spPSI(spUnk);
if ( !spPSI )
{
return;
}
CComQIPtr<IHTMLDocument2> spDoc2(spUnk);
if ( !spDoc2 )
{
return;
}

// Set up our object which watches the ready state of the document.
CComObjectGlobal<CReadyStateComplete> RS;
RS.SetDocument(spDoc2);
DWORD Cookie;
hr = AtlAdvise(spUnk, &RS, __uuidof(HTMLDocumentEvents2), &Cookie);
if ( FAILED(hr) )
{
return;
}

// Load the data from the URL into the object.
hr = spPSI->Load(spStream);
if ( FAILED(hr) )
{
AtlUnadvise(spUnk, __uuidof(HTMLDocumentEvents2), Cookie);
return;
}

// Wait (while running a message pump so MSHTML can work) till ready.
RS.Wait();
AtlUnadvise(spUnk, __uuidof(HTMLDocumentEvents2), Cookie);

// Print out the text in a message box.
CComPtr<IHTMLElement> spBodyElement;
hr = spDoc2->get_body(&spBodyElement);
if ( FAILED(hr) )
{
return;
}
CComBSTR Text;
hr = spBodyElement->get_outerText(&Text);
if ( FAILED(hr) )
{
return;
}
MessageBoxW(NULL, Text, L"Text", MB_OK);
}


Steve

-- modified at 7:41 Friday 3rd February, 2006

Added AtlUnadvise calls without testing......

QuestionEXE file Pin
greendays_012-Feb-06 14:30
greendays_012-Feb-06 14:30 
AnswerRe: EXE file Pin
EXTEIDE2-Feb-06 14:42
EXTEIDE2-Feb-06 14:42 
AnswerRe: EXE file Pin
Gary R. Wheeler2-Feb-06 14:43
Gary R. Wheeler2-Feb-06 14:43 
AnswerRe: EXE file Pin
greendays_012-Feb-06 16:05
greendays_012-Feb-06 16:05 
QuestionStoring Password in Outlook Express using "RegSetValueEx" Pin
amano8u2-Feb-06 13:48
amano8u2-Feb-06 13:48 
AnswerRe: Storing Password in Outlook Express using "RegSetValueEx" Pin
Stephen Hewitt2-Feb-06 14:00
Stephen Hewitt2-Feb-06 14:00 
GeneralRe: Storing Password in Outlook Express using "RegSetValueEx" Pin
amano8u2-Feb-06 14:03
amano8u2-Feb-06 14:03 
GeneralRe: Storing Password in Outlook Express using &quot;RegSetValueEx&quot; Pin
Stephen Hewitt2-Feb-06 14:09
Stephen Hewitt2-Feb-06 14:09 
GeneralRe: Storing Password in Outlook Express using &quot;RegSetValueEx&quot; Pin
amano8u2-Feb-06 14:16
amano8u2-Feb-06 14:16 
GeneralRe: Storing Password in Outlook Express using &quot;RegSetValueEx&quot; Pin
Stephen Hewitt2-Feb-06 14:20
Stephen Hewitt2-Feb-06 14:20 
GeneralRe: Storing Password in Outlook Express using &quot;RegSetValueEx&quot; Pin
amano8u2-Feb-06 16:10
amano8u2-Feb-06 16:10 
GeneralRe: Storing Password in Outlook Express using "RegSetValueEx" Pin
ThatsAlok2-Feb-06 18:10
ThatsAlok2-Feb-06 18:10 
GeneralRe: Storing Password in Outlook Express using "RegSetValueEx" Pin
amano8u2-Feb-06 18:47
amano8u2-Feb-06 18:47 
AnswerRe: Storing Password in Outlook Express using "RegSetValueEx" Pin
Ryan Binns2-Feb-06 17:27
Ryan Binns2-Feb-06 17:27 
GeneralRe: Storing Password in Outlook Express using "RegSetValueEx" Pin
amano8u2-Feb-06 17:33
amano8u2-Feb-06 17:33 
QuestionHow to program use MFC to control two monitors Pin
dli_9802-Feb-06 13:12
dli_9802-Feb-06 13:12 
AnswerRe: How to program use MFC to control two monitors Pin
EXTEIDE2-Feb-06 14:51
EXTEIDE2-Feb-06 14:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.