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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralNot working in ie6memberAleksandar Vucetic16 Feb '08 - 10:57 
GeneralRe: Not working in ie6memberKarstenK26 May '08 - 23:09 
QuestionRe: Not working in ie6memberrvleonce6 Sep '11 - 22:20 
AnswerRe: Not working in ie6memberKarstenK25 Sep '11 - 21:44 

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