Recent

Author Topic: Set InitialDir/RootDir for Dialogs to My Computer/This PC  (Read 1160 times)

hgdagon

  • New Member
  • *
  • Posts: 10
Set InitialDir/RootDir for Dialogs to My Computer/This PC
« on: June 04, 2020, 11:57:56 pm »
I've been searching for this for a while now, and, apparently I should be using SHGetKnownFolderPath, but it seems there's no way to do so in Lazarus?

I tried using alternatives, i.e. CSIDL_DRIVES, but that doesn't work either.

TRon

  • Hero Member
  • *****
  • Posts: 2538
Re: Set InitialDir/RootDir for Dialogs to My Computer/This PC
« Reply #1 on: June 05, 2020, 12:09:51 am »
Free Pascal, package winunits-base, unit shlobj.pp

Free Pascal is part of lazarus and that package is include by default. You can apply the msn documentation in order to use that function.

hgdagon

  • New Member
  • *
  • Posts: 10
Re: Set InitialDir/RootDir for Dialogs to My Computer/This PC
« Reply #2 on: June 05, 2020, 12:44:55 am »
Can you give an example? The unit is included, the application builds just fine, yet the result is not the my computer directory.
In the meantime I found SHGetFolderPathUTF8 from LazFileUtils, but that also doesn't return the My Computer/This PC "directory".

To be perfectly clear, I'm only having a problem getting My Computer/This PC, others (seemingly, only those found in windirs, but haven't checked every single one) work fine. CSIDL_DRIVES (or FOLDERID_ComputerFolder) doesn't work.

TRon

  • Hero Member
  • *****
  • Posts: 2538
Re: Set InitialDir/RootDir for Dialogs to My Computer/This PC
« Reply #3 on: June 05, 2020, 01:47:41 am »
Can you give an example?
Nope !  :)

I can do better than that by providing a link on the subject, see below

Quote
The unit is included, the application builds just fine, yet the result is not the my computer directory.
Which result ? What code ? What OS ? What are you expecting ?

Let me take a wild guess, you were expecting to have that function to return an actual physical directory/path ?

Quote
In the meantime I found SHGetFolderPathUTF8 from LazFileUtils, but that also doesn't return the My Computer/This PC "directory".
That is correct. It simply can't return a directory as it is a virtual folder, as can be read from msdn documentation with regards to that specific id.

Quote
To be perfectly clear, I'm only having a problem getting My Computer/This PC, others (seemingly, only those found in windirs, but haven't checked every single one) work fine. CSIDL_DRIVES (or FOLDERID_ComputerFolder) doesn't work.
Oh, there are others that are virtual and don't return an actual physical directory  ;)

You can make a search on this forum (as other went before you) but better have a look here: https://stackoverflow.com/questions/55595111/how-to-get-my-computer-virtual-folder-path

hgdagon

  • New Member
  • *
  • Posts: 10
Re: Set InitialDir/RootDir for Dialogs to My Computer/This PC
« Reply #4 on: June 05, 2020, 04:39:47 pm »
Thanks, everybody, for responding. Unfortunately, I couldn't figure out any of those, so I kept searching, and I found an old post with the correct GUID to use

Code: Pascal  [Select][+][-]
  1. {20D04FE0-3AEA-1069-A2D8-08002B30309D}

So, I can use:

Code: Pascal  [Select][+][-]
  1. SelectDirectoryDialog1.InitalDir:='::{20D04FE0-3AEA-1069-A2D8-08002B30309D}';
  2. DirectoryEdit1.Rootdir:='::{20D04FE0-3AEA-1069-A2D8-08002B30309D}';

Depending on the control I'm using.

 

TinyPortal © 2005-2018