Click here to Skip to main content
Licence Zlib
First Posted 12 Sep 2002
Views 55,811
Bookmarked 14 times

A wrapper class for ITEMIDLIST

By | 27 Jan 2003 | Article
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

About the Author

kim-ryo

Architect

China China

Member

kim-ryo is a lord of creation as his own thoughts.
 
http://z-soft.net

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGetting file Infotips doesn't work Pinmembernanfang4:53 2 Jan '08  
GeneralRe: Getting file Infotips doesn't work PinmemberEmulator ®7:34 9 Oct '09  
GeneralGreat, Thanks [modified] PinmemberDan Bloomquist9:10 24 May '07  
GeneralGreat. Thanks for your effort PinmemberGautam Jain20:07 19 Aug '05  
GeneralRe: Great. Thanks for your effort PinsussAnonymous2:00 23 Oct '05  
GeneralGood job. Though there're some errors. PinmemberRomanV6:09 21 Jan '04  
GeneralRe: Good job. Though there're some errors. Pinmemberkim-ryo22:18 23 Jan '04  
GeneralVery Good Job! Pinmemberjhwurmbach23:27 21 Jan '03  
GeneralRe: Very Good Job! Pinmemberkim-ryo13:56 22 Jan '03  
Generalmemory leak Pinmemberumeca7422:38 21 Jan '03  
GeneralRe: memory leak Pinmemberkim-ryo13:49 22 Jan '03  
GeneralRe: memory leak - crash PinmemberOTOM11:26 6 Apr '03  
GeneralRe: memory leak - crash Pinmemberkim-ryo18:52 7 Apr '03  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 28 Jan 2003
Article Copyright 2002 by kim-ryo
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid