Click here to Skip to main content
Click here to Skip to main content
Go to top

A wrapper class for ITEMIDLIST

, 27 Jan 2003
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

kim-ryo
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 Pinmembernanfang2-Jan-08 4:53 
GeneralRe: Getting file Infotips doesn't work PinmemberEmulator ®9-Oct-09 7:34 
GeneralGreat, Thanks [modified] PinmemberDan Bloomquist24-May-07 9:10 
GeneralGreat. Thanks for your effort PinmemberGautam Jain19-Aug-05 20:07 
GeneralRe: Great. Thanks for your effort PinsussAnonymous23-Oct-05 2:00 
GeneralGood job. Though there're some errors. PinmemberRomanV21-Jan-04 6:09 
GeneralRe: Good job. Though there're some errors. Pinmemberkim-ryo23-Jan-04 22:18 
GeneralVery Good Job! Pinmemberjhwurmbach21-Jan-03 23:27 
GeneralRe: Very Good Job! Pinmemberkim-ryo22-Jan-03 13:56 
Generalmemory leak Pinmemberumeca7421-Jan-03 22:38 
Hi
 
your GetDisplayName method leaks for STRRET_WSTR; the docs aren't very clear about it but the returned wide pOleStr should be freed with shell's allocator after use. See the docs for StrRetToBuf
 
nice class to get people started though!
 
nikos
GeneralRe: memory leak Pinmemberkim-ryo22-Jan-03 13:49 
GeneralRe: memory leak - crash PinmemberOTOM6-Apr-03 11:26 
GeneralRe: memory leak - crash Pinmemberkim-ryo7-Apr-03 18:52 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 28 Jan 2003
Article Copyright 2002 by kim-ryo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid