Re: Common Dialog questions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



You can always retrieve the user's settings using the CSIDL constants ...
there is full listing under the CSIDL item at
http://vbnet.mvps.org/code/browse/index.html ; here's the basics of one
method with using these values:

Option Explicit

Private Const MAX_LENGTH = 260
Private Const S_OK = 0
Private Const SHGFP_TYPE_CURRENT = &H0

Private Declare Function SHGetFolderPath _
Lib "shfolder.dll" Alias "SHGetFolderPathA" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
ByVal hToken As Long, _
ByVal dwReserved As Long, _
ByVal lpszPath As String) As Long


Private Sub Command1_Click()

Const CSIDL_DESKTOPDIRECTORY = &H10
Debug.Print GetFolderPath(CSIDL_DESKTOPDIRECTORY)

End Sub


Private Function GetFolderPath(CSIDL As Long) As String

Dim sPath As String
Dim sTmp As String

'fill pidl with the specified folder item
sPath = Space$(MAX_LENGTH)

If SHGetFolderPath(Me.hWnd, CSIDL, 0&, SHGFP_TYPE_CURRENT, sPath) = S_OK
Then
sTmp = Left$(sPath, InStr(sPath, Chr$(0)) - 1)
End If

GetFolderPath = sTmp

End Function


> C:\Documents and Settings\birchr\Desktop


There's also a way to directly set the directory in the common dialog by
specifying the actual registry value (CLSID) for the particular item.
Unfortunately though, while I can locate the Desktop value, this refers to
the virtual desktop folder and not that of the file system, so navigation
using that value will not work. The others listed here, however, do,
depending of course on the OS for some of the later items.

Private Sub Command2_Click()

With CommonDialog1
' .InitDir = "::{1f4de370-d627-11d1-ba4f-00a0c91eedba}" 'Computer
Search Results Folder
' .InitDir = "::{645FF040-5081-101B-9F08-00AA002F954E}" 'Recycle Bin
' .InitDir = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}" 'my docs
' .InitDir = "::{e17d4fc0-5564-11d1-83f2-00a0c90dc849}" 'Search
Results Folder
' .InitDir = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" 'my computer
' .InitDir = "::{7007ACC7-3202-11D1-AAD2-00805FC1270E}" 'Network
Connections
' .InitDir = "::{D20EA4E1-3957-11d2-A40B-0C5020524152}" 'fonts
' .InitDir = "::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}" 'Scheduled
Tasks
' .InitDir = "::{E211B736-43FD-11D1-9EFB-0000F8757FCD}" 'Scanners &
Cameras
' .InitDir = "::{208D2C60-3AEA-1069-A2D7-08002B30309D}" 'my network
places
.InitDir = "::{00021400-0000-0000-C000-000000000046}" 'desktop
(virtual, not disk)
.ShowOpen
End With

End Sub



--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------



"Steve Easton" <admin@xxxxxxxxxxxxx> wrote in message
news:uFuTpNQVFHA.3280@xxxxxxxxxxxxxxxxxxxxxxx
: Using a getfile.ShowOpen common dialog:
:
: 1. Is there a common string I can use for getfile.InitDir that will open
the desktop in both 9x and
: 2K / XP
: I know that: C:Windows\Desktop will do it in 9x, and
%UserProfile%\Desktop will do it in 2K / XP.
: Is there something common to both??
:
: 2. Is there a way to change the text on the Open button so that the open
button reads: Add, Lock or
: Unlock depending upon which function the user is performing??
:
: As always, many thanks in advance.
:
: ;-)
:
: --
: Steve Easton
: Microsoft MVP FrontPage
: 95isalive
: This site is best viewed............
: .......................with a computer
:
:

.



Relevant Pages

  • Re: Hard Drive Folder Size
    ... The drive and folder will always be the same. ... Private Declare Sub CopyMemory Lib "kernel32" _ ... (ByVal lItem As Long, ByVal sDir As String) ... Dim s1 As String, sectorsPerCluster As Long, bytesPerSector As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Bytes per Sector
    ... click on a folder and choose Properties. ... Private Declare Sub CopyMemory Lib "kernel32" _ ... (ByVal lItem As Long, ByVal sDir As String) ... Dim s1 As String, sectorsPerCluster As Long, bytesPerSector As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Bytes per Sector
    ... click on a folder and choose Properties. ... Private Declare Sub CopyMemory Lib "kernel32" _ ... (ByVal lItem As Long, ByVal sDir As String) ... Dim s1 As String, sectorsPerCluster As Long, bytesPerSector As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Fast Size Folder
    ... as far as I know that is exactly what Windows itself does when you right click a folder and choose Properties. ... Private Declare Sub CopyMemory Lib "kernel32" _ ... ByVal sDir As String) As Long ... Dim s1 As String, sectorsPerCluster As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Hard Drive Folder Size
    ... The drive and folder will always be the same. ... Private Declare Sub CopyMemory Lib "kernel32" _ ... (ByVal lItem As Long, ByVal sDir As String) ... Dim s1 As String, sectorsPerCluster As Long, bytesPerSector As Long ...
    (microsoft.public.vb.general.discussion)