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
CONST BIF_RETURNONLYFSDIRS = 1
CONST MAX_PATH = 260
CONST BFFM_INITIALIZED = 1
CONST BFFM_SETSELECTIONA = &H466
DECLARE SUB CoTaskMemFree LIB "Ole32" ALIAS "CoTaskMemFree"(hMem AS LONG)
DECLARE FUNCTION SHBrowseForFolder LIB "Shell32" ALIAS "SHBrowseForFolder"_
(lpbi AS BROWSEINFO) AS LONG
DECLARE FUNCTION SHGetPathFromIDList LIB "Shell32" ALIAS "SHGetPathFromIDList"_
(pidList AS LONG, lpBuffer AS STRING) AS LONG
DECLARE FUNCTION GetWindowRect LIB "User32" ALIAS "GetWindowRect"_
(hWnd AS LONG, lpRect AS QRECT) AS LONG
DECLARE FUNCTION MoveWindow LIB "User32" ALIAS "MoveWindow"_
(hWnd AS LONG, x AS LONG, y AS LONG,nWidth AS LONG,_
nHeight AS LONG, bRepaint AS LONG) AS LONG
DECLARE FUNCTION SetWindowText LIB "user32" ALIAS "SetWindowTextA"_
(hWnd AS LONG, ByRef lpString AS STRING) AS LONG
TYPE QBROWSEDIALOG EXTENDS QOBJECT
WITH QBROWSEDIALOG
CAPTION AS STRING
Title AS STRING
InitialDir AS STRING
Directory AS STRING
X AS STRING
FUNCTION BrowseHook(hWnd AS LONG, uMsg AS LONG, lParam AS LONG, lpData AS LONG) AS LONG
IF uMsg = BFFM_INITIALIZED THEN
DIM R AS QRECT
GetWindowRect(hWnd, R)
MoveWindow (hWnd, (Screen.Width-(R.Right-R.Left))/2, (Screen.Height-(R.Bottom-R.Top))/2,_
(R.Right-R.Left), (R.Bottom-R.Top), 0)
SendMessage(hWnd, BFFM_SETSELECTIONA, 1, lpData)
IF LEN(.CAPTION) THEN
SetWindowText(hWnd, .CAPTION)
END IF
END IF
END FUNCTION
FUNCTION EXECUTE AS LONG
DIM BI AS BROWSEINFO
DIM pidl AS LONG
DIM sPath AS STRING*MAX_PATH
DIM xPath AS STRING*MAX_PATH
.InitialDir = .InitialDir + CHR$(0)
BI.hWndOwner = Application.Handle
BI.pszDisplayName = VARPTR(xPath)
BI.lpszTitle = VARPTR(This.Title)
BI.lpfnCallback = CODEPTR(This.BrowseHook)
BI.lParam = VARPTR(This.InitialDir)
pidl = SHBrowseForFolder(BI)
IF pidl THEN
IF SHGetPathFromIDList(pidl, sPath) THEN
.Directory = LEFT$(sPath, INSTR(sPath, CHR$(0))-1)
ELSE
.Directory = LEFT$(xPath, INSTR(xPath, CHR$(0))-1)
END IF
CoTaskMemFree pidl
Result = 1
ELSE
Result = 0
END IF
END FUNCTION
END WITH
END TYPE
DECLARE SUB Click
DIM BD AS QBrowseDialog
BD.Title = "Title"
BD.CAPTION = "Caption"
CREATE Form AS QFORM
CREATE Edit AS QEDIT
END CREATE
CREATE Button AS QBUTTON
Left = Edit.Width +5
OnClick = Click
END CREATE
END CREATE
Form.SHOWMODAL
SUB Click
BD.InitialDir = COMMAND$(0)-Application.ExeName
IF BD.EXECUTE THEN
Edit.Text=BD.Directory
Form.CAPTION = BD.X
END IF
END SUB
|