1

Please help me to create a project to open dialog box without using common dialog component/control.

Regards Sesha

Sesha
  • 11
  • 1
  • 2
  • You can certainly create a full VB application by using only a form and some auxiliary hidden controls. But those are very advanced techniques. –  Apr 05 '14 at 06:42
  • Alex K's answer is a good one, however you should specify what TYPE of dialog there are plenty. – Denzil Newman Apr 06 '14 at 06:57
  • @Denzil I need file open dialog but without using "commondialog" control in vb6 – Sesha Apr 06 '14 at 08:05
  • Why don't you want to use the ocx? – MarkJ Apr 06 '14 at 14:31
  • Creating "under-the-radar-ware" maybe? I.e. a program to be used on a locked down PC (library, work, unsuspecting user's, etc.) where elevation rights are not available so installing isn't an option. – Bob77 Apr 07 '14 at 00:38

3 Answers3

5

Here is some sample code from the Microsoft KB, source.

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 Sub Command1_Click()
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String

    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = Form1.hwnd
    OpenFile.hInstance = App.hInstance
    sFilter = "Batch Files (*.bat)" & Chr(0) & "*.BAT" & Chr(0)
    OpenFile.lpstrFilter = sFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(257, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile
    OpenFile.lpstrInitialDir = "C:\"
    OpenFile.lpstrTitle = "Use the Comdlg API not the OCX"
    OpenFile.flags = 0
    lReturn = GetOpenFileName(OpenFile)
    If lReturn = 0 Then
        MsgBox "The User pressed the Cancel Button"
    Else
        MsgBox "The user Chose " & Trim(OpenFile.lpstrFile)
    End If
End Sub
jac
  • 9,666
  • 2
  • 34
  • 63
1

The CommonDialog control is a thin wrapper around the GetOpenFileName/GetSaveFileName APIs which you can invoke directly from VB. Here is a working example.

Alex K.
  • 171,639
  • 30
  • 264
  • 288
0

You may use very nice library from vbAccelerator.com: -

Common Dialog Direct Library

Ashwani Kumar
  • 215
  • 1
  • 4