HOWTO: Invoke the "Add to Favorites" Dialog Box in IE4ID: Q182034
|
The "Add to Favorites" dialog box provides a user interface for the user to
save a Web page as a favorite. The ShellUIHelper::AddFavorite method can be
used to invoke this dialog box from a Visual C++ or Visual Basic
application or from script on a Web page.
Please note that you must install the Internet Client SDK before you can
implement this code in Visual C++.
Also, you must install the desktop update that comes with Internet Explorer
4.0x in order to use the ShellUIHelper object.
The AddFavorite method takes two parameters. The first parameter is the URL
of the Web page to save as a favorite. The second parameter is the title to
be used for this favorite (optional).
When specifying the URL to save as a favorite, you must specify the
protocol type (http://, file://, and so forth) If you do not specify the
protocol, AddFavorite will return E_FAIL (0x80004005) in Visual C++, and a
run-time error in Visual Basic or script.
<SCRIPT LANGUAGE=VBSCRIPT>
window.external.addFavorite "http://www.microsoft.com", "Microsoft"
</SCRIPT>
#include "ExDisp.h"
IShellUIHelper* pShell = NULL;
HRESULT hr = CoCreateInstance(CLSID_ShellUIHelper, NULL, CLSCTX_SERVER,
IID_IShellUIHelper, (void**)&pShell);
if (hr == S_OK)
{
COleVariant vtTitle("Microsoft");
pShell->AddFavorite(OLESTR("http://www.microsoft.com"), &vtTitle);
pShell->Release();
}
NOTE: The \Inetsdk\Include directory must be listed first in the
Directories tab of the settings for the project.
Dim shellHelper As New ShellUIHelper
shellHelper.AddFavorite "http://www.microsoft.com", "Microsoft"
For additional information, please see the following article in the Microsoft Knowledge Base:
Q183339 OC: window.external Supports All Methods of ShellUIHelperFor more information, see the MSDN Online Web Workshop:
http://msdn.microsoft.com/workshop
Additional query words: IShellUIHelper AddFavorite
Keywords : kbIE400 kbIE401 kbIE500
Version : WINDOWS:4.0,4.01,5.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 28, 1999