Since Windows 2000, the file common dialog was modified to display, on the left, a bar with shortcuts to different default directories. The good part is that this list can be modified, and modifying it does not involve any COM object, only some simple Registry tweaking. In this article, I will explain how to programmatically modify the Registry to display your own list of shortcuts in places bar of the file dialog.
System Settings
It turns out that the folders listed in the Places Bar are specified in Registry, under the HKEY_CURRENT_USER key. The path is:
Software\Microsoft\Windows\CurrentVersion\Policies\ComDlg32\PlacesBar
Folders can be specified in two ways:
- Full path of the folder (type of value is REG_SZ, and data is a string with the path)
- By IDs for a predefined list of folders (type of value is REG_DWORD, and data is an integer representing the ID of the predefined folder)
In the following image, you can see three entries: two integers indicating the Desktop (0) and My Documents (5) and a custom folder “D:\Cilu”.
The name of the values must be of the form PlaceX , where X can have a value from 0 to 4, because a maximum of only five shortcuts are displayed on the Places Bar.
This key does not exist by default. The operating system tries to read this key before displaying a file dialog. If it doesn’t find the key, it loads a default list of folders, the one you probably see on your file dialog. If, however, it finds it, the custom list is used.
This key is system wide. All the applications, except for the ones in the Microsoft Office suite, are affected. If you change (create, delete) this Registry key, all applications displaying a file dialog will have the Places Bar with those folders.
Note: To change the Places Bar for the Microsoft Office application, follow this Knowledge Base article, 826214.
List of IDs for Pre-Defined Folders
The following table displays the list of IDs of the pre-defined folders:
ID (hex) | Predefined Folder |
---|---|
0 | Desktop |
1 | Internet Explorer |
2 | Start Menu\Programs |
3 | My Computer\Control Panel |
4 | My Computer\Printers |
5 | My Documents |
6 | <user name>\Favorites |
7 | Start Menu\Programs\Startup |
8 | <user name>\Recent |
9 | <user name>\SendTo |
a | <desktop>\Recycle Bin |
b | <user name>\Start Menu |
c | logical “My Documents” desktop icon |
d | “My Music” folder |
e | “My Videos” folder |
10 | <user name>\Desktop |
11 | My Computer |
12 | Network Neighborhood (My Network Places) |
13 | <user name>\nethood |
14 | Windows\Fonts |
16 | All Users\Start Menu |
17 | All Users\Start Menu\Programs |
18 | All Users\Startup |
19 | All Users\Desktop |
1a | <user name>\Application Data |
1b | <user name>\PrintHood |
1c | <user name>\Local Settings\Applicaiton Data (nonroaming)0x001d // nonlocalized startup |
1e | Nonlocalized common startup |
1f | Common favorites |
20 | Internet Cache |
21 | Cookies |
22 | History |
23 | All Users\Application Data |
24 | GetWindowsDirectory() |
25 | GetSystemDirectory() |
26 | C:\Program Files |
27 | C:\Program Files\My Pictures |
28 | USERPROFILE |
29 | x86 system directory on RISC |
2a | x86 C:\Program Files on RISC |
2b | C:\Program Files\Common |
2c | x86 Program Files\Common on RISC |
2d | All Users\Templates |
2e | All Users\Documents |
2f | All Users\Start Menu\Programs\Administrative Tools |
30 | <user name>\Start Menu\Programs\Administrative Tools |
31 | Network and Dial-up Connections |
35 | All Users\My Music |
36 | All Users\My Pictures |
37 | All Users\My Video |
38 | Resource Directory |
39 | Localized Resource Directory |
3a | Links to All Users OEM specific apps |
3b | USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning |
Application-Specific Change of Places Bar
As explained earlier, changing the Registry key Software\Microsoft\Windows\CurrentVersion\Policies\ComDlg32\PlacesBar affects all applications installed on a machine (except for the Office applications). If you only want a modified Places Bar for a specific application, a small hack into the Registry can be temporarily done to achieve that.
The Windows API function RegOverridePredefKey allows a programmer to map a pre-defined Registry key to a specified key. Thus, you can do the following:
- Create a temporary key and map it for the HKEY_CURRENT_USER
- Put the file dialog places there under Software\Microsoft\Windows\CurrentVersion\Policies\ComDlg32\PlacesBar
- Display the file dialog
- At the end, restore the predefined HKEY_CURRENT_USER and delete the temporary key
I have put all this together into a sample applications that allows you to select five custom places from the predefined folders list or any folder on disk. The application looks like the one in this screenshot:
Note: To select a custom folder, use the Browse… item at the bottom of each combo box item list.
Creating a temporary key and mapping it on HKEY_CURRENT_USER
The SnatchRegistry() function creates a temporary Registry key (in my application, called “MariusBancila”) and calls RegOverridePredefKey to map it on HKEY_CURRENT_USER. It returns a handle to that key:
HKEY CDemoOpenFileDlg::SnatchRegistry()
{
HKEY hTempKey;
// create a temporary Registry key
RegCreateKey(HKEY_CURRENT_USER, TEMP_REG_KEY, &hTempKey);
// override the current user with the new created key
RegOverridePredefKey(HKEY_CURRENT_USER, hTempKey);return hTempKey;
}