Click here to Skip to main content
15,860,861 members
Articles / Desktop Programming / WTL

2Find Toolbar for IE - Yet Another Sample

Rate me:
Please Sign up or sign in to vote.
4.94/5 (62 votes)
15 Jun 20039 min read 2M   10.7K   209   1.6K
Google-like Toolbar with customization from xml file and update from web features

Introduction

This working example is based on the Toolbar for IE sample by Rashid Thadha. I tried to incorporate most features that are found in the Google toolbar (and some new ones). It looks much like the Google Bar now and now you can even customize it.

I am planning to list of support bug, features list at toolbar's homepage. Hope there will be more images, FAQs and knowledge bases.

Features

  • The ToolBar is fully customized from a xml file.
  • No resource files are needed.
  • Automatic update of toolbar and all media files.
  • Automatic detection of changed files and download from web-server.
  • Compiles, links and runs under VC.Net
  • Multi-level menu
  • TEXT tag - you can create an icon with a static text!
  • The adding *many* COMBO BOXES
  • PAGE tag - you can insert HTML page into toolbar.
  • .CAB package. I demonstrate how to make an install package.
  • POST request
  • Include additional XML.
  • Combo box has (history and autocomplete features) and you can define several different web engines.
  • Buttons, large buttons (with different size images), separators, drop-down menus with images and hints for items.
  • Tooltips for buttons.
  • Drag-drop into search combo-box.
  • Chevrons.
  • Options, About page.
  • Open local/web URL in a new/old/modal dialog window.
  • Highlight words and an incremental find in a html page (like in the Google toolbar).
  • Uninstall the ToolBar directly from the web browser.
  • Run-time hiding, disabling of buttons, changing combo-box size and other options in options page (see options for details).
  • Change image on mouse entering.
  • Automatically open IE and visualize the toolbar during dll registration.
  • Single / Split / None types for Buttons in the main menu.
  • You can use current URL, domain, toolbar_id and some other in web url and posting data.
  • hot_img attribute in MENU tag - all icons can be changed on the mouse over event.
  • Some commands are replaced with a new SPECIAL command type.
  • The Combo box includes predefined values.
  • You can set/get attributes for the toolbar from javascript with put_NID, put_Pass, get_ver.
  • Uninstall removes ALL Downloaded files.
  • Added xmill support to compress XML files.
  • Added icon into standard toolbar to show/hide your toolbar.
  • Show/Hide toolbar from toolbar's menu.
  • Make a Post request using InternetConnect, HttpOpenRequest and so on functions.
  • TAB key can toogle between combo boxes.
  • Disables mouse wheel into combo-boxes.
  • Hot images can included into multi-level menus.
  • Load xml and other images from resources.
  • Load images from an external dll file.
  • Choice of several different fonts.
  • An update can be "run" from the setup program.
  • You can use simple standard menu (without images).
  • You can check if user changed local files on his computer.
  • Change text colour into blue on over mouse event.
  • Execute an external program.
  • TAB now jump focus from Standart address bar to first combo box, next combo box,.., back to address bar. Shift key also works.
  • Now you can insert not only combo boxes but also edit control. (see line 81 in BandEditCtrl.inl).
Image 1

New Features

  • Script tag - can execute java scripts!
  • Source reorganized a little (as always) I tried to add more comments.
  • You can add text into buttons with bitmaps (not icons)!
  • Added sample Context menu handler in HTML page - select some text and right-click mouse in HTML to call popup menu.
  • Now you can put several fonts in XML file and I'll find first installed on user's computer.
  • Ticker control, comment are welcome.
  • Lot of resource and memory leaks fixed.
  • Show/hide mechanism : added parameter vis_id - now you can hide each button and each MenuItem!!
  • Fixed status bar hints in menus in Split menus with icon.
  • Added encoding for search parameters
  • Added update dll mechanism. see UPDATE_DLL define for details.
  • Added direct parameter to add search in list on options page (addtoselect - set it to "yes").
  • It was 1:00 a.m. and I decided to add small TBInfo struct in this project. look on it - may be you don't know about that technique and you will like it
  • wordfindHint attribute - now you can see hints for "find" auto-generated buttons, too.
  • Added new mechanism to monitoring connection to WWW, not finished yet.
  • Removed Scope attribute from Setting - implemented using CHECKBOX now.

I am sure I forgot about some other features I implemented :( Have a look through source code to find some more... :)

Installation

To install the ToolBar: run "regsvr32.exe %path%\2Find.dll". It will check for the 2find.xml and some other files in the same directory. If they are not present there then it will try to download them from http://zmike.chat.ru/toolbar directory. If it can't be done it will display an "empty" toolbar in IE. In the new version you can open toolbar_sample.html in your IE and installation process will start automatically. Note: you can use WinZip to extract the .dll file from the .cab file.

Building

You have to download and install Microsoft Platform SDK (at least Core SDK). Also check that you installed SP5 for Visual Studio. On NT4 ensure you have installed SP6a.

Add in the first include directory for Platform Sdk (something like "E:\Microsoft Platform SDK\Include" in VC++ -> Tools -> Options -> Directories -> Include files). For example:

Image 2

To help you (if you don't want to download and install Platform SDK), I've put the necessary compressed includes from the Platform SDK here. Use the latest WinRar to extract them:

  1. unpack .rar to some folder
  2. then add it to VC headers directories (at the top of the list)
  3. rebuild project

Don't forget to include the WTL library (7.0). Check out NamesInc.cpp for some important constants.

I tried to help you (if you don't want to download and install Platform SDK) I've put the comppresed includes from Platform SDK here. Use the latest WinRar to extract them:

  1. unpack .rar to some folder
  2. then add it to VC headers directories (at the top of the list)
  3. rebuild project

Don't forget about the WTL library. See NamesInc.cpp for some important constants.

Sample Overview

I'll describe here only the differences and new features that I added/changed. For more details see the Toolbar for IE sample by Rashid Thadha. To Implement the automatic detection of changed files and downloading them from web-server - feature and to prevent changing the toolbar on client side (disabled in this sample). I use the GetCRC function to calculate the CRC of each local file, store it in the registry and if it is changed download the newer file from the web server. In the sample I have disabled this feature: uncomment /*|| oldcrc!=newcrc*/ string to enable it.

You can even make .asp file on your web server and send a .xml file (with settings ) as output of it. Look at these lines:

#ifdef _ECOACH
	if (sstrFile == _bstr_t(L"ecoach.xml"))
		sstrFile = L"ecoach.asp";
#endif

Here is main code to open a new web browser to display and enable the toolbar.

IWebBrowser2 *pIE;
HRESULT hr =  CoCreateInstance(CLSID_InternetExplorer, NULL,
                               CLSCTX_LOCAL_SERVER,
                               IID_IWebBrowser2,(void**)&pIE);
pIE->put_Visible(VARIANT_TRUE);

VARIANT vtBandGUID;
VARIANT vtShow;
VARIANT vtNotUsed;
vtBandGUID.vt = VT_BSTR;
vtBandGUID.bstrVal = SysAllocString( pszBarCLSID );
vtShow.vt = VT_BOOL;
vtShow.boolVal = bShow;
vtNotUsed.vt = VT_INT;
vtNotUsed.intVal = 1;
HRESULT hr = pIE->ShowBrowserBar(&vtBandGUID, &vtShow,
	&vtNotUsed);
SysFreeString(vtBandGUID.bstrVal);

Here is an example of how to register the OnChange event handler in an opened page.

IHTMLElementPtr e3 = NULL;
pHtmlDoc3->getElementById(_bstr_t(m_id.c_str()),&e3);
if (e3)
{
  IHTMLDocument2Ptr pHtmlDoc2 = pHtmlDoc3;

  IHTMLSelectElement *e = NULL;
  HRESULT  hr= e3->QueryInterface( __uuidof( IHTMLSelectElement ),
                                  (void**)&e);
  e3->Release();
  if (e)
  {
   LPDISPATCH dispFO
          = CHtmlEventObject<CBANDTOOLBARCTRL>::CreateHandler(ctrl,
                                CBandToolBarCtrl::OnSelChange, 1);

   VARIANT vIn;
   V_VT(&vIn) = VT_DISPATCH;
   V_DISPATCH(&vIn) = dispFO;
   hr = e->put_onchange( vIn );
  }
 }

And here is the prototype for the handler:

void OnSelChange( DISPID id, VARIANT* pVarResult );

I use these functions to detect if any documents (for example the options page) have been loaded.

BEGIN_SINK_MAP(CPugiObj)
  SINK_ENTRY_EX(0, DIID_DWebBrowserEvents2, DISPID_ONQUIT, OnQuit)
  SINK_ENTRY_EX(0, DIID_DWebBrowserEvents2, DISPID_DOWNLOADCOMPLETE,
                OnDownloadComplete)
END_SINK_MAP()

We can also modify the loaded page and/or add new elements:

IHTMLElementPtr element;
hr = pHtmlDoc2->createElement(_bstr_t(L"OPTION"),&element);
IHTMLOptionElementPtroption = element;
option->put_text(_bstr_t(ctrl->m_toolbar->
                          m_toolbarItems[b]->m_caption.c_str()));
hr = e->add(element,_variant_t(long(-1)));

or change old ones.

IHTMLInputElement *i = NULL;
HRESULT  hr = el->QueryInterface( __uuidof( IHTMLInputElement),
                                  (void**)&i );
if (i)
{
   i->put_checked(VARIANT_TRUE);i->Release();
}

I use this code to load the bitmaps from disk.

CImageList list;
list.CreateFromImage((wchar_t*)filebmp,bSize.cy,0,
                     CLR_DEFAULT,IMAGE_BITMAP,
                     LR_CREATEDIBSECTION|LR_LOADFROMFILE);

And this from the resources:

CImageList ilCool;
ilCool.CreateFromImage(IDB_TOPICONS,16,0, CLR_DEFAULT,IMAGE_BITMAP,
	LR_CREATEDIBSECTION);
m_wndToolBar.SetImageList(ilCool);

And this one to load from another .dll file:

h_image = LoadLibrary(filebmp.c_str());
EnumResourceNames(h_image,RT_BITMAP,EnumResNameProc,0);
CImageList list;
list.Create (bSize.cx,bSize.cy,ILC_COLORDDB|ILC_MASK,0,1);
list.Add(LoadImage(s),clr_format);

Here is the appending owner-draw menu:

handle.AppendMenu(MF_OWNERDRAW,WM_MENU_USER + MAX_MENU_SIZE*id +j,
                  LPCTSTR(pMI));

I added this handler to process the default function; you can find them in Platform SDK.

MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem)
MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem)

