|

Introduction
This article explains how to add a drop-down menu to a toolbar button of Internet Explorer.
The procedure for adding a standard button to the IE Toolbar is well described at MSDN.
Microsoft provides only one CLSID for the button extension: {1FBA04EE-3024-11d2-8F1F-0000F87ABD16}. So, using this CLSID, we can't add a button different from a standard style, and trying to set a BTNS_DROPDOWN or BTNS_WHOLEDROPDOWN style will be ignored: HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\<Your GUID>
"CLSID"="{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}"
...
Some of the Internet Explorer built-in toolbar buttons (such as "Back" or "Forward"), and some buttons of applications from Microsoft placed on the Internet Explorer toolbar (MS Office, for example), have drop-down functionality.
Unfortunately, MSDN does not provide any documentation regarding the addition of drop-down buttons (the author hasn’t found any information for a long time) for the Internet Explorer toolbar. Probably, such a procedure requires deeper integration with Internet Explorer than the usual registry workaround.
This article solution implements a drop-down behavior of the Internet Explorer toolbar button.
General Steps
Since the IE7 tabbed browsing concept has been released, the Internet Explorer internal window structure has been changed considerably. The following illustration from Spy++ shows the structure of internal windows of Internet Explorer 6 and 7.


The first step is to determine the version of Internet Explorer.
- Detecting the IE version.
The best place for this is the IObjectWithSite::SetSite() method, which will be called during the creation and termination of the object we are implementing here (meaning our test extension). While creating, the site object passed at SetSite() is non-zero, and allows us to get the pointer to the Web browser instance. STDMETHODIMP CMasterObject::SetSite(IUnknown *pUnkSite)
{
if(!pUnkSite)
{
ATLTRACE(_T("SetSite(): pUnkSite is NULL\n"));
}
else
{
HRESULT hRes = S_OK;
CComPtr<IServiceProvider> spSP;
hRes = pUnkSite->QueryInterface(&spSP);
if(SUCCEEDED(hRes) && spSP)
hRes = spSP->QueryService(IID_IWebBrowserApp,
&m_pWebBrowser2);
}
m_spUnkSite = pUnkSite;
m_bIsIe7 = FALSE;
if(pUnkSite)
{
CComPtr<IDispatch> pDocDisp;
CComQIPtr<IHTMLDocument2> pHtmlDoc2;
CComQIPtr<IHTMLWindow2> pWindow;
CComQIPtr<IOmNavigator> pNavigator;
HRESULT hRes = m_pWebBrowser2->get_Document(&pDocDisp);
if(SUCCEEDED(hRes) && pDocDisp)
{
hRes = pDocDisp->QueryInterface(IID_IHTMLDocument2,
(void**)&pHtmlDoc2);
if(SUCCEEDED(hRes) && pHtmlDoc2)
{
hRes = pHtmlDoc2->get_parentWindow(&pWindow);
if(SUCCEEDED(hRes) && pWindow)
{
hRes = pWindow->get_navigator(&pNavigator);
if(SUCCEEDED(hRes) && pNavigator)
{
CComBSTR bstrVersion;
hRes =
pNavigator->get_appVersion(&bstrVersion);
if(SUCCEEDED(hRes))
{
CHAR szVersion[MAX_PATH];
memset(szVersion,0,MAX_PATH);
WideCharToMultiByte(CP_ACP, 0,
bstrVersion.m_str,
-1, szVersion,
MAX_PATH, NULL, NULL);
if(strstr(szVersion, "MSIE 7.") != 0)
m_bIsIe7 = TRUE;
}
}
}
}
}
}
return S_OK;
}
- Finding a handle of the Web browser window.
This handle is required for the TrackPopupMenu function that we should use later. We can obtain it very easily for versions 5 and 6: long nBrowser = 0;
m_pWebBrowser2->get_HWND(&nBrowser);
HWND hWndParent = (HWND)nBrowser;
...
But since beta1 of version 7, we have to find the active tab first and the corresponding browser window next:

HWND hWnd = GetWindow(hWndParent, GW_CHILD);
...
if(hWnd)
{
TCHAR szClassName[MAX_PATH];
while(hWnd)
{
memset(szClassName,0,MAX_PATH);
GetClassName(hWnd, szClassName, MAX_PATH);
if(_tcscmp(szClassName,_T("TabWindowClass"))==0)
{
if(IsWindowVisible(hWnd))
{
hWnd = GetWindow(hWnd, GW_CHILD);
while(hWnd)
{
memset(szClassName,0,MAX_PATH);
GetClassName(hWnd, szClassName, MAX_PATH);
if(_tcscmp(szClassName,_T("Shell DocObject View"))==0)
{
hWnd = FindWindowEx(hWnd, NULL,
_T("Internet Explorer_Server"), NULL);
if(hWnd) hWndIe7ActiveTab = hWnd;
break;
}
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
}
}
}
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
}
}
if(hWndIe7ActiveTab) hWndMenuParent = hWndIe7ActiveTab;
Probably, when IE7 will be fully released, Microsoft will present a new IWebBrowser interface, and we can then determine which tab is active at the moment. But, currently, MSDN does not provide any such function. So, we have to enumerate all internal "TabWindowClass" windows and assume that the active tab should be visible.
- Finding a handle of the IE Toolbar window.
We can obtain it very easily for all IE versions as shown below: hWndToolBar = WindowFromPoint(pt);
- Finding the button on-screen position.
In this step, we should determine if the button was clicked by the mouse or selected from the chevron’s menu.

And, if the button was clicked, we should calculate the button’s rectangle for correct menu positioning: int nIDCommand = -1;
BOOL bRightAlign = FALSE;
if(hWndToolBar)
{
ScreenToClient(hWndToolBar,&pt);
int nButton = (int)::SendMessage(hWndToolBar,
TB_HITTEST, 0, (LPARAM)&pt);
if(nButton>0)
{
TBBUTTON pTBBtn;
memset(&pTBBtn,0,sizeof(TBBUTTON));
if(::SendMessage(hWndToolBar, TB_GETBUTTON,
nButton, (LPARAM)&pTBBtn))
{
nIDCommand = pTBBtn.idCommand;
RECT rcButton;
if(::SendMessage(hWndToolBar,TB_GETRECT,nIDCommand,
(LPARAM)&rcButton))
{
pt.x = rcButton.left;
pt.y = rcButton.bottom;
ClientToScreen(hWndToolBar,&pt);
RECT rcWorkArea;
SystemParametersInfo(SPI_GETWORKAREA,0,
(LPVOID)&rcWorkArea,0);
if(rcWorkArea.right-pt.x<150)
{
bRightAlign = TRUE;
pt.x = rcButton.right;
pt.y = rcButton.bottom;
ClientToScreen(hWndToolBar,&pt);
}
}
}
}
else
{
GetCursorPos(&pt);
bIsChevron = TRUE;
}
}
- The last step. Display the button as pushed, and pop up the menu.
if(nIDCommand!=-1 && !bIsChevron)
::SendMessage(hWndToolBar, TB_PRESSBUTTON,
nIDCommand, MAKELPARAM(1,0));
int nCommand = TrackPopupMenu(hMenuTrackPopup, nFlags,
pt.x, pt.y, 0, hWndMenuParent, 0);
if(nIDCommand!=-1 && !bIsChevron)
::SendMessage(hWndToolBar, TB_PRESSBUTTON,
nIDCommand, MAKELPARAM(0,0));
switch (nCommand)
{
case ID_ITEM1:
...
This example does not create a natural drop-down button (missing a drop-down arrow, or a separate section), but can be used as a simple and quick solution to extend the functionality of a simple IE Toolbar button.
Anyway, I hope others find this code useful. Please feel free to report errors, issues, or requests.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh) | FirstPrevNext |
|
|
 |
