Click here to Skip to main content
15,898,134 members
Articles / Desktop Programming / MFC

Windows Explorer wildcard selection shell extension

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
28 Sep 200213 min read 195.1K   3.2K   47  
A shell extension to allow you to select files based on a wildcard search
#include "stdafx.h"
#include "resource.h"

#include "Select.h"
#include "CtxMenu.h"
#include "PatternDlg.h"
#include "defs.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////

BEGIN_MESSAGE_MAP(PatternDlg, super)
	//{{AFX_MSG_MAP(PatternDlg)
	ON_CBN_EDITUPDATE(IDC_PATTERN_COMBO, OnComboEdit)
	ON_CBN_SELENDOK(IDC_PATTERN_COMBO, OnComboSelect)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

PatternDlg::PatternDlg(CtxMenu* ctxmenu)
	: super(PatternDlg::IDD, NULL)
{
	this->ctxmenu = ctxmenu;
}

/////////////////////////////////////////////////////////////////////////////

void PatternDlg::DoDataExchange(CDataExchange* pDX)
{
	super::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClickMeNotDlg)
	DDX_Control(pDX, IDC_PATTERN_COMBO, combo);
	DDX_Control(pDX, IDC_HYPERLINK, link);
	//}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////

BOOL PatternDlg::OnInitDialog(void)
{
	super::OnInitDialog();

	link.SetURL(WEBSITE_URL);

	combo.LoadHistory(SETTINGS_KEY, PATTERNS_SETTINGS);

	GetDlgItem(IDOK)->EnableWindow(FALSE);

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////

void PatternDlg::OnOK(void)
{
	combo.AddToHistory();
	combo.SaveHistory(SETTINGS_KEY, PATTERNS_SETTINGS);

	super::OnOK();
}

/////////////////////////////////////////////////////////////////////////////

void PatternDlg::OnComboEdit(void)
{
	CString str;
	combo.GetWindowText(str);
	SelectFiles(str);
}

/////////////////////////////////////////////////////////////////////////////

void PatternDlg::OnComboSelect(void)
{
	int index = combo.GetCurSel();

	if (index != -1)
	{
		CString str;
		combo.GetLBText(index, str);
		SelectFiles(str);
	}
}

/////////////////////////////////////////////////////////////////////////////

void PatternDlg::SelectFiles(CString& str)
{
	if (str.IsEmpty())
	{
		GetDlgItem(IDOK)->EnableWindow(FALSE);
		ctxmenu->RestoreOriginalSelection();
	}
	else
	{
		GetDlgItem(IDOK)->EnableWindow(TRUE);
		ctxmenu->SelectFiles((LPCTSTR) str);
	}
}

/////////////////////////////////////////////////////////////////////////////

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
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions