Click here to Skip to main content
15,897,334 members
Articles / Desktop Programming / ATL

The Mini Shell Extension Framework – Part III

Rate me:
Please Sign up or sign in to vote.
4.96/5 (11 votes)
18 Sep 200516 min read 142.4K   1.4K   46  
Discussion of a small C++ framework to create Windows shell extensions (IShellFolderImpl).
//
// (C) Copyright by Victor Derks <vba64@xs4all.nl>
//
// See README.TXT for the details of the software licence.
//
#pragma once
#include <atlsnap.h>
#include "../include/strutil.h"
#include "../include/util.h"
#include "vvvitem.h"
#include "resource.h"

#if _MSC_VER == 1300 // ATL 7.0 BEGIN_MSG_MAP generates: expression no effect warnings.
#pragma warning(push)
#pragma warning(disable: 4555) // expression has no effect; expected expression with side-effect
#endif


class CPropertyPageItem : public CSnapInPropertyPageImpl<CPropertyPageItem>
{
public:
	static HPROPSHEETPAGE CreateInstance(CVVVItem& item, long& wEventId, IShellFolder* pshellfolder)
	{
		CPropertyPageItem* ppage = new CPropertyPageItem(item, wEventId, pshellfolder);
		return ppage->Create();
	}

	enum { IDD = IDD_PROPERTY_PAGE_ITEM };

	BEGIN_MSG_MAP(CPropertyPageItem)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		CHAIN_MSG_MAP(CSnapInPropertyPageImpl<CPropertyPageItem>)
	END_MSG_MAP()


	CPropertyPageItem(CVVVItem& item, long& wEventId, IShellFolder* pshellfolder) :
		_item(item),
		_wEventId(wEventId),
		_rshellfolder(pshellfolder)
	{
	}


	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		InitializeStaticString();
		InitializeControls();
		return 1;
	}


	BOOL OnApply()
	{
		CString str;
		GetDlgItemText(IDC_EDIT_ITEM_NAME, str);
		str.Trim();

		if (_item.GetDisplayName() != str)
		{
			_item.SetDisplayName(str);
			_wEventId |= SHCNE_RENAMEITEM;
		}

		unsigned int nSize = GetDlgItemInt(IDC_EDIT_ITEM_SIZE, NULL, false);
		if (_item.GetSize() != nSize)
		{
			_item.SetSize(nSize);
			_wEventId |= SHCNE_ATTRIBUTES;
		}

		return true;
	}

private:
	// It is easier to patch the dialog during runtime with the locale
	// strings then to maintain copies of the dialog resource.
	void InitializeStaticString()
	{
		ATLVERIFY(SetDlgItemText(IDC_STATIC_ITEM_NAME, LoadString(IDS_SHELLEXT_NAME) + _T(":")));
		ATLVERIFY(SetDlgItemText(IDC_STATIC_ITEM_SIZE, LoadString(IDS_SHELLEXT_SIZE) + _T(":")));
	}


	void InitializeControls()
	{
		ATLVERIFY(SetDlgItemText(IDC_EDIT_ITEM_NAME, _item.GetName()));
		ATLVERIFY(SetDlgItemInt(IDC_EDIT_ITEM_SIZE, _item.GetSize()));

		// Note: SHLimitInputEdit is only supported on Windows XP.
		//ATLVERIFY(SUCCEEDED(SHLimitInputEdit(GetDlgItem(IDC_EDIT_ITEM_NAME), _rshellfolder)));
	}

	CPropertyPageItem& operator=(const CPropertyPageItem&) throw();

	// Member variables
	CVVVItem&             _item;
	long&                 _wEventId;
	CComPtr<IShellFolder> _rshellfolder;
};


#if _MSC_VER == 1300
#pragma warning(pop)
#endif

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
Software Developer (Senior) Hitachi High-Tech Analytical Science
Netherlands Netherlands
Victor lives in Nijmegen, the oldest city in The Netherlands.
He studied Applied Physics in Delft and works Hitachi High-Tech Analytical Science.

Comments and Discussions