如题!

解决方案 »

  1.   

    应该是在你的Form居中的情况下就会自动居中吧
      

  2.   

    窗体代码:
    Option Explicit
    Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    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 Const OFN_ENABLEHOOK = &H20
    Private Const OFN_EXPLORER = &H80000                         '  new look commdlg
    Dim m_ofn As OPENFILENAMEPrivate Sub Command1_Click()
         With m_ofn
            
            .lStructSize = Len(m_ofn)
            .hInstance = App.hInstance
            .hwndOwner = Me.hwnd
            .lpstrFilter = "Bitmaps (*.BMP)" + Chr$(0) + "*.BMP" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
            .lpstrFileTitle = Space(249) + "*.BMP"
            .lpstrFile = .lpstrFileTitle
            .lpstrTitle = "请选择Bmp图片..."
            '.lpstrInitialDir = "C:\Windows"
            .nMaxFile = 255
            .nMaxFileTitle = 255
            '&H51 + &H80000
            'OFN_ENABLEHOOK  要使用勾子,这个必须
            .flags = OFN_EXPLORER Or OFN_ENABLEHOOK  ' Or  Or OFN_ENABLETEMPLATE _
                     Or OFN_CREATEPROMPT Or OFN_NODEREFERENCELINKS Or OFN_ENABLEHOOK        .lpTemplateName = "tt"
            .lpfnHook = GetProcAddress(AddressOf OpenSaveHookProc)        
        End With    Call GetOpenFileName(m_ofn)End Sub模块代码:
    Option Explicit
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    Private Const WM_INITDIALOG = &H110
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
    Public Function GetProcAddress(ByVal Addr As Long) As Long
        GetProcAddress = Addr
    End FunctionPublic Function OpenSaveHookProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        On Error Resume Next
        
        Select Case uMsg
           Case WM_INITDIALOG
               'temporary vars for demo
                Dim rc As RECT
                Dim hwndParent As Long, newLeft As Long, newTop As Long, dlgWidth As Long, dlgHeight As Long, scrWidth As Long, scrHeight As Long            'obtain the handle to the parent dialog
                hwndParent = GetParent(hwnd)
            
                If hwndParent <> 0 Then
                    'Just to prove the handle was obtained,
                    'change the dialog's caption.
                    'Call SetWindowText(hwndParent, "I'm Hooked on Hooked Dialogs!")
                    
                    'Position the dialog in the centre of
                    'the screen. First get the current dialog size.
                     Call GetWindowRect(hwndParent, rc)
                    
                    '(To show the calculations involved, I've
                    'used variables instead of creating a
                    'one-line MoveWindow call.)
                     dlgWidth = rc.Right - rc.Left
                     dlgHeight = rc.Bottom - rc.Top
                    
                     scrWidth = Screen.Width \ Screen.TwipsPerPixelX
                     scrHeight = Screen.Height \ Screen.TwipsPerPixelY
                    
                     newLeft = (scrWidth - dlgWidth) \ 2
                     newTop = (scrHeight - dlgHeight) \ 2
                    
                    '..and set the new dialog position to centre.
                     Call MoveWindow(hwndParent, newLeft, newTop, dlgWidth, dlgHeight, True)
                    
                End If
                OpenSaveHookProc = 1
                
    '       Case WM_COMMAND
    '            ……
    '       Case WM_NOTIFY
    '            ……
        End Select
    End Function
      

  3.   

    http://vbnet.mvps.org/index.html?code/hooks/fileopensavedlghookadvtext.htm