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

By , 18 Sep 2005
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
#include "../include/propertypageimpl.h"
#include "../include/strutil.h"
#include "../include/util.h"
#include "vvvfile.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 CPropertyPageVVV : public CShellExtPropertyPageImpl<CPropertyPageVVV>
{
public:
	static HPROPSHEETPAGE CreateInstance(const CString& strFilename)
	{
		CPropertyPageVVV* ppage = new CPropertyPageVVV(strFilename);
		return ppage->Create();
	}

	enum { IDD = IDD_PROPERTY_PAGE_VVV };

	BEGIN_MSG_MAP(CPropertyPageVVV)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		COMMAND_HANDLER(IDC_EDIT_LABEL, EN_CHANGE, OnChangeEditName)
		CHAIN_MSG_MAP(CShellExtPropertyPageImpl<CPropertyPageVVV>)
	END_MSG_MAP()

	CPropertyPageVVV(const CString& strFilename) :
		_strFilename(strFilename)
	{
		CVVVFile vvvfile(strFilename);

		// Retrieve the file data: the sample don't shows the page if this fails.
		_strLabel   = vvvfile.GetLabel();
		_nFileCount = vvvfile.GetFileCount();
	}


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


	LRESULT OnChangeEditName(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
	{
		CString str = GetLabel();
		SetModified(str != _strLabel);
		bHandled = true;
		return 1;
	}


	BOOL OnApply()
	{
		CString str = GetLabel();
		if (str.IsEmpty())
			return false; // an empty name is invalid (in our VVV example).

		try
		{
			CVVVFile(_strFilename).SetLabel(str);
			_strLabel = str;
			return true;
		}
		catch (const _com_error& e)
		{
			CString strMsg = LoadString(IDS_PROPERTYPAGE_UNABLE_TO_UPDATE) +
			                 FormatLastError(static_cast<DWORD>(e.Error()));
			IsolationAwareMessageBox(GetParent().m_hWnd, strMsg, MSF::LoadString(IDS_SHELLEXT_ERROR_CAPTION), MB_OK | MB_ICONERROR);
		}

		return false;
	}

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_LABEL, LoadString(IDS_SHELLEXT_LABEL) + _T(":")));
		ATLVERIFY(SetDlgItemText(IDC_STATIC_FILECOUNT, LoadString(IDS_SHELLEXT_FILECOUNT) + _T(":")));
	}


	void InitializeControls()
	{
		ATLVERIFY(SetDlgItemText(IDC_EDIT_LABEL, _strLabel));
		ATLVERIFY(SetDlgItemInt(IDC_EDIT_FILECOUNT, _nFileCount));
	}


	CString GetLabel()
	{
		CString str;

		GetDlgItemText(IDC_EDIT_LABEL, str);
		str.Trim();

		return str;
	}


	// Member variables
	CString _strFilename;
	CString _strLabel;
	UINT    _nFileCount;
};


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

By viewing downloads associated with this article you agree to the Terms of use 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

About the Author

Victor Derks
Architect GE Healthcare
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 | Mobile
Web03 | 2.8.140415.2 | Last Updated 18 Sep 2005
Article Copyright 2005 by Victor Derks
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid