Click here to Skip to main content
15,921,884 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: why can't I print an icon? Pin
Mark Salsbery11-Jul-08 6:34
Mark Salsbery11-Jul-08 6:34 
GeneralRe: why can't I print an icon? Pin
Bram van Kampen12-Jul-08 16:25
Bram van Kampen12-Jul-08 16:25 
GeneralRe: why can't I print an icon? Pin
tataxin13-Jul-08 14:43
tataxin13-Jul-08 14:43 
GeneralRe: why can't I print an icon? Pin
Bram van Kampen15-Jul-08 14:47
Bram van Kampen15-Jul-08 14:47 
QuestionUsing getenv Pin
rocktx10-Jul-08 8:17
rocktx10-Jul-08 8:17 
AnswerRe: Using getenv Pin
David Crow10-Jul-08 8:43
David Crow10-Jul-08 8:43 
GeneralRe: Using getenv [modified] Pin
Bram van Kampen12-Jul-08 16:42
Bram van Kampen12-Jul-08 16:42 
Questionget_anchors doesn't return all anchors Pin
Mohammad Tarik10-Jul-08 7:30
Mohammad Tarik10-Jul-08 7:30 
Hello,

I am trying to get all links on an web page. Unfortunately, the "get_anchors" doesn't seem to retrieve all anchor elements. I have pages full of links and all I get are few or none.

I'm using Visual C++ 2003. I have an MFC Dialog application with embedded webbrowser control.

Here's my code: (btw, GetDocument function calls IWebBrowser::get_Document() function and it works fine with things other than getting anchors).

HRESULT hr;
IHTMLDocument2 * pHtmlDoc = GetDocument();
CStringArray sURLArray;

if (pHtmlDoc != NULL)
{
    IHTMLElementCollection * pColl = NULL;
    hr = pHtmlDoc->get_anchors(&pColl);

    if(SUCCEEDED(hr))
    {
        LONG nElem = 0;
        hr = pColl->get_length(&nElem);

        if(SUCCEEDED(hr))
        {
            for(long i = 0; i < nElem; i++)
            {
                _variant_t vIndex(i);

                IDispatch * pDisp2 = NULL;
                hr = pColl->item(vIndex, vIndex, &pDisp2);
                if(SUCCEEDED(hr))
                {
                    IHTMLAnchorElement * pAnchElem = NULL;
                    hr = pDisp2->QueryInterface(IID_IHTMLAnchorElement, (void**) &pAnchElem);
                    if(SUCCEEDED(hr))
                    {
                        BSTR bstrHref;
                        if(SUCCEEDED(pAnchElem->get_href(&bstrHref)))
                        {
                            CString strLink(bstrHref);
                            if(!strLink.IsEmpty())
                                sURLArray.Add(strLink);
                            SysFreeString(bstrHref);
                        }
                        pAnchElem->Release();
                    }
                    pDisp2->Release();
                }
                MessageBox(sURLArray.GetAt(i));
            }
        }
        pColl->Release();
    }
    pHtmlDoc->Release();
}

Taking a look now at the code. I think that I should have used if(FAILED(...)) return; instead of if(SUCCEEDED(...)) .. it would have been more readable without all these brackets.

Any help is appreciated

Thanks
QuestionRe: get_anchors doesn't return all anchors Pin
David Crow10-Jul-08 7:32
David Crow10-Jul-08 7:32 
AnswerRe: get_anchors doesn't return all anchors Pin
Mohammad Tarik10-Jul-08 7:35
Mohammad Tarik10-Jul-08 7:35 
QuestionRe: get_anchors doesn't return all anchors Pin
David Crow10-Jul-08 7:45
David Crow10-Jul-08 7:45 
AnswerRe: get_anchors doesn't return all anchors Pin
Mohammad Tarik10-Jul-08 7:58
Mohammad Tarik10-Jul-08 7:58 
QuestionRe: get_anchors doesn't return all anchors Pin
David Crow10-Jul-08 8:16
David Crow10-Jul-08 8:16 
AnswerRe: get_anchors doesn't return all anchors Pin
Mohammad Tarik10-Jul-08 8:37
Mohammad Tarik10-Jul-08 8:37 
GeneralRe: get_anchors doesn't return all anchors Pin
David Crow10-Jul-08 8:41
David Crow10-Jul-08 8:41 
GeneralRe: get_anchors doesn't return all anchors Pin
Mohammad Tarik10-Jul-08 8:51
Mohammad Tarik10-Jul-08 8:51 
GeneralRe: get_anchors doesn't return all anchors Pin
Mohammad Tarik10-Jul-08 9:20
Mohammad Tarik10-Jul-08 9:20 
QuestionRe: get_anchors doesn't return all anchors Pin
David Crow10-Jul-08 10:16
David Crow10-Jul-08 10:16 
AnswerRe: get_anchors doesn't return all anchors Pin
Mohammad Tarik10-Jul-08 11:04
Mohammad Tarik10-Jul-08 11:04 
QuestionDisk Info Pin
Fedrer10-Jul-08 7:09
Fedrer10-Jul-08 7:09 
AnswerRe: Disk Info Pin
David Crow10-Jul-08 7:35
David Crow10-Jul-08 7:35 
QuestionHow do I load asociated file in application from windows explorer???? Pin
AlmodJ10-Jul-08 5:48
AlmodJ10-Jul-08 5:48 
AnswerRe: How do I load asociated file in application from windows explorer???? Pin
Rajesh R Subramanian10-Jul-08 6:07
professionalRajesh R Subramanian10-Jul-08 6:07 
AnswerRe: How do I load asociated file in application from windows explorer???? Pin
AlmodJ10-Jul-08 7:18
AlmodJ10-Jul-08 7:18 
GeneralRe: How do I load asociated file in application from windows explorer???? Pin
Mark Salsbery10-Jul-08 7:27
Mark Salsbery10-Jul-08 7:27 

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.