Why setfocus to hidden text box? – API File open dialog

S

Seth

I am using a module that calls directly into comdlg32.dll to allow user to
select a file name using the Windows Common Dialog.

I downloaded an example by ghudson from:
http://www.access-programmers.co.uk/forums/showthread.php?t=75790

In ghudson’s code below he sets focus to a hidden text box on the form
(tbHidden). tbHidden is an unbound text box with a height and width of
0.025cm which is placed in the top left-hand corner of form
fFindOpenImportFile.

Why does he set focus to tbHidden?

Cheers,
Seth

ghudson’s code in form fFindOpenImportFile:
---------------------------------------------------
Private Sub bBrowse_Click()
On Error GoTo Err_bBrowse_Click

Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant

Me.tbHidden.SetFocus ‘****** What is this for?

' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _
' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*"
strFilter = "All Files (*.*)" & vbNullChar & "*.*"

lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly

varFileName = tsGetFileFromUser( _
fOpenFile:=True, _
strFilter:=strFilter, _
rlngflags:=lngFlags, _
strDialogTitle:="Find File (Select The File And Click The Open Button)")

If IsNull(varFileName) Or varFileName = "" Then
Debug.Print "User pressed 'Cancel'."
Beep
MsgBox "File selection was canceled.", vbInformation
Exit Sub
Else
'Debug.Print varFileName
tbFile = varFileName
End If

Call ParseFileName

Exit_bBrowse_Click:
Exit Sub

Err_bBrowse_Click:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_bBrowse_Click

End Sub
-----------------------------------------------------------
 
D

Dirk Goldgar

Seth said:
I am using a module that calls directly into comdlg32.dll to allow
user to select a file name using the Windows Common Dialog.

I downloaded an example by ghudson from:
http://www.access-programmers.co.uk/forums/showthread.php?t=75790

In ghudson's code below he sets focus to a hidden text box on the form
(tbHidden). tbHidden is an unbound text box with a height and width of
0.025cm which is placed in the top left-hand corner of form
fFindOpenImportFile.

Why does he set focus to tbHidden?

Cheers,
Seth

ghudson's code in form fFindOpenImportFile:
---------------------------------------------------
Private Sub bBrowse_Click()
On Error GoTo Err_bBrowse_Click

Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant

Me.tbHidden.SetFocus '****** What is this for?

' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _
' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*"
strFilter = "All Files (*.*)" & vbNullChar & "*.*"

lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or
tscFNHideReadOnly

varFileName = tsGetFileFromUser( _
fOpenFile:=True, _
strFilter:=strFilter, _
rlngflags:=lngFlags, _
strDialogTitle:="Find File (Select The File And Click The Open
Button)")

If IsNull(varFileName) Or varFileName = "" Then
Debug.Print "User pressed 'Cancel'."
Beep
MsgBox "File selection was canceled.", vbInformation
Exit Sub
Else
'Debug.Print varFileName
tbFile = varFileName
End If

Call ParseFileName

Exit_bBrowse_Click:
Exit Sub

Err_bBrowse_Click:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_bBrowse_Click

End Sub
-----------------------------------------------------------

Without downloading and examining his code myself, I can only speculate.
One possibility is that he's using that text box to help position the
API file dialog. If that text box has the focus, then it has a window
handle (hWnd) which can be retrieved by calling the API GetFocus
function, and then passed to the API GetOpenFileName function as the
"owner" of the dialog. Doing that would cause the dialog to be
positioned with is upper left corner just inside the upper left corner
of the text box.

As I said, that's only speculation. I've done the same thing by
positioning an infinitesimal form and using its hWnd that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top