Expected multi-level menu !
see <MENU> tag in "Menu" button and virtual void appendMenu(CMenuHandle handle,...) functions

CAB package

I demonstrate how to make an install packgage. Use CabArc.Exe, makecert.exe, exptext.exe, signcode.exe See toolbar_sample.bat and toolbar_sample.html for details.

POST request

See post attribute in WEBJUMP atg and the most interesting getPostData function that uses byteSafeVector class.

Include additional XML.

use INCLUDEXML tag

(<INCLUDEXML>toolbar_sample_ex.xml</INCLUDEXML>)
in XML file

Single / Split / None types for Buttons in the main menu.

type attribute of Menu tag see .XML for details

You can use current URL, domain, toolbar_id and some other in web url and posting data.
%url - current url
%d - domain
%nid - toolbar id
and some others - see sources for details

Some commands are replaced with a new SPECIAL command type. Command types: ClearHistory, Search, Uninstall, Update, Switch to, Make Default Toolbar, Hide toolbar, and others see Special class and SPECIAL tag for details

You can set/get attributes to the toolbar from javascript put_NID, put_Pass, get_ver.
See toolbar_sample.html for details

Uninstall removes ALL Downloaded files.

I store them in HKEY_CURRENT_USER\Software\toolbar_sample\toolbar_sample\Historyfiles
and I delete .dll during Windows restart. I write a value into RunOnce key in registry.

