CWebView::GetDocumentTitle Method  
 
INT GetDocumentTitle(
  LPTSTR lpszTitle,  
  INT nMaxLength,  
);

The GetDocumentTitle method returns the document title.

Parameters

lpszTitle
A string buffer which will contain the current document title when the method returns. If this parameter is NULL, the method will not copy anything into the buffer but will return the length of the title, not including the terminating null character.
nMaxLength
An integer which specifies the maximum number of characters which can be copied into the string buffer, including the terminating null. If the lpszTitle parameter is NULL this value should be zero.

Return Value

If the method succeeds, the return value is the length of the document title in characters, not including the terminating null. If the document does not have a title or the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The GetDocumentTitle method returns the current title of the document loaded in the browser. This corresponds to the contents of the <title> element in the document's <head> section, if one is defined.

The title is not fixed at the time the page is first loaded. A script running in the document can modify the <title> element dynamically, and some web applications use this technique to reflect state changes (for example, to indicate new messages or status updates). Because of this, the value returned by this method may change over the lifetime of the page. If the document does not explicitly define a title, the method may return an empty string. Applications that display document titles should be prepared to handle this case.

If the browser window was created using Create without a specific title, the application title will be automatically changed to reflect the current document title. This does not happen if the browser window is attached to an existing window or if an application title was specified when the window was created. If you wish to manually update a top-level window title with the current document title, call this method in response to a WEBVIEW_EVENT_NAVIGATION_COMPLETED event and then call the SetWindowText function to change the text in the window's title bar.

If the current document does not have a title, this method will return zero and the last error code will be set to NO_ERROR. If the lpszTitle parameter is not NULL, it will be set to an empty string when the method returns. This is not uncommon if the SetDocumentText method is called to change the current document and the text does not contain HTML markup or does not include a <title> tag.

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