|
|
It is very good ,but I want to get the details. Maybe,you can teach me step by step in a project with vs2008. Thanks very much. could you give me a e-mail to gg8_8@yahoo.com.cn? Waiting for you.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
First of all accept my regards for this article.
I am new to IE7 development and would like to know some initial steps, as, what project type of VS2005 you used? can you please specify some points to setup a simple development environment?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hey Friends
Did anybody got a way to add DropDown to the Internet Explorer button?
If not Try out this
Install SkyPe
Note that SkyPe button on IE has dropdown
Go to Registry & change the text of the button added by SKyPe
Now again have a look at the button added by skype
does it shows dropdown?
May be it would help in solving the DropDown Mystery  Regards
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
Guys, i need it urgentlly, wana know how to do the same task on MS outlook 2002/03. By using _IDTExtensibility2.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello sir, its very excellent article...even i used for myself n i m impressed... but i want the same code in c#
Dynamically, I want to change image displayed on commandButton without restarting IE. This can be done bt changing image in registry but it needs IE to be restarted, which is not my requirement. As i m working in c#.net,ur VC++ code cant help me... i am facing problems to get handle of toolbar items. 
Any help in C# will be great please reply me on ciennie@hotmail.com
-- modified at 4:34 Monday 23rd July, 2007
Lead a few, Follow one..... Love all, hate none...
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Hi,
I am facing problem adding a tool tip to a submenu item. Can any body tell me how can we add atool tip to submenu.
Regards Sumeet
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi When i tried registering this DLL in a machine where VS is not installed.It failed in registering the DLL. Says "Load library failed. This application has failed to start because the application configuration s incorrect.Reinstalling the application may fix the problem"
Help will be appreciated.
sumeet
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
i got it...its because we have to register atl80.dll.If its not getting registered then we have to set minsize od mindependency from Project settings of Solution.
|
| Sign In·View Thread·PermaLink | 3.00/5 (2 votes) |
|
|
|
 |
|
|
Could someone tell me how to add dropdown arrow to this IE7 button? I'm new to this plugin world.
thanks
Neela
Neela
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Hi- I'm new at these Internet Explorer buttons. I understand you have to generate a GUID for the registry. Does this guid have to be anywhere in the program or have anything to do with the program. For example do the GUIDs in TestExtension_i.c have anything to do with that GUID? Also can anyone point to an example where when I click on one of the items in the pull down it lets me do something to the html in the page, for example highlight some text or something?
Thanks
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Very thankful to you to write such nice article. But i want to do the same thing in C#.NET. Please if some body know how to convert it into C# then mail me at: rizwan_nuces@yahoo.com cheers Rizwan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
This was the document which i was waiting for long... I loved to see such a code which do the things i needed soo fast... I have few questions though... Can I use it for my works? or any copyright?? lol what will be the work involved in making a arrow as other dropdown menus in IE. Also when the test extension is in Chevron, and if we select the test extension menu, Chevron just disappears when ussual dropdown menus don't.
Any way this one I love like any thing I will make it as bookmark.... 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I too would like to know how to keep the chevron window from closing immediately when the button is clicked. Ideas are appreciated.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
You might know the answer to this...IE7 has the context menu that has a "Open in New Tab". I am creating a Browser Helper Object and for IE6, you had to load Shdoclc.dll to add items to the context menu...only it doesn't have "Open in New Tab". How could I find where it lives, to load the appropriate DLL, or how can I get it to be displayed?
Thanks, Murph
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I'm developing Internet Explorer plug-in. And I need to use natural drop-down button (with drop-down arrow such as "Back","Forward",MS Word) with menu and button features. I drew separator and arrow on right side of the button. When users clics to left side of the button program handles a button click. When users clics to right side of the button it means that menu has chosen. Unfortunately this is no natural drop-down menu, but it too similar. If anybody knows how to create a natural drop-down menu write me please.
Edward
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
I'm developing Internet Explorer plug-in. And I need to use natural drop-down button (with drop-down arrow such as "Back","Forward",MS Word) with menu and button features. I drew separator and arrow on right side of the button. When users clics to left side of the button program handles a button click. When users clics to right side of the button it means that menu has chosen. Unfortunately this is no natural drop-down menu, but it too similar. If anybody knows how to create a natural drop-down menu write me please.
Edward
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks so f***ing much mate! I was trying to discover why I can't see my BHO menu using IE7 and it was driving me crazy
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Wow, this article is exactly what I have been looking for. Thank you very much for the info. Great Article!
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Could someone tell me how to add dropdown arrow to this IE7 button? I'm new to this plugin world.
thanks
Neela
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|