[AccessD] IMAllocate

John W. Colby jwcolby at colbyconsulting.com
Mon May 30 07:07:47 CDT 2005


Stuart,

>From MSDN:

There are two styles of dialog box available. The older style is displayed
by default and is not resizable. To specify a dialog box using the newer
style, set the BIF_USENEWUI flag in the ulFlags member of the BROWSEINFO
structure. The newer style provides a number of additional features,
including drag-and-drop capability within the dialog box, reordering,
deletion, shortcut menus, the ability to create new folders, and other
shortcut menu commands. Initially, it is larger than the older dialog box,
but can be resized by the user.

ulFlags is a long integer, I assume of bits that can be set/reset.

Thus in your code:

'To get the New Folder button declare the BIF_USENEWUI constant in your
code.
Const BIF_USENEWUI = &H40&
 
  'Fill BROWSEINFO structure data
   With BI
      .hOwner = 0
      .pidlRoot = 0
      .lpszTitle = lstrTitle
      .ulFlags = 1
      .ulFlags = .ulFlags Or BIF_USENEWUI
      .pszDisplayName = Space$(260)
   End With

This displays a different dialog with a "make new folder" button on it.

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John W. Colby
Sent: Monday, May 30, 2005 7:53 AM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] IMAllocate


Stuart,

Is there a way to have this dialog present a "new directory" button so that
if a directory doesn't exist it can be created from within the dialog?

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Monday, May 30, 2005 12:21 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] IMAllocate


On 29 May 2005 at 23:59, John W. Colby wrote:

> Is this in something I can reference?  I am trying to get code to
> browse for folders as opposed to files, and I am up against this ATM.
> 

ShBrowseForFolder() allocates memory automatically for the pidl so you 
don't need to worry about IMAllocate, but you need to clean it up yourself 
afterwards with  CoTaskMemFree.

Here's a simple Folder Browser demo.

Stick this in a module soemwhere:

Public Declare Function SHBrowseForFolder Lib "shell32.dll" _
   Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Public Declare Function SHGetPathFromIDList Lib "shell32.dll" _
   Alias "SHGetPathFromIDListA" _
  (ByVal pidl As Long, _
   ByVal pszPath As String) As Long
    
Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)

Public Type BROWSEINFO    'BI
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type


Stick this behind a button on a form:

Private Sub btnBrowseForFolder_Click()
  Dim pidl As Long
  Dim BI As BROWSEINFO
  Dim sPath As String
  Dim pos As Integer
 
  'Fill BROWSEINFO structure data
   With BI
      .hOwner = 0
      .pidlRoot = 0
      .lpszTitle = "Browsing"
      .ulFlags = 1
      .pszDisplayName = Space$(260)
   End With
  
  'show dialog returning pidl to selected item
   pidl = SHBrowseForFolder(BI)
 
  'if pidl is valid, parse & return the user's selection
   sPath = Space$(260)
    
   If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
   
     'SHGetPathFromIDList returns the absolute
     'path to the selected item. No path is returned for virtual folders.
      pos = InStr(sPath, Chr$(0))
      If pos Then Text1 = Left(sPath, pos - 1)
   Else:
     Text1 = "Problem"
   End If
 'free the pidl
   Call CoTaskMemFree(pidl)
        
End Sub
-- 
Stuart





More information about the AccessD mailing list