Added xmill support to compress XML files.

I didn't add sources it in this sample but you can easy insert it. see _XmlParserImpl::parse in XmlParserImpl.cpp

Added icon into standard toolbar to show/hide your toolbar.

  CRegKey keyAppID;
  keyAppID.Create(HKEY_LOCAL_MACHINE,
  	_T("SOFTWARE\\Microsoft\\Internet Explorer\\Extensions
\\{C6A4CB5E-ACE2-4256-8864-059BDA996CE7}"));
  _bstr_t ico = getprogpath() + "favicon.ico";
  keyAppID.SetValue("Praize", "ButtonText");
  keyAppID.SetValue("{E0DD6CAB-2D10-11D2-8F1A-0000F87ABD16}", "CLSID");
  keyAppID.SetValue("yes", "Default Visible");
  keyAppID.SetValue(ico, "HotIcon");
  keyAppID.SetValue(ico, "Icon");
  keyAppID.SetValue("Praize", "MenuStatusBar");
  keyAppID.SetValue("&Praize", "MenuText");
  keyAppID.SetValue(bandUUID, "BandCLSID");

PAGE tag - you can insert HTML page into toolbar.

See...

class CPage :
       public IDispEventImpl<1, CPage, &DIID_DWebBrowserEvents2, 
                            &LIBID_SHDocVw, 1, 0>,
       public CWindowImpl<CPage,CAxWindow>

...for details - it is very short.

Hot images into multi-level menu.

I chaged CCommandBarCtrlImpl::DrawItem3D function a little.

Load xml and images from resources.

Find USE_RESOURCE_FILES define.

load images from external dll file.

Find EnumResourceNames(h_image,RT_BITMAP,EnumResNameProc,0); and see details.

Several fonts

You can add several <FONT> tags into XML.

Also:

  • Update can be "run" from setup program Find UPDATE_DLL_FROM_EXE for details.
  • You can use simple standard menu (without images) Find _USE_SIMPLE_MENU fro details.
  • You can check that user changed local files on his computer Find _DONT_CHECK_VERSION_FILE in sources.
  • Make text blue on over mouse event: See CBandToolBarReflectorCtrl::OnItemPrePaint for details.
  • Execute an external program. Execute extern application see for example:
<SHELLEXECUTE name="Send mail"
	command="mailto:mtscf@microsoft.com?subject=Feedback&body=
The%20InetSDK%20Site%20Is%20Superlative"
	not_found="Can't send email"/>

All other features and functions implemented looking in MSDN and codeproject site :-)

Image 3

Auto Complete and Tooltips

Image 4

Chevrons

Image 5

Drag - drop in search combo-box

Image 6

Change Image on Mouse Image Entering, All Buttons as Images

Image 7

XML Schema

You can see xml source here

Image 8

I am using my own XML parser helper to process it.

Options

Note that there are NO scripts in options page. I use events to set/get settings. You can see the HTML text here

Image 9

Adrian Bickle helped me in editing of this article. I am planning to add more details about implementation. But please tell me what items are more interesting for you.

Victor Chiel made a great index of Index of Bugs, fixes, request, isntalation problems

I am planing to support list of bug, features list at toolbar's homepage.
Hope there will be more images, FAQs and knowledge base.
So, you are welcome.

Thank you for your attention.

History

  • v1.0.0 (13 March 2002) Initial release
  • v1.0.4 (22 March 2002) Fixed problems with registration on Win98. Fixed some problems with IE in Offline mode.
  • v1.0.5 (22 November 2002) A lot of features/bugs added/removed. Most important: VC.Net support, multi-level menus.
  • v1.1.0 (1 February 2003) A lot of bugs added/removed.
  • v1.2.0 (29 May 2003) Ticker control, Script command, context handler, some other cosmetic changes.


Image 10

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
Mike has been programming in C/C++ for 11 years and Visual C++/MFC for 4 years. His background includes pure and applied mathematics, engineering and physics, and he is currently based in Moscow, Russia.

Comments and Discussions

 
QuestionToolbar appear after instalation Pin
NightStream12-Dec-11 2:53
NightStream12-Dec-11 2:53 
Generalatlcom.h(3017) : error C2899: typename cannot be used outside a template declaration Pin
ramveers17-Mar-11 0:54
ramveers17-Mar-11 0:54 
Questioncan you give VC7 project? Pin
Victor Y. Sklyar20-Dec-10 11:19
Victor Y. Sklyar20-Dec-10 11:19 
Generalinclude.rar Pin
helianghui8-Jun-10 16:44
helianghui8-Jun-10 16:44 
GeneralRe: include.rar Pin
Mike Melnikov8-Jun-10 19:35
Mike Melnikov8-Jun-10 19:35 
GeneralInclude.rar Pin
Member 324084811-Feb-10 19:13
Member 324084811-Feb-10 19:13 
GeneralRe: Include.rar Pin
forrest.ua12-Feb-10 1:51
forrest.ua12-Feb-10 1:51 
GeneralI make a toobar based on mike's job Pin
horse of zoroo11-Jan-10 21:45
horse of zoroo11-Jan-10 21:45 
QuestionStore Javascript in Source of Toolbar Pin
itsbino14-Sep-09 1:23
itsbino14-Sep-09 1:23 
GeneralNot Finding .........Toolbar for IE sample by Rashid Thadha. Pin
roncooper12-Aug-09 3:40
roncooper12-Aug-09 3:40 
GeneralRe: Not Finding .........Toolbar for IE sample by Rashid Thadha. Pin
Mike Melnikov12-Aug-09 8:56
Mike Melnikov12-Aug-09 8:56 
GeneralImage Source Pin
benjamin silverio11-Aug-09 15:28
benjamin silverio11-Aug-09 15:28 
Questionplease, include.rar?? Pin
cscn20002-Aug-09 20:34
cscn20002-Aug-09 20:34 
GeneralI want the the necessary compressed includes from the Platform SDK [modified] Pin
hnxiaomage7-Feb-09 21:18
hnxiaomage7-Feb-09 21:18 
GeneralWich Languaje Pin
andres.uy19-Nov-08 6:21
andres.uy19-Nov-08 6:21 
Generala good idea Pin
joyjjjz11-Sep-08 21:59
joyjjjz11-Sep-08 21:59 
QuestionHow can I get the Select Text from Internet Explorer Webpage to Search Combo Box using VC++ Pin
Dabara1-Jul-08 18:48
Dabara1-Jul-08 18:48 
Generalnot able to open the homepage Pin
mital_d_vora16-Jun-08 20:02
mital_d_vora16-Jun-08 20:02 
GeneralCrashing tabs in IE7, helping! Pin
Allen Shi4-Jun-08 21:51
Allen Shi4-Jun-08 21:51 
GeneralRe: Crashing tabs in IE7, helping! Pin
Allen Shi29-Jun-08 23:06
Allen Shi29-Jun-08 23:06 
Generalinclude.rar Pin
klint is back29-May-08 0:17
klint is back29-May-08 0:17 
GeneralLicense and home page Pin
blpiko26-May-08 3:44
blpiko26-May-08 3:44 
GeneralGreat Article Pin
Assaf Koren23-Apr-08 21:46
Assaf Koren23-Apr-08 21:46 
GeneralCrashing tabs in IE7 and crashed when close ie6 Pin
Allen Shi22-Apr-08 22:09
Allen Shi22-Apr-08 22:09 
QuestionIs there still no fix for crashing tabs in ie7? Pin
alias110112-Apr-08 14:33
alias110112-Apr-08 14:33 

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.