Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Internet Explorer AdBlock

, 17 Jan 2008
Internet Explorer AdBlock Add-on
ieadblock_src.zip
IE AdBlockPS
IE AdBlockps.def
IE AdBlock
AdBlockBand.rgs
AdBlockBHO.rgs
bin
XListCtrlSSDU.lib
XListCtrlSSRU.lib
IE AdBlock.def
IE AdBlock.rgs
res
bmpToolbar.bmp
checkboxes.bmp
icoSettings.ico
XListCtrl
checkboxes.bmp
//*********************************************************************
// INCLUDES
//*********************************************************************

#include "stdafx.h"
#include "resource.h"
#include "AdBlockToolBarCtrl.h"

#include "AdBlockBHO.h"

#include "SettingsSheet.h" 

//*********************************************************************
// MESSAGE MAP
//*********************************************************************

BEGIN_MESSAGE_MAP(CAdBlockToolBarCtrl, CToolBarCtrl)
	ON_WM_SIZE()
	ON_WM_KEYDOWN()
	ON_CONTROL_REFLECT(0, OnCommand)
	ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnTTNNeedText)
END_MESSAGE_MAP()

//*********************************************************************
// HELPER FUNCTIONS
//*********************************************************************

BOOL IsWindow(CWnd *pWnd)
{
    if (!pWnd)
	{
        return FALSE;
	}
    return ::IsWindow(pWnd->m_hWnd);
}

//*********************************************************************
// CONSTRUCTOR & DESTRUCTOR
//*********************************************************************

CAdBlockToolBarCtrl::CAdBlockToolBarCtrl()
{
}

//=====================================================================

CAdBlockToolBarCtrl::~CAdBlockToolBarCtrl()
{
}

//*********************************************************************
// PUBLIC FUNCTIONS
//*********************************************************************

bool CAdBlockToolBarCtrl::Create(CRect rcClientParent, CWnd * pWndParent, CAdBlockBand * pBand) 
{
	// Create toolbar control
	if (!CToolBarCtrl::Create(DEFAULT_TOOLBAR_STYLE, rcClientParent, pWndParent, IDB_IETOOLBAR))
	{
		return false;
	}

	// Add bitmap toolbar
	if (AddBitmap(2, IDB_IETOOLBAR) == -1)
	{
		DWORD dwError = ::GetLastError();
		return false;
	}

	// Create buttons
	TBBUTTON tbs[NUM_TOOLBAR_BUTTONS];
	for (int i = 0; i < NUM_TOOLBAR_BUTTONS; i++)
	{
		tbs[i].dwData = 0;
		tbs[i].fsState = TBSTATE_ENABLED;
		// TEMPORARY DISABLE SOME BUTTONS
		if (i != 2)
		{
			tbs[i].fsState = 0;
		}
		// END TEMPORARY CODE
		tbs[i].fsStyle = TBSTYLE_BUTTON;
		tbs[i].iBitmap = i;
		tbs[i].idCommand = ID_TBB_BLACKLIST_ADD + i;
		tbs[i].iString = i;
	}

	// Add buttons
	if (AddButtons(NUM_TOOLBAR_BUTTONS, tbs) == FALSE)
	{
		return false;
	}

	// Store band pointer
	m_pBand = pBand;

	// Succeeded
	return true;
}

//=====================================================================

STDMETHODIMP CAdBlockToolBarCtrl::TranslateAcceleratorIO(LPMSG pMsg)
{
	return S_FALSE;
}

//=====================================================================

