Click here to Skip to main content
Click here to Skip to main content

IE Drop-Down Button

By , 8 Nov 2007
 
Screenshot - samples.jpg

Introduction

This sampls how to add a drop-down arrow button of Internet Explorer.

regsvr32 debug/dropbutton.dll

Using the code


LRESULT CIEToolbarWnd::OnCheckButton(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (m_isIE7)
{
return DefWindowProc(uMsg, wParam, lParam);
}

if (m_ParentWnd.GetButtonID() == (int)wParam)
{
BrowserWndInfo *pInfo = m_ParentWnd.GetBrowserWndInfo();

if (pInfo != NULL)
{
if (pInfo->nButtonState == TBSTATE_CHECKED)
{
lParam = MAKELONG(TRUE, 0);
}
else
{
lParam = MAKELONG(FALSE, 0);
}
}
}
}

LRESULT CIEToolbarWnd::OnAddString(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
LRESULT lResult = DefWindowProc(uMsg, wParam, lParam);

if (m_isIE7)
{
return lResult;
}

if ((int)wParam == 0)
{
LPWSTR strButtonText = (LPWSTR)lParam;
if (_tcscmp(BUTTON_NAME, strButtonText) == 0)
{
m_buttonStrIndex = lResult;
}
}
return lResult;
}


LRESULT CIEToolbarWnd::OnAddButton(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
LRESULT lResult = DefWindowProc(uMsg, wParam, lParam);

if (m_isIE7)
{
return lResult;
}

int nButtons = (int)wParam;
LPTBBUTTON pButtons = (LPTBBUTTON)lParam;
for (int i = 0; i < nButtons; i++)
{
if (pButtons[i].iString == m_buttonStrIndex)
{
m_ParentWnd.SetButtonID(pButtons[i].idCommand);

m_ParentWnd.NotifySetButtonInfo(pButtons[i].idCommand);
}
}
return lResult;
}

LRESULT CIEToolbarWnd::OnSetButtonInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
int iID = (int) wParam;
LPTBBUTTONINFO lptbbi = (LPTBBUTTONINFO)lParam;

int ButtonID = m_ParentWnd.GetButtonID();
if (ButtonID == -1)
{
if (lptbbi->pszText != NULL && wcscmp(lptbbi->pszText, L"DropButton") == 0)
{
ButtonID = iID;
m_ParentWnd.SetButtonID(ButtonID);
}
}
if (ButtonID == iID)
{
lptbbi->dwMask = lptbbi->dwMask | TBIF_STYLE | TBSTYLE_CHECK| TBIF_STATE;
lptbbi->fsStyle = lptbbi->fsStyle|BTNS_DROPDOWN |BTNS_CHECK;
BrowserWndInfo* pInfo = m_ParentWnd.GetBrowserWndInfo();
if (pInfo != NULL && pInfo->nButtonState == TBSTATE_CHECKED)
{
lptbbi->dwMask = lptbbi->dwMask | TBIF_STYLE | TBSTYLE_CHECK| TBIF_STATE;
lptbbi->fsStyle = lptbbi->fsStyle|BTNS_DROPDOWN |BTNS_CHECK;
lptbbi->fsState = TBSTATE_ENABLED|TBSTATE_CHECKED;
}
else
{
lptbbi->dwMask = lptbbi->dwMask | TBIF_STYLE | TBSTYLE_CHECK| TBIF_STATE;
lptbbi->fsStyle = lptbbi->fsStyle|BTNS_DROPDOWN |BTNS_CHECK;
lptbbi->fsState = TBSTATE_ENABLED;
}
}
return DefWindowProc(uMsg, wParam, lParam);
}

void CIEToolbarWnd::SubclassToolbar(IWebBrowser2 *pWB)
{
if (pWB == NULL)
{
return;
}

long hWnd = NULL;
pWB->get_HWND(&hWnd);

int nViewCount = m_arrayBrowserWndInfo.GetSize();

BrowserWndInfo *pBrowserWndInfo = new BrowserWndInfo;

if (pBrowserWndInfo == NULL)
{
return;
}
pBrowserWndInfo->pWebBrowser = pWB;
pBrowserWndInfo->nButtonState = 0;
pBrowserWndInfo->hBrowserWnd = (HWND)hWnd;
m_arrayBrowserWndInfo.Add(pBrowserWndInfo);

if (m_ParentWnd.GetBrowserWndInfo() == NULL)
{
m_ParentWnd.SetBrowserWndInfo(pBrowserWndInfo);
}

if (nViewCount > 0)
{
return;
}

HWND hToolbarWnd = NULL;

if (m_isIE7)
{
ie7SubclassToolbar((HWND)hWnd);
}
else
{
normalSubclassToolbar((HWND)hWnd);
}
}

void CIEToolbarWnd::UnsubclassToolbar(IWebBrowser2 *pWebBrowser)
{
BrowserWndInfo* pBrowseWndInfo = findBrowserWndInfo(pWebBrowser);

if (pBrowseWndInfo != NULL)
{
m_arrayBrowserWndInfo.Remove(pBrowseWndInfo);
m_ParentWnd.SetBrowserWndInfo(NULL);
}

if (m_arrayBrowserWndInfo.GetSize() == 0)
{
if (m_hWnd)
{
UnsubclassWindow();
}
if (m_ParentWnd.m_hWnd)
{
m_ParentWnd.UnsubclassWindow();
}
}

if (pBrowseWndInfo != NULL)
{
delete pBrowseWndInfo;
}
}

void CIEToolbarWnd::SetCurrentBrowserWnd(IWebBrowser2 *pWebBrowser)
{
if (pWebBrowser == NULL)
{
return;
}
BrowserWndInfo* pBrowseWndInfo = findBrowserWndInfo(pWebBrowser);
m_ParentWnd.SetBrowserWndInfo(pBrowseWndInfo);
}


void CIEToolbarWnd::IsIE7(BOOL isIE7)
{
m_isIE7 = isIE7;
}

BOOL CIEToolbarWnd::ie7SubclassToolbar(HWND hBrowserWnd)
{
HWND hCmdbarWnd = FindWindowEx(hBrowserWnd, NULL, L"CommandBarClass", NULL);
if (hCmdbarWnd)
{
HWND hRebarWnd = FindWindowEx(hCmdbarWnd, NULL, L"ReBarWindow32", NULL);

HWND hToolbarWnd = ::GetDlgItem(hRebarWnd, 0x0000A000);

if (hToolbarWnd != NULL)
{
m_ParentWnd.SetToolbarWnd(hToolbarWnd);

SubclassWindow(hToolbarWnd);

m_ParentWnd.SubclassWindow(hCmdbarWnd);

return TRUE;
}
}
return FALSE;
}

BOOL CIEToolbarWnd::normalSubclassToolbar(HWND hBrowserWnd)
{
HWND hCmdbarWnd = ::GetDlgItem(hBrowserWnd, 0x0000A005);

if (hCmdbarWnd)
{
HWND hRebarWnd = FindWindowEx(hCmdbarWnd, NULL, L"ReBarWindow32", NULL);

if (hRebarWnd)
{
HWND hToolbarWnd = ::GetDlgItem(hRebarWnd, 0x0000A000);
if (hToolbarWnd != NULL)
{
m_ParentWnd.SetToolbarWnd(hToolbarWnd);
SubclassWindow(hToolbarWnd);
m_ParentWnd.SubclassWindow(hCmdbarWnd);
return TRUE;
}
}
}
return FALSE;
}

Points of Interest

Did you learn anything interesting/fun/annoying while writing the code? Did you do anything particularly clever or wild or zany?

History

Keep a running update of any changes or improvements you've made here.

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

About the Author

ferlysky
China China
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionrunning the projectmemberrvleonce6 Sep '11 - 22:24 
I try to test this project and it doesn't work on all version of IE. I just obtain the error message "miss inject". There is something to modify?
I'm beginner with atl/mfc project.
How can I do ?
Thanks.
rvleonce
QuestionIE8 ?memberSebastian M21 Jul '09 - 5:56 
The drop down menu is not displayed on IE8. Do you have an update for this problem?
Thanks!
AnswerRe: IE8 ?memberASheff14 Sep '10 - 22:23 
WNDPROC pfnWndProc = (WNDPROC)::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)pProc); (atlwin.h, line 3165) retugned 0.
GetLastError = 5 (Access Denied)
ASheff

GeneralSome changes to make it workmemberKarstenK28 May '08 - 3:36 
have I done. Please contact me to get the code. Than it is working REALLY better with the IE7 on Vista. Blush | :O
 
Greetings from Germany

GeneralNot working in ie6memberAleksandar Vucetic16 Feb '08 - 10:57 
This is exactly what I was looking for, but unfortunately it doesn't work in ie6, and I have no idea why (after 2 days of change and try Frown | :( Any ideas? Thanks for the code!
GeneralRe: Not working in ie6memberKarstenK26 May '08 - 23:09 
For IE 6 it is better to make a normal Toolbar.
 
Because of its oldness and vunerability you should consider not to support it.
 
Greetings from Germany

QuestionRe: Not working in ie6memberrvleonce6 Sep '11 - 22:20 
I try to test this project and it doesn't work on all version of IE. I just obtain the error message "miss inject". There is something to modify?
I'm beginner with atl/mfc project.
How can I do ?
Thanks.
rvleonce
AnswerRe: Not working in ie6memberKarstenK25 Sep '11 - 21:44 
you got a big problem, because such projects are very sophisticated and the interfaces of the IE 7 - 9 are changed somewhat and badly documented.
 
You better use the offical interfaces: http://archive.msdn.microsoft.com/SpicIE[^]
 
If you dont like trouble: USE IT!!!
 
The harder way is my advice for you is to use an easy approach.
 
Search for a "Exec ... ( )" function in the code. In that you can start to run another executable or show a menu for further actions.
 
"Have a lot of fun" and "stay tuff"
Press F1 for help or google it.
Greetings from Germany

AnswerIt's not work properlymemberEvgen_povt20 Dec '07 - 20:00 
Hello.
 
Please help me.
 
After installed it is not work properly. The button appearance but without arrow.
 
Function DefWindowProc in CIEToolbarWnd::OnSetButtonInfo() return error (error code: 14007) for all custom buttons, but it is success for standard buttons (such as RSS, Print, Help, etc).
 
Who can explain me, why this.
GeneralPositionmemberSF123414 Nov '07 - 9:27 
Would anyone know a way of positioning the icon on the toolbar so you know it is always in a specific position when installed.
 
For example after registering the current source code the icon was not on my toolbar at all. I had to go to the customize toolbar window and position it so it would show on my toolbar.
 
Is there a way to position and so I know that once it is installed it is always visible to the end user?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 8 Nov 2007
Article Copyright 2007 by ferlysky
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid