Click here to Skip to main content
15,867,686 members
Articles / Desktop Programming / MFC
Article

A wrapper class for ITEMIDLIST

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
27 Jan 2003Zlib2 min read 80.3K   1.5K   16   13
CItemIDList class helps manage ITEMIDLIST more easily

Introduction

This is a class helps you manage ITEMIDLIST easier.

The 
  CItemIDList
class holds a pointer to a ITEMIDLIST structure (the pointer is in CItemIDList::m_pidl). It also has public static member functions which you can use as global functions.(Version 2.0)

Constructors

CItemIDList(LPCTSTR pcszPath);   

Construct with a path string.

CItemIDList(LPITEMIDLIST pidl);   

Construct with LPITEMIDLIST.(Copy it,and free on destruct)

CItemIDList(CItemIDList& iidl);   

Construct with another class object.

CItemIDList(void);   

Construct class instance with m_pidl empty.

Member functions

int GetIconIndex(void) const;

Get folder item's icon index in system image list.

BOOL GetDisplayName(LPTSTR pszBuf,DWORD dwFlags=SHGDN_NORMAL) 
            const;   

Retrieve pidl's dislpay name.

CItemIDList Duplicate(UINT nCount=-1) const;   

Copy a pidl due to the count number.

inline BOOL IsEmpty(void) const;   

Whether m_pidl is NULL.

CItemIDList GetAt(UINT nIndex) const;   

Return a relative pidl at specified index.

BOOL Create(LPITEMIDLIST pidlf);   

Create from a LPITEMIDLIST.

inline UINT GetCount(void) const;   

Get pidl count.

inline UINT GetSize(void) const;   

Get pidl's size,in byte.

inline void Empty(void);   

Free m_pidl and set to NULL.

void GetPath(LPTSTR pszPath) const;   

Retrieve full path.(only available for full-quality pidl)

inline HRESULT GetUIObjectOf(REFIID riid,LPVOID* ppOut,HWND 
            hWnd=NULL);   

Retrieve other shell interface.Same as IShellFolder::GetUIObjectOf.

inline void Split(LPSHELLFOLDER& lpsf,CItemIDList& 
            ciid) const;   

Get IShellFolder interface and the tail pidl cell from a full-quality pidl.

CItemIDList GetLastPidl(void) const;  

Retrieve the tail pidl cell.

void GetToolTipInfo(LPTSTR pszToolTip,UINT cbSize) const;  

Retrieve the tooltip info of the m_pidl.

void Attach(LPITEMIDLIST pidl);  

Attach a pidl.

LPITEMIDLIST Detach(void); 

Detach a pidl.

Operators

CItemIDList operator+(CItemIDList& piidl);   

Concat two pidls.

operator LPITEMIDLIST(void) const;   

Get m_pidl.

operator LPCITEMIDLIST(void) const;   

Get m_pidl convert to LPCITEMIDLIST.

const CItemIDList& operator=(CItemIDList& ciidl1);   

Copy from another class instance.

const CItemIDList& operator=(LPITEMIDLIST pidl);   

Copy from a LPITEMIDLIST.

operator+=(CItemIDList& ciidl);   

Add a new pidl to m_pidl's tail.

BOOL operator==(CItemIDList& ciidl);   

Query whether two pidl's name is same.

CItemIDList operator[](UINT nIndex);   

Return a relative pidl at specified index.(Same as

CItemIDList::GetAt(UINT 
            nIndex)
)

Example

#include "ItemIDList.h"
#include <windows.h>
#include <iostream.h>

//Some test code...
void main()
{
	char szFile[MAX_PATH];
	ZeroMemory(szFile,MAX_PATH);

	OPENFILENAME info;
	ZeroMemory(&info,sizeof(info));

	info.lStructSize=sizeof(info);
	info.lpstrFile=szFile;
	info.hwndOwner=NULL;
	info.nMaxFile=MAX_PATH;

	if(GetOpenFileName(&info))
	{
		CItemIDList item(szFile),item2;
		char szName[MAX_PATH];
		item.GetDisplayName(szName);
		cout<<szName<<endl;

		item.GetToolTipInfo(szName,MAX_PATH);
		cout<<szName<<endl;

		item2=item;
		item2.GetPath(szName);
		cout<<szName<<endl;

		item2=item[item.GetCount()-1];
		item2.GetDisplayName(szName);
		cout<<szName<<endl;

		item2=item.GetAt(0);
		item2.GetDisplayName(szName);
		cout<<szName<<endl;

		CItemIDList item3;
		item3=item.Duplicate(item.GetCount()-1);
		item3.GetPath(szName);
		cout<<szName<<endl;

		item3=item.Duplicate(item.GetCount()-1)+item2;
		item3.GetPath(szName);
		cout<<szName<<endl;
	}
}

Enjoy...

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License


Written By
Architect
China China
kim-ryo is a lord of creation as his own thoughts.

http://z-soft.net

Comments and Discussions

 
GeneralGetting file Infotips doesn't work Pin
nanfang2-Jan-08 4:53
nanfang2-Jan-08 4:53 
GeneralRe: Getting file Infotips doesn't work Pin
Emulator ®9-Oct-09 7:34
Emulator ®9-Oct-09 7:34 
GeneralGreat, Thanks [modified] Pin
Dan Bloomquist24-May-07 9:10
Dan Bloomquist24-May-07 9:10 
GeneralGreat. Thanks for your effort Pin
Gautam Jain19-Aug-05 20:07
Gautam Jain19-Aug-05 20:07 
GeneralRe: Great. Thanks for your effort Pin
Anonymous23-Oct-05 2:00
Anonymous23-Oct-05 2:00 
Should be no.Smile | :)
GeneralGood job. Though there're some errors. Pin
Member 46289721-Jan-04 6:09
Member 46289721-Jan-04 6:09 
GeneralRe: Good job. Though there're some errors. Pin
kim-ryo23-Jan-04 22:18
kim-ryo23-Jan-04 22:18 
GeneralVery Good Job! Pin
jhwurmbach21-Jan-03 23:27
jhwurmbach21-Jan-03 23:27 
GeneralRe: Very Good Job! Pin
kim-ryo22-Jan-03 13:56
kim-ryo22-Jan-03 13:56 
Generalmemory leak Pin
umeca7421-Jan-03 22:38
umeca7421-Jan-03 22:38 
GeneralRe: memory leak Pin
kim-ryo22-Jan-03 13:49
kim-ryo22-Jan-03 13:49 
GeneralRe: memory leak - crash Pin
otom6-Apr-03 11:26
otom6-Apr-03 11:26 
GeneralRe: memory leak - crash Pin
kim-ryo7-Apr-03 18:52
kim-ryo7-Apr-03 18:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.