Click here to Skip to main content
15,894,540 members
Articles / Web Development / IIS

Cookie Spy

Rate me:
Please Sign up or sign in to vote.
4.85/5 (17 votes)
10 Oct 2001 202.8K   5.2K   61  
Creating a CookieSpy explorer bar with ATL
/*
 Copyright (c) 2001
 Author: Konstantin Boukreev 
 E-mail: konstantin@mail.primorye.ru 

 Created: 16.02.2001 17:10:00
 Version: 1.0.0

*/

#ifndef _DeskBandImpl_18b2f90a_7a23_40a9_a83e_43e358450c1b
#define _DeskBandImpl_18b2f90a_7a23_40a9_a83e_43e358450c1b

#if _MSC_VER > 1000 
#pragma once
#endif // _MSC_VER > 1000

#define _QUOTE(x) # x
#define QUOTE(x) _QUOTE(x)
#define __FILE__LINE__ __FILE__ "(" QUOTE(__LINE__) ") : "

#ifndef _SHLOBJ_H_
#pragma message( __FILE__LINE__ " warning : to avoid this message, include <shlobj.h> in stdafx.h" )
#include <shlobj.h>
#endif _SHLOBJ_H_

template <class T>
class ATL_NO_VTABLE DeskBandImpl : 
	public IDeskBand,
	public IObjectWithSite,
	public CMessageMap
{
protected:
	DWORD				m_dwBandID;
	DWORD				m_dwViewMode;
	DESKBANDINFO		m_dbi;	
	CComPtr<IUnknown>	m_spUnkSite;
	CComQIPtr<IInputObjectSite, &IID_IInputObjectSite> m_spInputObjectSite;

public:	
	DeskBandImpl(const wchar_t* title = 0) : 
		m_dwBandID(0), 
		m_dwViewMode(0) 
	{
		memset(&m_dbi, 0, sizeof DESKBANDINFO);
		m_dbi.ptMinSize.x = 0;	
		m_dbi.ptMinSize.y = 0;
		m_dbi.ptMaxSize.x = -1;
		m_dbi.ptMaxSize.y = -1;
		m_dbi.ptIntegral.x = 1;
		m_dbi.ptIntegral.y = 1;		
		m_dbi.dwModeFlags = DBIMF_NORMAL | DBIMF_VARIABLEHEIGHT;
		if (title) lstrcpyW(m_dbi.wszTitle, title);
	}

 BEGIN_MSG_MAP(DeskBandImpl)
	MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
	MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
 END_MSG_MAP()

 BEGIN_COM_MAP(DeskBandImpl)
	COM_INTERFACE_ENTRY(IObjectWithSite)
	COM_INTERFACE_ENTRY(IOleWindow)		
	COM_INTERFACE_ENTRY_IID(IID_IDockingWindow,IDeskBand)
	COM_INTERFACE_ENTRY_IID(IID_IDeskBand,IDeskBand)
 END_COM_MAP()

// IOleWindow
public:
	STDMETHOD(GetWindow)(HWND* phWnd)
	{
		T* pT = static_cast<T*>(this);
		*phWnd = pT->m_hWnd;
		return S_OK;
	}
	STDMETHOD(ContextSensitiveHelp)(BOOL bEnterMode)
	{
		return E_NOTIMPL;
	}

// IDockingWindow
public:
	STDMETHOD(ShowDW)(BOOL bShow)
	{
		T* pT = static_cast<T*>(this);
		ShowWindow(pT->m_hWnd, bShow ? SW_SHOW : SW_HIDE);
		return S_OK;
	}
	STDMETHOD(CloseDW)(DWORD dwReserved)
	{
		ShowDW(FALSE);

		T* pT = static_cast<T*>(this);
		if (IsWindow(pT->m_hWnd))
			DestroyWindow(pT->m_hWnd);

		pT->m_hWnd = 0;
		return S_OK;
	}
	STDMETHOD(ResizeBorderDW)(LPCRECT prcBorder, IUnknown* punkSite, BOOL bReserved)
	{			
		return E_NOTIMPL;
	}
	
// IDeskBand		
public:
	STDMETHOD(GetBandInfo)(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO* pdbi)
	{
		m_dwBandID = dwBandID;
		m_dwViewMode = dwViewMode;

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

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

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

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

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

		   if(pdbi->dwMask & DBIM_TITLE)
			{			  
			  lstrcpyW(pdbi->wszTitle, m_dbi.wszTitle);
			}

		   if(pdbi->dwMask & DBIM_MODEFLAGS)
			{
			  pdbi->dwModeFlags = m_dbi.dwModeFlags;
			}
   
		   if(pdbi->dwMask & DBIM_BKCOLOR)
			{
			  pdbi->crBkgnd = m_dbi.crBkgnd;
			}
		}		
		return S_OK;
	}

// IObjectWithSite
public:
	STDMETHOD(SetSite)(IUnknown *pUnkSite)
	{		
		m_spUnkSite = pUnkSite;		
		m_spInputObjectSite = pUnkSite;

		if(pUnkSite)
		{			
			CComQIPtr<IOleWindow> pOleWindow(pUnkSite);
			HWND hParent = 0;
			pOleWindow->GetWindow(&hParent);
			if(!hParent) return E_FAIL;
			
			T* pT = static_cast<T*>(this);
			if(!pT->m_hWnd)
			{
				RECT rc;
				::GetClientRect(hParent, &rc);
				if(!pT->CreateControlWindow(hParent, rc)) 
					return E_FAIL;
			}						
		}		
		return S_OK;
	}
	STDMETHOD(GetSite)(REFIID riid, void** ppv)	
	{			
		ATLASSERT(ppv);
		if (!m_spUnkSite) return E_FAIL;
		return m_spUnkSite->QueryInterface(riid, ppv);		
	}

//message handlers
protected:
	LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		T* pT = static_cast<T*>(this);
		pT->FocusChange(FALSE);		
		bHandled = FALSE;
		return 1;
	}
	LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		T* pT = static_cast<T*>(this);
		pT->FocusChange(TRUE);
		bHandled = FALSE;
		return 1;
	}

// override
protected:
	void FocusChange(BOOL bFocus)
	{
		T* pT = static_cast<T*>(this);		
		if(m_spInputObjectSite)
			m_spInputObjectSite->OnFocusChangeIS(pT->GetUnknown(), bFocus);
	}

	HWND CreateControlWindow(HWND hParent, RECT& rc)
	{
		T* pT = static_cast<T*>(this);		
		return pT->Create(hParent, rc, 0, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS);
	}
};


#endif //_DeskBandImpl_18b2f90a_7a23_40a9_a83e_43e358450c1b

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 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


Written By
Web Developer
Russian Federation Russian Federation
I am freelance programmer. About 3 years of experience in C++ and I would rather use ATL, STL, WTL but not MFC Smile | :) . Main backgrounds are Win32 API, COM and Networking. Now I am interested about AI (Neural Network, Fuzzy Logic and GA). Currently based in Vladivostok, Russia.

Comments and Discussions