Articles   Members Online:
-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 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
22-Jul-02
Category
Win API
Language
Delphi 2.x
Views
24
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

How to get special Windows folder location

Answer:

Solve 1:

1   uses
2   ...ShlObj...
3   
4   var
5   SFolder: pItemIDList;
6   SpecialPath: array[0..MAX_PATH] of Char;
7   begin
8   	SHGetSpecialFolderLocation(Form1.Handle, CSIDL_STARTUP, SFolder);
9   	SHGetPathFromIDList(SFolder, SpecialPath);
10    Label1.Caption := StrPas(SpecialPath);
11  end;

Other folders :
CSIDL_BITBUCKET
CSIDL_CONTROLS
CSIDL_DESKTOP - WINDOWS\Desktop 
CSIDL_DESKTOPDIRECTORY - WINDOWS\Desktop
CSIDL_DRIVES
CSIDL_FONTS - WINDOWS\FONTS
CSIDL_NETHOOD - WINDOWS\NetHood
CSIDL_NETWORK
CSIDL_PERSONAL - X:\My Documents 
CSIDL_PRINTERS
CSIDL_PROGRAMS - WINDOWS\StartMenu\Programs
CSIDL_RECENT - WINDOWS\Recent
CSIDL_SENDTO - WINDOWS\SendTo
CSIDL_STARTMENU - WINDOWS\Start Menu 
CSIDL_STARTUP - WINDOWS\Start Menu\Programs\StartUp
CSIDL_TEMPLATES - WINDOWS\ShellNew


Solve 2:

12  function WinAPI_GetWindowsDirectory: string;
13  begin
14    SetLength(Result, MAX_PATH);
15    SetLength(Result, GetWindowsDirectory(pchar(Result), MAX_PATH));
16  end;
17  
18  function WinAPI_GetSystemDirectory: string;
19  begin
20    SetLength(Result, MAX_PATH);
21    SetLength(Result, GetSystemDirectory(pchar(Result), MAX_PATH));
22  end;
23  
24  //In fact you can get just about every special folder location
25  
26  function WinAPI_SHGetSpecialFolderLocation(nFolder: integer): string;
27  var
28    pidl: PItemIDList;
29  begin
30    SHGetSpecialFolderLocation(0, nFolder, pidl);
31    SetLength(Result, MAX_PATH);
32    SHGetPathFromIDList(pidl, pchar(Result));
33    SetLength(Result, pchar_StrLen(pchar(Result)));
34  end;



Solve 3:

35  function GetSystemPath(Folder: Integer): string;
36  var
37    PIDL: PItemIDList;
38    Path: LPSTR;
39    AMalloc: IMalloc;
40  begin
41    Path := StrAlloc(MAX_PATH);
42    SHGetSpecialFolderLocation(Application.Handle, Folder, PIDL);
43    if SHGetPathFromIDList(PIDL, Path) then
44      Result := Path;
45    SHGetMalloc(AMalloc);
46    AMalloc.Free(PIDL);
47    StrDispose(Path);
48  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