gmnt
asked on
Finding the Windows Desktop Directory
Is there a quick one-line way of finding the Windows Desktop Directory so that an application can save a file to it independent of directory structure. e.g. c:\windows\desktop, or c:\windows\users\frank\des ktop etc..???
Looking for an answer asap on this so am prepared to offer 400 points for this one.
Looking for an answer asap on this so am prepared to offer 400 points for this one.
and here's another one:
function GetDesktopFolder: String;
var
Buffer: array[0..MAX_PATH] of Char;
PIDL: PItemIDList;
begin
SHGetSpecialFolderLocation (Handle, CSIDL_DESKTOP, PIDL);
SHGetPathFromIDList(PIDL, Buffer);
Result := Buffer;
end;
Ciao, Mike
function GetDesktopFolder: String;
var
Buffer: array[0..MAX_PATH] of Char;
PIDL: PItemIDList;
begin
SHGetSpecialFolderLocation
SHGetPathFromIDList(PIDL, Buffer);
Result := Buffer;
end;
Ciao, Mike
ASKER
How does this react if, for example, the PC has multiple users and there are a number of desktop folders? Does it use the desktop of the currently active user i.e. the one actually logged in and running the application?
Yep, the folder of the currently logged in user is returned.
Ciao, Mike
Ciao, Mike
ASKER
I think the first one is easier to understand - Are there any specifics I need e.g. in "uses" etc or just declare the function at the top?
Nothing special to consider. Just take in Registry into the uses clause and copy the code out. Btw: the second code is not much harder than the first one. You need to include ShlObj and with this SHGet* stuff you are independent of eventual changes Microsoft makes to the registry in future Windows versions.
Ciao, Mike
Ciao, Mike
ASKER
I'm getting errors:
Undeclared identifier: 'Handle'
Unsatisfied forward or external declaration: 'TfrmMain.GetDesktopFolder '
I've included ShlObj and have declared the function with all the others:
procedure btnAboutClick(Sender: TObject);
procedure cmbSlot1Change(Sender: TObject);
function GetDesktopFolder: String;
private
{ Private declarations }
Any suggestions (btw using Delphi 4)
Undeclared identifier: 'Handle'
Unsatisfied forward or external declaration: 'TfrmMain.GetDesktopFolder
I've included ShlObj and have declared the function with all the others:
procedure btnAboutClick(Sender: TObject);
procedure cmbSlot1Change(Sender: TObject);
function GetDesktopFolder: String;
private
{ Private declarations }
Any suggestions (btw using Delphi 4)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I needed an answer fast, and got it.
A nice quick and clean answer - much appreciated.
Garth.
A nice quick and clean answer - much appreciated.
Garth.
I'm always glad to help (in particular when so many points are involved ;-)).
Good luck until next time,
Ciao, Mike
Good luck until next time,
Ciao, Mike
function GetDesktopFolderName: String;
var
AReg: TRegIniFile;
begin
Result := '';
AReg := TRegIniFile.Create('Softwa
Result := AReg.ReadString('Shell Folders', 'Desktop', '');
AReg.Free;
end;
Ciao, Mike