Reputation: 185
I'm using GetOpenFileName
to open files in C++, is it possible to set the initial dir at "Computer" virtual location with lpstrInitialDir
?
Thanks, Lee.
Upvotes: 1
Views: 1896
Reputation: 807
If you need to support legacy Windows older than Vista, where IFileDialog
is not available, try specifying a Shell folder GUID. For example, the My Computer
GUID is 20D04FE0-3AEA-1069-A2D8-08002B30309D
. You can specify it like this:
ofn.lpstrInitialDir = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
However, it is worth noting that this method is almost doomed to fail on Windows 7 and later, due to behavioral changes
So, you are better off using IFileDialog
on Vista and later instead.
Upvotes: 1
Reputation: 613491
This is not possible with GetOpenFileName
because the location you wish to use is not part of the file system. Rather it is part of the wider shell namespace.
If you look at the documentation for GetOpenFileName
you will see that it has been superseded (over 10 years ago in fact) by the Common Item Dialogs. Those dialogs do allow you to specify the initial folder as a shell item.
Upvotes: 3