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

The Mini Shell Extension Framework – Part III

, 18 Sep 2005
Discussion of a small C++ framework to create Windows shell extensions (IShellFolderImpl).
msf091.zip
include
columnprovider.rgs
contextmenu.rgs
contextmenu_sf.rgs
extension.rgs
extractimage_sf.rgs
infotip.rgs
infotip_sf.rgs
propertysheetext.rgs
propertysheetext_sf.rgs
shell32missing.def
shell32missing.lib
shellfolder.rgs
shellfolderwin98.rgs
vvvsample
Copy of sample1.vvv
menuicon.bmp
sample.def
sample.manifest
sample1.vvv
vvv.ico
vvvtest
sample.yyy
sample1.vvv
sample2.vvv
//
// (C) Copyright by Victor Derks <vba64@xs4all.nl>
//
// See README.TXT for the details of the software licence.
//
#pragma once


// Purpose: emulated version of the system shell folder view
//          As this version has full source it makes things easier to understand.

// TODO: make this CDefView at least do the 'view' part.


#include "shellviewimpl.h"


namespace MSF
{

class CCallback
{
public:
	CCallback(IShellFolderViewCB* pshellfolderviewcb) :
		_rshellfolderviewcb(pshellfolderviewcb)
	{
	}


	HRESULT CallCB(UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		if (_rshellfolderviewcb == NULL)
			return E_FAIL;

		return _rshellfolderviewcb->MessageSFVCB(uMsg, wParam, lParam);
	}


	// Purpose: function is used when shellfolder view is created to 
	//          obtain something.. [UNDOCUMENTED]
	HRESULT GetUndocumentedSetting()
	{
		return CallCB(SFVM_UNDOCUMENTED78, 0, 0);
	}


	// Purpose: used during startup to retrieve sorting defauls.
	HRESULT GetSortDefaults(int* piDirection, int* piColumn)
	{
		CallCB(SFVM_GETSORTDEFAULTS,
			reinterpret_cast<WPARAM>(piDirection), reinterpret_cast<LPARAM>(piColumn));
	}


	HRESULT GetViewData()
	{
		return CallCB(SFVM_GET_VIEW_DATA, 0, 0);
	}


	HRESULT GetShowWebView()
	{
		return CallCB(SFVM_SHOWWEBVIEW, 0, 0);
	}


	HRESULT GetBackGroundEnum()
	{
		return CallCB(SFVM_BACKGROUNDENUM, 0, 0);
	}


	HRESULT GetColumnStream()
	{
		return CallCB(SFVM_GETCOLUMNSTREAM, 0, 0);
	}


	HRESULT GetWebViewLayout()
	{
		return CallCB(SFVM_GET_WEBVIEW_LAYOUT, 0, 0);
	}


	HRESULT GetCustomViewInfo()
	{
		return CallCB(SFVM_GET_CUSTOMVIEWINFO, 0, 0);
	}


	HRESULT FindItem()
	{
		return CallCB(SFVM_FINDITEM, 0, 0);
	}


	void NotifyWndMain(HWND hwnd)
	{
		CallCB(SFVM_WNDMAIN, hwnd, 0);
	}


	void NotifyWndSize()
	{
		CallCB(SFVM_SIZE, 0, 0);
	}


	void NotifyEnumeratedItems()
	{
		CallCB(SFVM_ENUMERATEDITEMS, 0, 0);
	}


	void NotifyWindowCreated(HWND hwndView)
	{
		CallCB(SFVM_WINDOWCREATED, hwndView, 0);
	}


	void NotifyWindowClosing()
	{
		CallCB(SFVM_WINDOWCLOSING, 0, 0);
	}


	void NotifyRemovingObject()
	{
		CallCB(SFVM_REMOVINGOBJECT, 0, 0);
	}


	void NotifyViewDestruct()
	{
		CallCB(SFVM_VIEWRELEASE, 0, 0);
	}

private:
	CComPtr<IShellFolderViewCB> _rshellfolderviewcb;
};


class CDefviewEnumTask()
{
public:
	FillObjectsToDPA()
	{
		_callback.GetBackGroundEnum();

		//_callback. // enum done?
	}
};


class CViewState
{
public:
	void InitWithDefaults(const CCallback& callback)
	{
		GetDefaults(callback);
	}


	void GetDefaults(const CCallback& callback)
	{
		if (SUCCEEDED(callback.GetSortDefaults(&_iDirection, &_iColumn)))
			return;
	
		_iDirection = 0;// todo
		_iColumn = 0;
	}

