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 the Windows Start Menu folder location and name 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
10-Oct-02
Category
Files Operation
Language
Delphi 2.x
Views
159
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to get the Start Menu folder location in Windows regardless of the OS (WinNT 
Wks, WinNT Srv, Win95, Win98)?

Answer:

Solve 1:
1   
2   procedure FreePidl(pidl: PItemIDList);
3   var
4     allocator: IMalloc;
5   begin
6     if Succeeded(SHGetMalloc(allocator)) then
7     begin
8       allocator.Free(pidl);
9   {$IFDEF VER90}
10      allocator.Release;
11  {$ENDIF}
12    end;
13  end;
14  
15  procedure TForm1.Button2Click(Sender: TObject);
16  var
17    pidl: PItemIDList;
18    buf: array[0..MAX_PATH] of Char;
19  begin
20    if Succeeded(ShGetSpecialFolderLocation(Handle, CSIDL_STARTMENU, pidl)) then
21    begin
22      if ShGetPathfromIDList(pidl, buf) then
23        ShowMessage(buf);
24      FreePIDL(pidl);
25    end;
26  end;


Needs ShlObj in the Uses clause.


Solve 2:

To obtain the name of the Windows\Start Menu\Program directory on a system, use 
code like this:
27  
28  function GetSpecialDir(Index: Integer): string;
29  var
30    S: string;
31    IDL: PItemIDList;
32  begin
33    Result := '';
34    if Succeeded(SHGetSpecialFolderLocation(0, Index, IDL)) then
35    begin
36      SetLength(S, MAX_PATH);
37      if Succeeded(SHGetPathFromIDList(IDL, PChar(S))) then
38        Result := PChar(S);
39    end;
40  end;


You call it with code like:

ProgDir := GetSpecialDir(CSIDL_PROGRAMS);

The CSIDL_ identifiers are specified in ShlObj.pas, so are the 
SHGetSpecialFolderLocation and SHGetPathFromIDList functions.


Solve 3:

Here is an example to get the startup folder:
41  
42  { ... }
43  var
44    idRoot: PItemIDList;
45    Buf: array[1..MAX_PATH] of Char;
46  begin
47    StartupFolder := '';
48    try
49      if SHGetSpecialFolderLocation(Handle, CSIDL_STARTUP, idRoot) = NOERROR then
50      begin
51        FillChar(Buf, SizeOf(Buf), #32);
52        SHGetPathFromIDList(idRoot, PChar(@Buf));
53        SetString(StartupFolder, PChar(@Buf), Length(Buf));
54        StartupFolder := Trim(StartupFolder) + '\';
55      end;
56    except
57    end;
58  end;
59  { ... }


			
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