Author: Jonas Bilinkevicius
In a TOpenDialog, you can set the initial directory. How do I set it as the
desktop? I could set it as c:\windows\desktop, but then what if Windows is not on
the user's c drive?
There is a shell function that can be used to inquire about the location of several
shell-related folders. You need to add ShlObj to the uses clause for this, plus
ActiveX for the CoTaskMemFree.
1 procedure FreePidl(pidl: PItemIDList);
2 begin3 CoTaskMemFree(pidl);
5 6 procedure TForm1.Button2Click(Sender: TObject);
7 var8 pidl: PItemIDList;
9 buf: array[0..MAX_PATH] of Char;
10 begin11 if Succeeded(ShGetSpecialFolderLocation(Handle, CSIDL_DESKTOP, pidl)) then12 begin13 if ShGetPathfromIDList(pidl, buf) then14 ShowMessage(buf);
See win32.hlp (or better msdn.microsoft.com, the list has been extended for Win98/2000) for a list of CSIDL values. There is also a newer ShGetSpecialFolderPath API that directly returns the path, but it is not available on older Win95 and NT installations.