|
-
Feb 16th, 2000, 04:01 AM
#1
Thread Starter
New Member
Hello,
I use the funtion GetOpenFileName of "comdlg32.dll".
How can I center the dialog box in the screen ?
Thank you
------------------
Vinni
-
Feb 16th, 2000, 02:15 PM
#2
You can setup a CallBack Procdure by setting the OFN_ENABLEHOOK Flag and RePosition the Dialog as it's displayed, ie.
Code:
'In a Module..
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Const SWP_NOSIZE = &H1
Private Const OFN_ENABLEHOOK = &H20
Private Const WM_INITDIALOG = &H110
Private Function ComDlgHookProc(ByVal hWnd As Long, ByVal iCode As Integer, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim tRECT As RECT
Select Case wParam
Case WM_INITDIALOG
Call GetWindowRect(hWnd, tRECT)
tRECT.Left = ((Screen.Width / Screen.TwipsPerPixelX) - (tRECT.Right - tRECT.Left)) / 2
tRECT.Top = ((Screen.Height / Screen.TwipsPerPixelY) - (tRECT.Bottom - tRECT.Top)) / 2
Call SetWindowPos(hWnd, 0, tRECT.Left, tRECT.Top, 0, 0, SWP_NOSIZE)
End Select
ComDlgHookProc = False
End Function
Private Function GetAddress(ByVal lAddress As Long) As Long
GetAddress = lAddress
End Function
Public Function DoComDlg(Optional ByVal Filter As String = "All Files|*.*", Optional ByVal InitDir As String) As String
Dim tOFN As OPENFILENAME
With tOFN
.lpstrFilter = Replace(Filter, "|", Chr(0)) & Chr(0) & Chr(0)
.lpstrInitialDir = InitDir
.lpstrFile = Space(255)
.nMaxFile = 255
.hwndOwner = 0&
.hInstance = App.hInstance
.lpstrTitle = "Open File" & Chr(0)
.flags = OFN_ENABLEHOOK
.lpfnHook = GetAddress(AddressOf ComDlgHookProc)
.lStructSize = Len(tOFN)
End With
Call GetOpenFileName(tOFN)
DoComDlg = Left(tOFN.lpstrFile, tOFN.nMaxFile)
End Function
Usage: Filename = DoComDlg([Filter], [InitDir])
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Certified AllExperts Expert
-
Feb 29th, 2000, 01:30 PM
#3
New Member
Need Help in multiselect CommonDialog
Hi !
I using vb5 to do my program. How can I choose more than a
file in common dialog and add them into listbox ?
Show my the way please ..
Thanks a lot.
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
|