?
Solved

How to put the Desktop object in a DriveListBox

Posted on 2003-03-04
4
Medium Priority
?
233 Views
Last Modified: 2013-12-26
I have a custom dialog that includes Drive, Folder and File list boxes.  It would be nice to have the Desktop, My Documents and Network objects appear in the list as they do in the common dialog controls.

Is it possible to add objects to DriveListBox or is there another function that already has this ability?



Something like the browse folder dialog would also work but I'd need it to exist as an object in my form rather than in it's own dialog box.  And I don't think you can do things like that when calling a shell object.

This is being attempted in VB6.

Thanks
0
Comment
Question by:vbncsu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Expert Comment

by:happel
ID: 8080006
'NOTE, code is not mine, copied from other vb-site
'I don't know the name of the author.


Private Type BrowseInfo
  hWndOwner As Long
  pIDLRoot As Long
  pszDisplayName As Long
  lpszTitle As Long
  ulFlags As Long
  lpfnCallback As Long
  lParam As Long
  iImage As Long
End Type


'Browsing type.
Public Enum BrowseType
  BrowseForFolders = &H1
  BrowseForComputers = &H1000
  BrowseForPrinters = &H2000
  BrowseForEverything = &H4000
End Enum

'Folder Type
Public Enum FolderType
  CSIDL_BITBUCKET = 10
  CSIDL_CONTROLS = 3
  CSIDL_DESKTOP = 0
  CSIDL_DRIVES = 17
  CSIDL_FONTS = 20
  CSIDL_NETHOOD = 18
  CSIDL_NETWORK = 19
  CSIDL_PERSONAL = 5
  CSIDL_PRINTERS = 4
  CSIDL_PROGRAMS = 2
  CSIDL_RECENT = 8
  CSIDL_SENDTO = 9
  CSIDL_STARTMENU = 11
End Enum

Private Const MAX_PATH = 260
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32.dll" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hWndOwner As Long, ByVal nFolder As Long, ListId As Long) As Long



Public Function BrowseFolders(hWndOwner As Long, sMessage As String, Browse As BrowseType, ByVal RootFolder As FolderType) As String
Dim Nullpos As Integer
Dim lpIDList As Long
Dim res As Long
Dim sPath As String
Dim BInfo As BrowseInfo
Dim RootID As Long

SHGetSpecialFolderLocation hWndOwner, RootFolder, RootID
BInfo.hWndOwner = hWndOwner
BInfo.lpszTitle = lstrcat(sMessage, "")
BInfo.ulFlags = Browse
If RootID <> 0 Then BInfo.pIDLRoot = RootID
lpIDList = SHBrowseForFolder(BInfo)
If lpIDList <> 0 Then
  sPath = String(MAX_PATH, 0)
  res = SHGetPathFromIDList(lpIDList, sPath)
  Call CoTaskMemFree(lpIDList)
  Nullpos = InStr(sPath, vbNullChar)
  If Nullpos <> 0 Then
    sPath = Left(sPath, Nullpos - 1)
  End If
End If
BrowseFolders = sPath
End Function


Private Sub cmdGetFolder_Click()
Dim sTmp As String
  'try different settings like CSIDL_DRIVES+CSIDL_PERSONAL+etc etc
  sTmp = BrowseFolders(Me.hWnd, "Select folder", BrowseForFolders, CSIDL_DRIVES+CSIDL_PERSONAL)
'
End Sub
0
 

Author Comment

by:vbncsu
ID: 8092121
This still uses shell commands to make a dialog for the browsing and returns the selected path.

Is there anyway to make the browse window appear in a dialog that I create?
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9053153
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->PAQ - with points refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9143694
Question is PAQ'd and points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question