	int _iDirection;
	int _iColumn;
};


class CContextMenuCB
{
	void CallBack()
	{
	}


	NotifyDfmCommand()
	{
		CallBack();
	}
}


class ATL_NO_VTABLE CDefView : public IShellViewImpl<CDefView>
{
public:
	DECLARE_NOT_AGGREGATABLE(CDefView)

	BEGIN_COM_MAP(CDefView)
		COM_INTERFACE_ENTRY(IShellView)
	END_COM_MAP()

	// COM_INTERFACE_ENTRY(IOleWindow) ?


	static CComPtr<IShellView> CreateInstance(const SFV_CREATE* pcsfv)
	{
		CComObject<CDefView>* pinstance;
		RaiseExceptionIfFailed(
			CComObject<CDefView>::CreateInstance(&pinstance));

		CComPtr<IShellView> rshellview(pinstance);

		pinstance->Init(pcsfv);

		return rshellview;
	}


	CDefView()
	{
	}


	void Init(const SFV_CREATE* pcsfv)
	{
		_rshellfolder       = pcsfv->pshf;
		_rshellviewOuter    = pcsfv->psvOuter;
		_rshellfolderviewcb = pcsfv->psfvcb;
	}


	HRESULT CreateViewWindow(IShellView* psvPrevious,
	                         const FOLDERSETTINGS* pfs,
	                         IShellBrowser* psb,
	                         RECT* prcView,
	                         HWND* phWnd)
	{
		//ATLTRACENOTIMPL(_T("IShellViewImpl::CreateViewWindow"));
		SV2CVW2_PARAMS params;

		params.cbSize   = sizeof(params);
		params.psvPrev  = psvPrevious;
		params.pfs      = pfs;
		params.psbOwner = psb;
		params.prcView  = prcView;
		params.pvid     = NULL; // todo

		HRESULT hr = CreateViewWindow2(params);
		*phWnd = params.hwndView;
		return hr;
	}


	HRESULT CreateViewWindow2(SV2CVW2_PARAMS* pParams)
	{
		_callback.NotifyWndMain(0);

		FillObjectsToDPA();

		SwitchToViewFVM();

		_callback.NotifyWindowCreated();

		UpdateListviewColors();

		_rshellbrowser = pParams.psbOwner;
	}


	void GetView()
	{
		ViewSupported();
	}


	void AddColumns()
	{
		//_callback.//streams
	}


	void DestroyViewWindow()
	{
		_callback.NotifyWindowClosing();
	}

private:

	void ViewSupported()
	{
		GetSFVMViewState();
	}


	void GetSFVMViewState()
	{
		_callback.GetViewData();
	}


	void SwitchToViewFVM()
	{
		AddColumns();

		TryShowWebView();
	}


	void TryShowWebView()
	{
		_callback.GetWebViewLayout();
	}


	static void WndProc()
	{
		// pthis->WndProc();
	}


	void WndProc()
	{
		switch()
		{
			case 
				OnCreate();

			case 
				WndSize();

			case 
				OnSelectionChanged();
		}
	}


	void OnCreate()
	{
		ShouldShowWebView();
	}


	void WndSize()
	{
		_callback.NotifyWndSize()
	}


	void OnSelectionChanged()
	{
	}


	bool ShouldShowWebView()
	{
		_callback.GetShowWebView();
	}


	void FindItem()
	{
		_callback.FindItem();
	}


	void ExplorerCommand()
	{
		InvokeContextMenu();
	}


	void InvokeContextMenu()
	{
		_deffoldermenu.InvokeCommand(_callback);
	}

	//WndProc()
	//OnFSNotify()
	//AddOrUpdateItem()
	//UpdateStatusBar()
	//OnLVNotify()
	//Attributes()
	//IsImageMode()
	//SetSortFeedback()
	//SetDefaultViewSettings
	//ForwardMenuMessages
	//SetFolderColors
	//OnInitMenuPopup
	//OnClipboardChange

	// Member variables
	CComPtr<IShellFolder>       _rshellfolder;
	CComPtr<IShellView>         _rshellviewOuter;
	CComPtr<IShellFolderViewCB> _rshellfolderviewcb;
	CComPtr<IShellBrowser>      _rshellbrowser;
	ATL::CWindow                _window;
};

} // namespace MSF

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

Share

About the Author

Victor Derks
Software Developer (Senior) Schneider Electric
Netherlands Netherlands
Victor lives in Nijmegen, the oldest city in The Netherlands.
He studied Applied Physics in Delft and now works for GE Healthcare.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 18 Sep 2005
Article Copyright 2005 by Victor Derks
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid