|
-
Mar 8th, 2007, 06:47 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] How do I "Choose a file and add its path to a table?"
I assumed a Common Dialog would be the control I needed here but it apparently only opens or saves files. Is there a way to use this control but intercept this behaviour and simply grab the filename + path without trying to open/save it?
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
Mar 8th, 2007, 06:52 PM
#2
Re: How do I "Choose a file and add its path to a table?"
CommonDialog doesn't do any Opening / Saving - it merely returns the path & filename selected so you can do that stuff
-
Mar 8th, 2007, 07:00 PM
#3
Thread Starter
Fanatic Member
Re: How do I "Choose a file and add its path to a table?"
Thanks for that!
I'm about to experiment but doesn't the control just have Open or Save buttons? Can I change the caption of these because my users are simply choosing files (ie. they don't want to open or save them)?
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
Mar 8th, 2007, 07:25 PM
#4
Re: How do I "Choose a file and add its path to a table?"
well you can change the DialogTitle, is that not sufficient?
if not:
in Form
Code:
Private Sub Command1_Click()
With CommonDialog1
.DialogTitle = "Choose A File"
.Flags = cdlOFNHideReadOnly Or cdlOFNFileMustExist
hHook = SetWindowsHookEx(WH_CBT, AddressOf Manipulate, GetWindowLong(Me.hwnd, GWL_HINSTANCE), GetCurrentThreadId)
.ShowOpen
Debug.Print .FileName
End With
End Sub
In Module
Code:
Option Explicit
' used for placing the hook
Public Declare Function UnhookWindowsHookEx Lib "user32" ( _
ByVal hHook As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" ( _
ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Const GWL_HINSTANCE = (-6)
Public Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
Public hHook As Long
' used for locating and changing the button
Public Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" ( _
ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" ( _
ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
' function called by hook
Public Function Manipulate(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim sBuffer As String * 255, lhWnd As Long
If lMsg = HCBT_ACTIVATE Then
GetClassName wParam, sBuffer, Len(sBuffer)
If InStr(sBuffer, "#32770") = 1 Then
lhWnd = FindWindowEx(wParam, 0, "Button", "&Open")
SetWindowText lhWnd, "Choose"
UnhookWindowsHookEx hHook
End If
End If
End Function
-
Mar 9th, 2007, 04:21 AM
#5
Thread Starter
Fanatic Member
Re: How do I "Choose a file and add its path to a table?"
That's very helpful, thanks!
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|