BOOL CAdBlockToolBarCtrl::PreTranslateMessage(MSG* pMsg) 
{
	// Declare variables
    CRect rectButton;
    CRect rectWindow;

	// Do we have a valid window?
    if (!IsWindow(m_ToolTip))
    {
        // Create and activate the tooltip control
        m_ToolTip.Create(this);
        m_ToolTip.Activate(TRUE);
        m_ToolTip.SetFont(GetFont());

        // Setup the button tooltip
		for (int i = 0; i < NUM_TOOLBAR_BUTTONS; i++)
		{
			// Get button rectangle
			GetItemRect(ID_TBB_BLACKLIST_ADD + i, &rectButton);

			// Calculate offset
			GetWindowRect(&rectWindow);
			rectButton.OffsetRect(rectWindow.left, rectWindow.top);
			ScreenToClient(&rectButton);

			// Add tooltip for the button
			m_ToolTip.AddTool(this, LPSTR_TEXTCALLBACK, &rectButton, ID_TBB_BLACKLIST_ADD + i);
		}
    }
    m_ToolTip.RelayEvent(pMsg);

    return CToolBarCtrl::PreTranslateMessage(pMsg);
}

//*********************************************************************
// PRIVATE FUNCTIONS
//*********************************************************************

void CAdBlockToolBarCtrl::OnSize(UINT nType, int cx, int cy) 
{
	// Do nothing - prevent base class impl from doing bad things
}

//=====================================================================

void CAdBlockToolBarCtrl::OnCommand()
{
	// Declare variables
	const MSG* pMsg = GetCurrentMessage();
	int nID = LOWORD(pMsg->wParam);
	_variant_t varEmpty;
	_variant_t varURL;

	// Execute right action
	switch (nID)
	{
	case ID_TBB_BLACKLIST_ADD:
		// Add current url to blacklist
		/*varURL = _bstr_t(g_MSDNURL);
		m_pBand->m_pIE->Navigate2(&varURL, &varEmpty, &varEmpty, &varEmpty, &varEmpty);*/
		break;

	case ID_TBB_WHITELIST_ADD:
		// Add current url to whitelist
		/*varURL = _bstr_t(g_WWURL);
		m_pBand->m_pIE->Navigate2(&varURL, &varEmpty, &varEmpty, &varEmpty, &varEmpty);*/
		break;

	case ID_TBB_SETTINGS:
		// Show settings
		CSettingsSheet settings(CListData::Instance()->GetBlackList(), CListData::Instance()->GetWhiteList());
		settings.DoModal();
	}
}

//=====================================================================

BOOL CAdBlockToolBarCtrl::OnTTNNeedText(UINT, NMHDR *pTTTStruct, LRESULT *)
{
	// Declare variables
    TOOLTIPTEXT* pTTT = ((TOOLTIPTEXT*)pTTTStruct);
	CLanguage * pLanguage = CLanguage::Instance();

	// Load correct text
	switch (pTTT->hdr.idFrom)
	{
	case ID_TBB_BLACKLIST_ADD:
		m_sToolTipText = pLanguage->GetString(IDS_TOOLTIP_ADDBLACKLIST);
		break;

	case ID_TBB_WHITELIST_ADD:
		m_sToolTipText = pLanguage->GetString(IDS_TOOLTIP_ADDBLACKLIST);
		break;

	case ID_TBB_SETTINGS:
		m_sToolTipText = pLanguage->GetString(IDS_TOOLTIP_SETTINGS);
		break;

	default:
		m_sToolTipText = _T("");
		break;
	}

	// Set window text to tooltip
    pTTT->lpszText = m_sToolTipText.GetBuffer(m_sToolTipText.GetLength());

	// Return TRUE
    return TRUE;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Geert van Horrik
Software Developer CatenaLogic
Netherlands Netherlands
I am Geert van Horrik, and I have studied Computer Science in the Netherlands.
 
I love to write software using .NET (especially the combination of WPF and C#). I am also the lead developer of Catel, an open-source application development framework for WPF, Silverlight, WP7 and WinRT with the focus on MVVM.
 
I have my own company since January 1st 2007, called CatenaLogic. This company develops commercial and non-commercial software.
 
To download (or buy) applications I have written, visit my website: http://www.catenalogic.com
Follow on   Twitter

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 17 Jan 2008
Article Copyright 2008 by Geert van Horrik
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid