Attribute VB_Name = "Comdlg"
' Common dialog module (c) Thunderbolt
 Option Explicit
       Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
                "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
       Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (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 Type ChooseColor
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    rgbResult As Long
    lpCustColors As String
    flags As Long
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type
Public ModWind As Boolean
Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As ChooseColor) As Long

Public Function ShowOpen(Title As String, Filter As String, Path As String, MultySelect As Boolean, frmHwnd As Long) As String
  ModWind = True
  Dim OpenFile As OPENFILENAME
         Dim lReturn As Long, i As Long, a As String: a = Filter + Chr(0)
         Do
         i = InStr(a, "|")
         If i = 0 Then Exit Do
         Mid(a, i, 1) = Chr(0)
         Loop
         OpenFile.lStructSize = Len(OpenFile)
         OpenFile.hwndOwner = frmHwnd
         OpenFile.hInstance = App.hInstance
         OpenFile.lpstrFilter = a
         OpenFile.nFilterIndex = 1
         OpenFile.lpstrFile = String(257, 0)
         OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
         OpenFile.lpstrFileTitle = OpenFile.lpstrFile
         OpenFile.nMaxFileTitle = OpenFile.nMaxFile
         OpenFile.lpstrInitialDir = Path
         OpenFile.lpstrTitle = Title
         OpenFile.flags = &H80000 Or &H1000 Or &H4
         If MultySelect = True Then OpenFile.flags = OpenFile.flags Or &H200
         lReturn = GetOpenFileName(OpenFile)
         If lReturn = 0 Then
            ShowOpen = ""
         Else
            ShowOpen = OpenFile.lpstrFile
         End If
ModWind = False
End Function
Public Function ShowColor(hWnd As Long) As Long
ModWind = True
Dim cc As ChooseColor
Dim lngRetVal As Long

cc.lStructSize = Len(cc)
cc.hwndOwner = hWnd
cc.hInstance = App.hInstance
cc.flags = 0
cc.lpCustColors = String$(16 * 4, 0)

lngRetVal = ChooseColor(cc)

If (lngRetVal) Then
    ShowColor = cc.rgbResult
Else
    ShowColor = 0
End If
ModWind = False
End Function

Public Function ShowSave(Title As String, Filter As String, Path As String, frmHwnd As Long) As String
  ModWind = True
  Dim OpenFile As OPENFILENAME
         Dim lReturn As Long, i As Long, a As String: a = Filter + Chr(0)
         Do
         i = InStr(a, "|")
         If i = 0 Then Exit Do
         Mid(a, i, 1) = Chr(0)
         Loop
         OpenFile.lStructSize = Len(OpenFile)
         OpenFile.hwndOwner = frmHwnd
         OpenFile.hInstance = App.hInstance
         OpenFile.lpstrFilter = a
         OpenFile.nFilterIndex = 1
         OpenFile.lpstrFile = String(257, 0)
         OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
         OpenFile.lpstrFileTitle = OpenFile.lpstrFile
         OpenFile.nMaxFileTitle = OpenFile.nMaxFile
         OpenFile.lpstrInitialDir = Path
         OpenFile.lpstrTitle = Title
         OpenFile.flags = &H80000 Or &H1000 Or &H4
         lReturn = GetSaveFileName(OpenFile)
         If lReturn = 0 Then
            ShowSave = ""
         Else
            ShowSave = OpenFile.lpstrFile
         End If
ModWind = False
End Function

