Click here to Skip to main content
15,892,005 members
Articles / Desktop Programming / MFC

"Browse For Folder" dialog alike with source

Rate me:
Please Sign up or sign in to vote.
4.60/5 (5 votes)
5 Sep 2001 114.9K   1.7K   38  
Shell interfaces in use. IShellFolder, IEnumIDList, etc.
// BFFTreeCtrl.cpp : implementation file
//
// Written by Marat Bedretdinov (maratb@hotmail.com)
// Copyright (c) 2000.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name is included. 
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage whatsoever.
// It's free - so you get what you pay for.//


#include "stdafx.h"
#include "exports.h"

#include "BFFTreeCtrl.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBFFTreeCtrl

CBFFTreeCtrl::CBFFTreeCtrl():
  m_pFullIdl(0),
  m_pRelativeIdl(0)
{
}

CBFFTreeCtrl::~CBFFTreeCtrl()
{
  SHFree(m_pFullIdl);
  SHFree(m_pRelativeIdl);
}


BEGIN_MESSAGE_MAP(CBFFTreeCtrl, CFileTreeCtrl)
	//{{AFX_MSG_MAP(CBFFTreeCtrl)
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


void CBFFTreeCtrl::SaveSelectedInfo()
{
  SHFree(m_pFullIdl);
  SHFree(m_pRelativeIdl);
 // remember the selected item's full and relative pidl first
  m_pFullIdl = SHCopyIdl(GetSelectedFullIdl());
  m_pRelativeIdl = SHCopyIdl(GetSelectedRelativeIdl());
}

////////////////////////////////////////////////////////////////////
// returns a copy of selected full qulified idl
////////////////////////////////////////////////////////////////////

LPITEMIDLIST CBFFTreeCtrl::GetTreeSelectedFullIdl()
{
// if the dialog has been visually destroyed
  if (!GetSafeHwnd())
	return SHCopyIdl(m_pFullIdl);
// otherwise get it from the tree control
  return SHCopyIdl(GetSelectedFullIdl());
}

////////////////////////////////////////////////////////////////////
// returns a copy of selected relative idl
////////////////////////////////////////////////////////////////////

LPITEMIDLIST CBFFTreeCtrl::GetTreeSelectedRelativeIdl()
{
// if the dialog has been visually destroyed
  if (!GetSafeHwnd())
	return SHCopyIdl(m_pRelativeIdl);
// otherwise get it from the tree control
  return SHCopyIdl(GetSelectedRelativeIdl());
}

const char*	CBFFTreeCtrl::GetSelectedPath() const
{
  return m_strPath;
}

const char*	CBFFTreeCtrl::GetSelectedName() const
{
  return m_strName;
}

void CBFFTreeCtrl::DisplaySelectedPath() 
{
  HTREEITEM hClickedItem = GetSelectedItem();
  ITreeNode* pNode = (ITreeNode*)GetItemData(hClickedItem);
  if (!pNode->IsSystemDirectory()) return;
  m_strPath = pNode->GetPath();
  m_strName = pNode->GetName();
  GetParent()->SetDlgItemText(IDED_PATH, m_strPath);
}

/////////////////////////////////////////////////////////////////////////////
// CBFFTreeCtrl message handlers

void CBFFTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
  CFileTreeCtrl::OnLButtonDown(nFlags, point);
  DisplaySelectedPath();
}

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



Comments and Discussions