HOWTO: Invoke the "Add to Favorites" Dialog Box in IE4

Last reviewed: March 5, 1998
Article ID: Q182034
The information in this article applies to:
  • Internet Client SDK, version 4.0
  • Microsoft Internet Explorer (Programming), versions 4.0, 4.01

SUMMARY

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++.

MORE INFORMATION

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.

Scripting

   <OBJECT ID="ShellUIHelper" WIDTH=0 HEIGHT=0
      CLASSID="CLSID:64AB4BB7-111E-11d1-8F79-00C04FC2FBE1">
   </OBJECT>

   <SCRIPT LANGUAGE=VBSCRIPT>
      ShellUIHelper.AddFavorite "http://www.microsoft.com", "Microsoft"
   </SCRIPT>

Visual C++

To invoke the "Add to Favorites" dialog box from a Visual C++ application that is hosting the WebBrowser control, insert the following code in your application:

   #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.

Visual Basic

To invoke this dialog box in a Visual Basic application, add a reference to Shdocvw.dll to your project if your application is not hosting the WebBrowser control:

   Dim shellHelper As New ShellUIHelper
   shellHelper.AddFavorite "http://www.microsoft.com", "Microsoft"

REFERENCES

Internet Client SDK Help:

   http://www.microsoft.com/msdn/sdk/inetsdk/help/

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Scott Roberts, Microsoft Corporation


Additional query words: IShellUIHelper AddFavorite
Technology : kbInetDev
Version : WINDOWS:4.0,4.01
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.