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
Shell API
Language
Delphi 2.x
Views
140
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   procedure FreePidl(pidl: PItemIDList);
2   var
3     allocator: IMalloc;
4   begin
5     if Succeeded(SHGetMalloc(allocator)) then
6     begin
7       allocator.Free(pidl);
8   {$IFDEF VER90}
9       allocator.Release;
10  {$ENDIF}
11    end;
12  end;
13  
14  procedure TForm1.Button2Click(Sender: TObject);
15  var
16    pidl: PItemIDList;
17    buf: array[0..MAX_PATH] of Char;
18  begin
19    if Succeeded(ShGetSpecialFolderLocation(Handle, CSIDL_STARTMENU, pidl)) then
20    begin
21      if ShGetPathfromIDList(pidl, buf) then
22        ShowMessage(buf);
23      FreePIDL(pidl);
24    end;
25  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:
26  
27  function GetSpecialDir(Index: Integer): string;
28  var
29    S: string;
30    IDL: PItemIDList;
31  begin
32    Result := '';
33    if Succeeded(SHGetSpecialFolderLocation(0, Index, IDL)) then
34    begin
35      SetLength(S, MAX_PATH);
36      if Succeeded(SHGetPathFromIDList(IDL, PChar(S))) then
37        Result := PChar(S);
38    end;
39  end;


You call it with code like:
40  
41  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:

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