Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get special Windows folder location (2) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
15-Sep-02
Category
Files Operation
Language
Delphi 2.x
Views
52
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert

How to get special Windows folder location

Answer:

The two key functions to browse through those virtual Windows folders are

SHGetSpecialFolderLocation();

and

SHGetPathFromIDList()

They can be used as shown in the sample code. You may replace the CSIDL_PROGRAMS 
constant with another one from the list in the comment below.

1   uses ShlObj, ActiveX;
2   
3   procedure TForm1.Button1Click(Sender: TObject);
4   var
5     BI: TBrowseInfo;
6     Buf: PChar;
7     Dir,
8       Root: PItemIDList;
9     Alloc: IMalloc;
10  begin
11    SHGetMalloc(Alloc);
12    Buf := Alloc.Alloc(Max_Path);
13  
14    // CSIDL_BITBUCKET  RecycleBin
15    // CSIDL_CONTROLS   ControlPanel
16    // CSIDL_DESKTOP    Desktop
17    // CSIDL_DRIVES     My Computer
18    // CSIDL_FONTS      Fonts
19    // CSIDL_NETHOOD    Network Neighborhood
20    // CSIDL_NETWORK    The virtual version of the above
21    // CSIDL_PERSONAL   'Personal'
22    // CSIDL_PRINTERS   printers
23    // CSIDL_PROGRAMS   Programs in the Start Menu
24    // CSIDL_RECENT     Recent Documents
25    // CSIDL_SENDTO     Folder SendTo
26    // CSIDL_STARTMENU  The whole Start menu
27    // CSIDL_STARTUP    The Autostart Group
28    // CSIDL_TEMPLATES  Document templates
29  
30    // use of the constants above
31    SHGetSpecialFolderLocation(Handle, CSIDL_PROGRAMS, Root);
32  
33    with BI do
34    begin
35      hwndOwner := Form1.Handle;
36      // NIL means show all
37      pidlRoot := Root;
38      pszDisplayName := Buf;
39      lpszTitle := 'Choose Folder';
40      ulFlags := 0;
41      lpfn := nil;
42    end;
43  
44    try
45      Dir := SHBrowseForFolder(BI);
46      if Dir <> nil then
47      begin
48        SHGetPathFromIDList(Dir, Buf);
49        ShowMessage(Buf);
50        Alloc.Free(Dir);
51      end;
52    finally
53      Alloc.Free(Root);
54      Alloc.Free(Buf);
55    end;
56  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC