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 GPL3
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 "AdBlockBand.h"

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

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

CAdBlockBand::CAdBlockBand()
{

}

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

HRESULT CAdBlockBand::FinalConstruct()
{
	return S_OK;
}

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

void CAdBlockBand::FinalRelease()
{
}

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

STDMETHODIMP CAdBlockBand::GetWindow(HWND *phWnd)
{
	// Get safe window handle
	*phWnd = m_wndToolBar.GetSafeHwnd();

	return S_OK;
}

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

STDMETHODIMP CAdBlockBand::ContextSensitiveHelp(BOOL fEnterMode)
{
	ATLTRACENOTIMPL("IOleWindow::ContextSensitiveHelp");
}

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

STDMETHODIMP CAdBlockBand::ShowDW(BOOL fShow)
{
	// Do we have a valid toolbar?
	if (m_wndToolBar.GetSafeHwnd())
	{
		// Should we show or hide our window?
		if (fShow)
		{
			// Show our window
			m_wndToolBar.ShowWindow(SW_SHOW);
		}
		else
		{
			// Hide our window
			m_wndToolBar.ShowWindow(SW_HIDE);
		}
	}

	// Succeeded
	return S_OK;
}

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

STDMETHODIMP CAdBlockBand::CloseDW(DWORD dwReserved)
{
	// Hide
	ShowDW(FALSE);

	// CToolBar will auto clean up

	// Succeeded
	return S_OK;
}

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

STDMETHODIMP CAdBlockBand::ResizeBorderDW(LPCRECT prcBorder, 
                                          IUnknown* punkSite, 
                                          BOOL fReserved)
{
	ATLTRACENOTIMPL("IDockingWindow::ResizeBorderDW");
}

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

STDMETHODIMP CAdBlockBand::GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO* pdbi)
{
	USES_CONVERSION;

	if (pdbi)
	{
		m_dwBandID = dwBandID;
		m_dwViewMode = dwViewMode;

		if (pdbi->dwMask & DBIM_MINSIZE)
		{
			pdbi->ptMinSize.x = TB_MIN_SIZE_X;
			pdbi->ptMinSize.y = TB_MIN_SIZE_Y;
		}

		if (pdbi->dwMask & DBIM_MAXSIZE)
		{
			pdbi->ptMaxSize.x = -1;
			pdbi->ptMaxSize.y = TB_MAX_SIZE_Y;
		}

		if(pdbi->dwMask & DBIM_INTEGRAL)
		{
			pdbi->ptIntegral.x = 1;
			pdbi->ptIntegral.y = 1;
		}

		if (pdbi->dwMask & DBIM_ACTUAL)
		{
			pdbi->ptActual.x = 200;
			pdbi->ptActual.y = TB_MAX_SIZE_Y;
		}

		if (pdbi->dwMask & DBIM_TITLE)
		{
			AFX_MANAGE_STATE(AfxGetStaticModuleState());
			CString strTitle((LPCSTR)IDS_TOOLBARNAME);
			lstrcpyW(pdbi->wszTitle, T2W((LPTSTR)(LPCTSTR)strTitle));
		}

		if (pdbi->dwMask & DBIM_MODEFLAGS)
		{
			pdbi->dwModeFlags = DBIMF_NORMAL;

			pdbi->dwModeFlags |= DBIMF_VARIABLEHEIGHT;
		}

		if (pdbi->dwMask & DBIM_BKCOLOR)
		{
			// Use the default background color by removing this flag
			pdbi->dwMask &= ~DBIM_BKCOLOR;
		}

		// Succeeded
		return S_OK;
	}
	else
	{
		return E_INVALIDARG;
	}
}

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

STDMETHODIMP CAdBlockBand::UIActivateIO(BOOL fActivate, LPMSG pMsg)
{
	// Should we activate?
    if (fActivate)
	{
		// Yes, set focus
		//SetFocus(m_hWnd);
	}

	// Succeeded
    return S_OK;
}

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

STDMETHODIMP CAdBlockBand::HasFocusIO(void)
{
	// Does the window has a focus?
    if (m_bFocus)
	{	
		// Yes, return S_OK
        return S_OK;
	}
	else
	{
		// No, return S_FALSE
		return S_FALSE;
	}
}

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

STDMETHODIMP CAdBlockBand::TranslateAcceleratorIO(LPMSG pMsg)
{
	// Needed for MFC calls
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// Let toolbar translate
	return m_wndToolBar.TranslateAcceleratorIO(pMsg);
}

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

STDMETHODIMP CAdBlockBand::SetSite(IUnknown* pUnkSite)
{
	// Are we initializing?
    if (pUnkSite != NULL)
    {
		// Initialize
		if (Initialize(pUnkSite) != S_OK)
		{
			return E_FAIL;
		}
    }
	else
    {
		// DeInitialize
		DeInitialize();
    }

    // Return the base class implementation
    return IObjectWithSiteImpl<CAdBlockBand>::SetSite(pUnkSite);
}

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

STDMETHODIMP CAdBlockBand::GetSite(REFIID riid, LPVOID *ppvReturn)
{
	// Set return value to NULL
	*ppvReturn = NULL;

	// Do we have a valid site object?
	if (m_spSite)
	{
		// Return interface
		return m_spSite->QueryInterface(riid, ppvReturn);
	}

	// Failed
	return E_FAIL;
}

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

HRESULT CAdBlockBand::Initialize(IUnknown * pUnkSite)
{
	// Declare variables
	HRESULT hr = S_OK;
	CComPtr<IUnknown> spUnknown(pUnkSite);
	CComPtr<IOleWindow> spOleWindow;
	CComPtr<IServiceProvider> spServiceProvider;

	// Store site IO
	pUnkSite->QueryInterface(IID_IInputObjectSite, (void **)&m_spSite);
	if (FAILED(hr))
	{
		return E_FAIL;
	}

	// Initialize the parent window
	m_hWndParent = NULL;

	// Get the parent window
	spOleWindow = spUnknown;
	spOleWindow->GetWindow(&m_hWndParent);

	// Check if we succeeded
	if (!m_hWndParent)
	{
		return E_FAIL;
	}

	// Create the tool window
	if (!CreateToolWindow())
	{
		return E_FAIL;
	}

	// Succeeded
	return S_OK;
}

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

void CAdBlockBand::DeInitialize()
{
}

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

bool CAdBlockBand::CreateToolWindow(void)
{
	// Needed for MFC calls
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	
	// Declare variables
	CRect rcClientParent;
	CWnd * pWndParent = CWnd::FromHandle(m_hWndParent);
	pWndParent->GetClientRect(&rcClientParent);

	// We need to create a reflection window in between our toolbar control
	// and the rebar in order to get WM_COMMAND messages sent from the toolbar to its
	// parent. 
	if (!m_wndReflectionWnd.Create(NULL, NULL, WS_CHILD, rcClientParent, pWndParent, 0))
	{
		return false;
	}

	// Create toolbar
	if (!m_wndToolBar.Create(rcClientParent, &m_wndReflectionWnd, this))
	{
		return false;
	}

	return true;
}

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

void CAdBlockBand::FocusChange(bool bFocus)
{
	// Store focus
    m_bFocus = bFocus;
    
    // Inform the input object site that the focus has changed
    if (m_spSite)
    {
        m_spSite->OnFocusChangeIS((IDockingWindow*)this, bFocus);
    }
}

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)

Share

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 | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 17 Jan 2008
Article Copyright 2008 by Geert van Horrik
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid