Click here to Skip to main content
Click here to Skip to main content
Go to top

IE Drop-Down Button

, 8 Nov 2007
Rate this:
Please Sign up or sign in to vote.
similar skype IE toolbar button, with drop-down arraw, support IE6 & IE7(multi-tab)
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

Share

About the Author

ferlysky

China China
No Biography provided

Comments and Discussions

 
Questionrunning the project Pinmemberrvleonce6-Sep-11 22:24 
QuestionIE8 ? PinmemberSebastian M21-Jul-09 5:56 
AnswerRe: IE8 ? PinmemberASheff14-Sep-10 22:23 
GeneralSome changes to make it work PinmemberKarstenK28-May-08 3:36 
GeneralNot working in ie6 PinmemberAleksandar Vucetic16-Feb-08 10:57 
GeneralRe: Not working in ie6 PinmemberKarstenK26-May-08 23:09 
QuestionRe: Not working in ie6 Pinmemberrvleonce6-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 ie6 PinmemberKarstenK25-Sep-11 21:44 
AnswerIt's not work properly PinmemberEvgen_povt20-Dec-07 20:00 
GeneralPosition PinmemberSF123414-Nov-07 9:27 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 8 Nov 2007
Article Copyright 2007 by ferlysky
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid