位置没办法!
初始Color:
    dlg.Color = RGB(255, 0, 0)
    dlg.Flags = cdlCCRGBInit + cdlCCFullOpen
    dlg.ShowColor

解决方案 »

  1.   

    都没问题,看:
    1、这个例子是让CommonDialog居中:
    'm_ofn是你的CommonDialog控件,属性名你可能要改一改!
    Private Sub Command1_Click()
        On Error GoTo ErrorHandle
        
        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
            .flags = OFN_EXPLORER Or OFN_READONLY Or OFN_SHOWHELP Or OFN_ENABLETEMPLATE _
                     Or OFN_CREATEPROMPT Or OFN_NODEREFERENCELINKS Or OFN_ENABLEHOOK        .lpTemplateName = "tt"
            .lpfnHook = GetProcAddress(AddressOf OpenSaveHookProc)
        End With
        
        If GetOpenFileName(m_ofn) Then
            MsgBox TrimNull(m_ofn.lpstrFile), vbInformation, "你打开的文件是:"
        End If
            
        Exit Sub
        
    ErrorHandle:
        MsgBox Err.Description, vbCritical
    End Sub在moudle中: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 Function2、初始化color:
    'm_ofn是你的CommonDialog控件
        m_ofn.Flags = cdlCCRGBInit + cdlCCFullOpen
        m_ofn.Color = RGB(255, 123, 213)   
        m_ofn.ShowColor
      

  2.   

    谢谢,初始化color已按你们的方法解决,我对API不熟,运行
            .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
    ...
    总是出错,请多指教!
      

  3.   

    简单的办法:新建一个阿隐藏的窗体,在上面放 CommonDialog ,然后设置这个窗体启动位置为屏幕中心就OK了。
      

  4.   

    或者复杂点的办法,用 API ,然后用上面 NiceFeather 的方法比较好!