和创建你自己的控件相比较,使用控件CommonDialog 的优点是什么?

解决方案 »

  1.   

    CommonDialog 没什么优点!
    建议用API。
    比如,打开文件对话框:标准模块:Module1.bas Option ExplicitPublic Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    Public 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
    窗体模块: 
    'Form1上添加一列表框控件List1,一命令按钮Command1
    Option ExplicitPrivate Sub Command1_Click()
            Dim ofn As OPENFILENAME
            Dim rtn& ', S$, Str$, i%
            
            ofn.lStructSize = Len(ofn)
            ofn.hwndOwner = Me.hwnd
            ofn.hInstance = App.hInstance
            ofn.lpstrFilter = "所有文件"
            ofn.lpstrFile = Space(254)
            ofn.nMaxFile = 255
            ofn.lpstrFileTitle = Space(254)
            ofn.nMaxFileTitle = 255
            ofn.lpstrInitialDir = App.path
            ofn.lpstrTitle = "打开文件"
            ofn.flags = 6148
            rtn = GetOpenFileName(ofn)
            'For i = 1 To Len(Trim(ofn.lpstrFile))
            '    S = Mid(Trim(ofn.lpstrFile), i, 1)
            '    If Len(S) <> 0 Then Str = Str & S
            'Next
            'Debug.Print Str
            'List1.AddItem ofn.lpstrFile
            If rtn <> 0 Then
               List1.AddItem ofn.lpstrFile
            Else
               List1.AddItem "按了取消键!"
            End If
    End Sub
      

  2.   

    使用控件CommonDialog 的优点是什么?
    ...起码便于初学者使用~
    问一下楼上的,怎样发出你那种代码的效果? 
    谢谢。

    ABIUS 后面那个图标,点下~
      

  3.   

    1楼的朋友,能否说下你的程序与CommonDialog 有什么区别吗?
    谢谢
      

  4.   

    使用控件CommonDialog 的优点就是代码量少。
      

  5.   

    使用 CommonDialog的控件是 代码精简,减少了繁琐的API。
    方便初学者对CommonDialog有所认识和上手~~