Thanks to all and in particular to Mike Lynch, I have got a working GetDir
MB function. Among the many problems solved were the definition of "the
window handle (hWnd) of`the calling application" as
systeminfo(SYS_INFO_APPLICATIONWND) (code 7), and the stripping of null
characters that is not required at all (MB len(spath) returns the exact
number of characters before "stripping", not 260)
Here is my restructured and cleaned up code
'****************** Declare etc. for required external functions
Type BrowseInfo
hWndOwner As Integer
pIDLRoot As Integer
pszDisplayName As Integer
lpszTitle As Integer
ulFlags As Integer
lpfnCallback As Integer
lParam As Integer
iImage As Integer
End Type
Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Integer)
Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As
String, ByVal lpString2 As String) As Integer
Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As
Integer
Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As
Integer, lpBuffer As String) As Integer
'****************** Declare for sample application and function GetDir
declare sub Main
declare function GetDir(spath as string) as logical
'****************** Sample application for calling GetDir
Sub Main
dim dirpath as smallint
dim spath as string
dirpath=getdir(spath)
note sPath
end sub
'****************** Function GetDir
function GetDir(spath as string) as logical
Dim lpIDList As Integer
Dim lResult As Integer
Dim udtBI As BrowseInfo
Define BIF_RETURNONLYFSDIRS 1
Define MAX_PATH 260
getdir=0
'Set the owner window
udtBI.hWndOwner = SystemInfo(7)
'lstrcat appends the two strings and returns the memory address
udtBI.lpszTitle = lstrcat("C:\", "")
'Return only if the user selected a directory
udtBI.ulFlags = BIF_RETURNONLYFSDIRS
'Show the 'Browse for folder' dialog
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList > 0 Then
getdir=1
sPath = String$(MAX_PATH, "0")
'Get the path from the IDList
lResult = SHGetPathFromIDList (lpIDList, sPath)
End If
call CoTaskMemFree( lpIDList)
End Function
Jacques PARIS
e-mail (>>>19.12.00) [EMAIL PROTECTED]
For MapInfo support, see the Paris PC Consult enr. site at
http://www.total.net/~rparis/gisproducts.htm
For MapBasic questions see the J.Paris site at
http://www.total.net/~jakesp/index.htm
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Martin,
Christopher (WSA Telford)
Sent: February 9, 2001 4:33 AM
To: 'Søren Breddam'; MapInfo-L (E-mail)
Cc: 'David Booth'
Subject: RE: MI-L Specifying path
The SHBrowseForFolder is not a VB but a Win32 API call. In theory, you
should be able to happily call it from MB.
However, we do have a snag in that the other listers might be able to shed
some light on: It appears that the call requires the window handle (hWnd) of
the calling application. This is easily obtainable in VB, but as for MB, I
dont know. I'm making enquiries elsewhere, but maybe someone on the list has
an insight?
Chris
_______________________________________________________________________
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, send e-mail to [EMAIL PROTECTED] and
put "unsubscribe MapInfo-L" in the message body.