Attribute VB_Name = "modComDlg"
' ======================================================================================
' Name:     DeskShots 1.0
' Author:   Joshy Francis (joshylogicss@yahoo.co.in)
' Date:     14 May 2007
'
' Requires: None
'
' Copyright © 2000-2007 Joshy Francis
' --------------------------------------------------------------------------------------
'The Wallpaper changing Utility.
'   *********Features**********
'   1. Simple & Powerful Thumbnail Viewer.
'   2. Moving & Replacing of Images in List done very very fast.
'   3. Uses own Database System.
'   4. Different Settings can be applied to each files in list.
'   5. Drag-N-Drop Supporting.
'   6. Change wallpaper in timed intervals.Can Set Any Interval.
'   7. Startup.
'   8. Tray Notification.Can Simply control from System Tray.
'   9. Can Change wallpaper Sequentially or randomly.
'   10. Also includes many other useful functions related to Array,ListView,File Programming,
'       Common Dialog Control API,System Tray Application,Startup Application etc.
'       Array Functions include moving an item in array to another position.Faster Array operations,
'       Saving Array to File,Reading Array from File etc.
'       Simple Progressbar code is included.
'       A Simple & powerful ListView Technique is established.
'   *****************************************
'you can freely use this code anywhere.But I wants you must include the Copyright Info
'some of the functions from PSC
' --------------------------------------------------------------------------------------
'I Will include comments after a few days.Please wait.

'Please..........Vote my program...
Option Explicit
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
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OpenFilename) As Long
Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OpenFilename) As Long
Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_ENABLEHOOK = &H20
Public Const OFN_ENABLETEMPLATE = &H40
Public Const OFN_ENABLETEMPLATEHANDLE = &H80
Public Const OFN_EXPLORER = &H80000                         '  new look commdlg
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_LONGNAMES = &H200000                       '  force long names for 3.x modules
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_NODEREFERENCELINKS = &H100000
Public Const OFN_NOLONGNAMES = &H40000                      '  force no long names for 4.x modules
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &H10000
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_READONLY = &H1
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_SHAREFALLTHROUGH = 2
Public Const OFN_SHARENOWARN = 1
Public Const OFN_SHAREWARN = 0
Public Const OFN_SHOWHELP = &H10

Function OpenFile(ByVal hwnd As Long, Optional ByVal dSave As Boolean = False, Optional ByVal lp As Long = 0) As String
Dim OF As OpenFilename, Ret As Long, str As String
Static FirstTime As Boolean
    With OF
            If dSave = True Then
                .Flags = OFN_EXPLORER Or OFN_OVERWRITEPROMPT
            Else
                .Flags = OFN_EXPLORER Or OFN_ALLOWMULTISELECT
            End If
        .hwndOwner = hwnd
        .lpstrFilter = "Picture Files" & Chr(0) & "*.bmp;*.jpg;*.gif;*.jpeg;*.wmf;*.emf;*.png;*.tif" & Chr(0) & "All Files" & Chr(0) & "*.*" & Chr(0)
            If FirstTime = False Then
                .lpstrInitialDir = App.Path
                FirstTime = True
            End If
        .lStructSize = Len(OF)
        .lpstrFile = Space$(65534) & Chr(0)
        .nMaxFile = 65535
            If dSave = False Then
                .lpstrTitle = "Add Image"
            Else
                .lpstrTitle = IIf(lp > 1, "Save File As", "Save File")
            End If
    End With
        If dSave = False Then
            Ret = GetOpenFileName(OF)
        Else
            Ret = GetSaveFileName(OF)
        End If
If Ret = 1 Then
    str = left(OF.lpstrFile, InStrRev(OF.lpstrFile, Chr(0) & Chr(0)) - 1)
Else
    str = ""
End If
        If OF.nFilterIndex = 1 And dSave = True Then
            str = str & ".txt"
        End If
    OpenFile = str
End Function
Public Function IsDir(d) As Boolean
On Error GoTo E
        IsDir = False
    RmDir d
        MkDir d
        IsDir = True
Exit Function
E:
'    Debug.Print Err.Description
    If Err.Description = "Path not found" Then
        IsDir = False
    Else
        IsDir = True
    End If
End Function
Public Function IsFile(F) As Boolean
On Error GoTo E
    IsFile = False
        If InStr(F, ":") = 0 Then
            Exit Function
        End If
        If InStr(F, "\") = 0 Then
            Exit Function
        End If
Dim n As Integer
    n = FreeFile
        Open F For Input As n
        Close n
        Reset
    IsFile = True
Exit Function
E:
    Reset
IsFile = False
End Function
Public Function GetLastBackSlash(text As String) As String
    Dim I, pos As Integer
    Dim lastslash As Integer
    For I = 1 To Len(text)
        pos = InStr(I, text, "\", vbTextCompare)
        If pos <> 0 Then lastslash = pos
    Next I
    GetLastBackSlash = right(text, Len(text) - lastslash)
End Function

