Click here to Skip to main content
15,884,986 members
Articles / Desktop Programming / WTL

RSS Reader Plug-in for Internet Explorer

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
16 Jul 2007CPOL4 min read 317.3K   1.3K   32  
This is a toolbar for the Internet Explorer which shows information from RSS taken from the Internet.
/*
	Project		: RSS Reader plugin for Internet Explorer
	File Name	: RRPComInterfaceImplementor.cpp
	Date		: 
	Purpose		: It implements all the COM intefaces requrired by IE,to make
				  this Component eligible as IE deskband (IE toolbar in this case)
	Note		: Generated by IE Deskband Wizard by RadBytes.com,It also contains
				  some code by me.
	Send comments 
	or Bugs to	: prafulla_t@users.sourceforge.net
*/
#include "stdafx.h"
#include <wchar.h>
#include "RssReaderPlugin.h"
#include "RRPComInterfaceImplementor.h"
#include "RRPToolbar.h"
#include <comdef.h>

const WCHAR TITLE_CRRPComInterfaceImplementor[] = L"CRRPComInterfaceImplementor";

/////////////////////////////////////////////////////////////////////////////
// CRRPComInterfaceImplementor

CRRPComInterfaceImplementor::CRRPComInterfaceImplementor(): 
	m_dwBandID(0), 
	m_dwViewMode(0), 
	m_bShow(FALSE), 
	m_bEnterHelpMode(FALSE), 
	m_hWndParent(NULL), 
	m_hWnd(NULL),
	m_pSite(NULL)
{
//	InitAllocCheck(ACOutput_Simple);
	debug = RRPDebugInfoLogger::getInstance();
}

CRRPComInterfaceImplementor::~CRRPComInterfaceImplementor() {
//	DeInitAllocCheck();

}
BOOL CRRPComInterfaceImplementor::RegisterAndCreateWindow()
{
	RECT rect;
	::GetClientRect(m_hWndParent, &rect);

	//Checking if we really have IE window handle
	ATLASSERT(m_hWndParent != NULL);

	//No name child widnow
	HWND reflectionWindowHandle = reflectionWindow.Create(m_hWndParent,NULL,NULL,WS_CHILD | SS_CENTER);
	
	rrpToolbar.setBrowser(webBrowser);
	
	//Perfect use of Operator HWND 
	//m_hWnd = reflectionWindow;
	m_hWnd = rrpToolbar.createToolbar(reflectionWindow,rect);

	

	return ::IsWindow(m_hWnd);
}

// IDeskBand
STDMETHODIMP CRRPComInterfaceImplementor::GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO* pdbi)
{
	m_dwBandID = dwBandID;
	m_dwViewMode = dwViewMode;

	if (pdbi)
	{
		if (pdbi->dwMask & DBIM_MINSIZE)
		{
			pdbi->ptMinSize.x = 250;
			pdbi->ptMinSize.y = 20;
		}
		if (pdbi->dwMask & DBIM_MAXSIZE)
		{
			pdbi->ptMaxSize.x = 0; // ignored
			pdbi->ptMaxSize.y = -1;	// width
		}
		if (pdbi->dwMask & DBIM_INTEGRAL)
		{
			pdbi->ptIntegral.x = -1; // ignored
			pdbi->ptIntegral.y = -1; // not sizeable
		}
		if (pdbi->dwMask & DBIM_ACTUAL)
		{
			pdbi->ptActual.x = 250;
			pdbi->ptActual.y = 30;
		}
		if (pdbi->dwMask & DBIM_TITLE)
		{
			wcscpy(pdbi->wszTitle, L"");
		}
		if (pdbi->dwMask & DBIM_BKCOLOR)
		{
			//Use the default background color by removing this flag.
			pdbi->dwMask &= ~DBIM_BKCOLOR;
		}
		if (pdbi->dwMask & DBIM_MODEFLAGS)
		{
			pdbi->dwModeFlags = DBIMF_FIXED;
		}
	}
	return S_OK;
}

// IOleWindow
STDMETHODIMP CRRPComInterfaceImplementor::GetWindow(HWND* phwnd)
{
	HRESULT hr = S_OK;
	if (NULL == phwnd)
	{
		hr = E_INVALIDARG;
	}
	else
	{
		*phwnd = m_hWnd;
	}
	return hr;
}

STDMETHODIMP CRRPComInterfaceImplementor::ContextSensitiveHelp(BOOL fEnterMode)
{
	m_bEnterHelpMode = fEnterMode;
	return S_OK;
}

// IDockingWindow
STDMETHODIMP CRRPComInterfaceImplementor::CloseDW(unsigned long dwReserved)
{
	if (::IsWindow(m_hWnd))
	{
		::DestroyWindow(m_hWnd);
	}
	return S_OK;
}

STDMETHODIMP CRRPComInterfaceImplementor::ResizeBorderDW(const RECT* prcBorder, IUnknown* punkToolbarSite, BOOL fReserved)
{
	// Not used by any band object.
	return E_NOTIMPL;
}

STDMETHODIMP CRRPComInterfaceImplementor::ShowDW(BOOL fShow)
{
	HRESULT hr = S_OK;
	m_bShow = fShow;
	ShowWindow(m_hWnd, m_bShow ? SW_SHOW : SW_HIDE);
	return hr;
}
// IObjectWithSite
STDMETHODIMP CRRPComInterfaceImplementor::SetSite(IUnknown* pUnkSite)
{
//If a site is being held, release it.
	if(m_pSite)
	{
		m_pSite->Release();
		m_pSite = NULL;
	}

	//If punkSite is not NULL, a new site is being set.
	if(pUnkSite)
	{
		//Get the parent window.
		IOleWindow  *pOleWindow = NULL;

		m_hWndParent = NULL;

		if(SUCCEEDED(pUnkSite->QueryInterface(IID_IOleWindow, (LPVOID*)&pOleWindow)))
		{
			pOleWindow->GetWindow(&m_hWndParent);
			pOleWindow->Release();
		}
		// Minimum of Explorer 4 required
        IServiceProviderPtr pServiceProvider = pUnkSite;

		if (webBrowser)
			webBrowser = NULL;
		
        if (FAILED(pServiceProvider->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (void**)&webBrowser)))
            return E_FAIL;
		

		if(!::IsWindow(m_hWndParent))
			return E_FAIL;

		if(!RegisterAndCreateWindow())
			return E_FAIL;

		//Get and keep the IInputObjectSite pointer.
		if(SUCCEEDED(pUnkSite->QueryInterface(IID_IInputObjectSite, (LPVOID*)&m_pSite)))
		{
			return S_OK;
		}  
		return E_FAIL;
	}
	return S_OK;
}

STDMETHODIMP CRRPComInterfaceImplementor::GetSite(REFIID riid, void **ppvSite)
{
	*ppvSite = NULL;

	if(m_pSite)
	{
	   return m_pSite->QueryInterface(riid, ppvSite);
	}
	return E_FAIL;
}

// IPersist
STDMETHODIMP CRRPComInterfaceImplementor::GetClassID(CLSID *pClassID)
{
	*pClassID = CLSID_RRPComInterfaceImplementor;
	return S_OK;
}

// IPersistStream
STDMETHODIMP CRRPComInterfaceImplementor::IsDirty(void)
{
	return S_FALSE;
}

STDMETHODIMP CRRPComInterfaceImplementor::Load(IStream *pStm)
{
	return S_OK;
}

STDMETHODIMP CRRPComInterfaceImplementor::Save(IStream *pStm, BOOL fClearDirty)
{
	return S_OK;
}

STDMETHODIMP CRRPComInterfaceImplementor::GetSizeMax(ULARGE_INTEGER *pcbSize)
{
	return E_NOTIMPL;
}


void CRRPComInterfaceImplementor::FocusChange(BOOL bHaveFocus) {
	if (m_pSite) {
	
		IUnknown* pUnk = NULL;
		if (SUCCEEDED(QueryInterface(IID_IUnknown, (LPVOID*)&pUnk)) && pUnk != NULL) {
			m_pSite->OnFocusChangeIS(pUnk, bHaveFocus);
			pUnk->Release();
			pUnk = NULL;
		}
	}
}



STDMETHODIMP CRRPComInterfaceImplementor::HasFocusIO(void)
{
    HWND hwnd = GetFocus();
    // See if the focus has been set to any of the children
    HWND hChild = ::GetWindow(rrpToolbar.m_hWnd, GW_CHILD);
    while (hChild) 
    {
        // check its child
        HWND hGrandChild = ::GetWindow(hChild, GW_CHILD);

        if (hwnd == hChild || hwnd == hGrandChild)
            return S_OK;

        hChild = ::GetWindow(hChild, GW_HWNDNEXT);
    }

    return S_FALSE;

}
STDMETHODIMP CRRPComInterfaceImplementor::TranslateAcceleratorIO(LPMSG lpMsg) {
	debug->log("Hi there");
	return 0;
}
STDMETHODIMP CRRPComInterfaceImplementor::UIActivateIO(BOOL fActivate, LPMSG lpMsg) {
	   debug->log("Hi there");
	   return S_OK;
}

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 Code Project Open License (CPOL)


Written By
India India
Quote : "Life is all about solving problems and enjoying their solutions !! "

Comments and Discussions