Click here to Skip to main content
15,881,516 members
Articles / Desktop Programming / ATL

Classic Shell

Rate me:
Please Sign up or sign in to vote.
4.99/5 (135 votes)
23 Feb 2010MIT33 min read 952.3K   10K   195  
Classic Start menu and other shell features for Windows 7 and Vista.
// Classic Shell (c) 2009-2010, Ivo Beltchev
// The sources for Classic Shell are distributed under the MIT open source license

#pragma once

#include <map>

// CIconManager - global cache for icons

class CIconManager
{
public:
	~CIconManager( void );

	static int LARGE_ICON_SIZE;
	static int SMALL_ICON_SIZE;
	HIMAGELIST m_LargeIcons;
	HIMAGELIST m_SmallIcons;

	// Initializes the manager. Called from DllMain
	void Init( void );

	// Retrieves an icon from a shell folder and child ID
	int GetIcon( IShellFolder *pFolder, PCUITEMID_CHILD item, bool bLarge );
	// Retrieves an icon from a file and icon index (index>=0 - icon index, index<0 - resource ID)
	int GetIcon( const wchar_t *location, int index, bool bLarge );
	// Retrieves an icon from shell32.dll by resource ID
	int GetStdIcon( int id, bool bLarge );
	// Retrieves an icon for a custom menu item
	int GetCustomIcon( const wchar_t *path, bool bLarge );

	// Must be called when the start menu is about to be unloaded
	void StopPreloading( bool bWait );

	static int GetDPI( void ) { return s_DPI; }

private:
	std::map<unsigned int,int> m_LargeCache;
	std::map<unsigned int,int> m_SmallCache;

	HANDLE m_PreloadThread;

	void ProcessPreloadedIcons( void );

	static int s_DPI;
	static bool s_bStopLoading;
	static std::map<unsigned int,HICON> s_PreloadedIcons; // queue of preloaded icons ready to be added to the image list
	static CRITICAL_SECTION s_PreloadSection; // protects all access to m_SmallCache and s_PreloadedIcons

	static DWORD CALLBACK PreloadThread( void *param );
	static void LoadFolderIcons( IShellFolder *pFolder, int level );
};

extern CIconManager g_IconManager;

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, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior)
United States United States
Ivo started programming in 1985 on an Apple ][ clone. He graduated from Sofia University, Bulgaria with a MSCS degree. Ivo has been working as a professional programmer for over 12 years, and as a professional game programmer for over 10. He is currently employed in Pandemic Studios, a video game company in Los Angeles, California.

Comments and Discussions