CWebView::GetDocumentLength Method  
 
INT GetDocumentLength();

The GetDocumentText method returns the current document length.

Parameters

None.

Return Value

If the method succeeds, the return value is the length of the document text in characters. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The GetDocumentLength method returns the number of characters in the current document. This will reflect the state of the document at the time the method is called. If the page has been dynamically modified by scripts after it was initially loaded, those changes will be included. Note that if your project is configured to use Unicode, this value will not be the same as the size of the document in bytes.

This method should only be called after navigation has completed. If called while a page is still loading, the contents of the page may be incomplete or empty. The length of the document includes the HTML markup and inline scripting.

If a blank page is currently being displayed, such as when navigating to about:blank or by setting the current document text to an empty string, this method can still return a value. Internally, the browser creates a blank page using the markup "<html><head></head><body></body></html>" and this method will return the length of that content.

The GetFilteredText method can be used to obtain a filtered version of the text with the HTML markup removed.

Example

INT nLength = pWebView->GetDocumentLength();
if (nLength > 0)
{
    LPTSTR pszBuffer = (LPTSTR)malloc((nLength + 1) * sizeof(TCHAR));
    if (!pszBuffer)
    {
        // Virtual memory exhausted
        return;
    }

    nLength = pWebView->GetDocumentText(pszBuffer, nLength + 1);
    if (nLength > 0)
    {
         // Write the document HTML to standard output
        _putts(pszBuffer);
        _puttc(_T('\n'), stdout);
    }

    free(pszBuffer);
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also