Attribute VB_Name = "modMain"
'=========================================
'=       LISTVIEW PAGINATION DEMO        =
'=---------------------------------------=
'=  Developed by P. G. B. Prasanna       =
'=  A Software Developer from Sri Lanka  =
'=  E-mail: pgbsoft@gmail.com            =
'=  Created: 02/01/2019                  =
'=  Licence: Free to use or modify       =
'=---------------------------------------=
'=        Copyright © 2019 PGBSoft       =
'=========================================

Option Explicit

Public dbCon As Connection

Public Declare Sub Sleep Lib "kernel32" _
    (ByVal dwMilliseconds As Long)

Private Declare Function InitCommonControlsEx _
    Lib "comctl32.dll" _
        (iccex As tagInitCommonControlsEx) As Boolean
    
Private Const ICC_USEREX_CLASSES = &H200

Private Type tagInitCommonControlsEx
    lngSize As Long: lngICC As Long
End Type

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryW" _
    (ByVal lpLibFileName As Long) As Long
    
Private Declare Function FreeLibrary Lib "kernel32" _
    (ByVal hLibModule As Long) As Long
    
Private Declare Function SetWindowPos _
    Lib "user32" _
    (ByVal hwnd As Long, _
    ByVal hWndInsertAfter As WndInsertAfterEnum, _
    ByVal X As Long, _
    ByVal Y As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal wFlags As SetWindowPosFlagsEnum) As Long

Private Enum WndInsertAfterEnum
    HWND_BOTTOM = 1
    HWND_BROADCAST = &HFFFF&
    HWND_DESKTOP = 0
    HWND_NOTOPMOST = -2
    HWND_TOP = 0
    HWND_TOPMOST = -1
End Enum

Private Enum SetWindowPosFlagsEnum
    SWP_FRAMECHANGED = &H20
    SWP_DRAWFRAME = SWP_FRAMECHANGED
    SWP_HIDEWINDOW = &H80
    SWP_NOACTIVATE = &H10
    SWP_NOCOPYBITS = &H100
    SWP_NOMOVE = &H2
    SWP_NOOWNERZORDER = &H200
    SWP_NOREDRAW = &H8
    SWP_NOREPOSITION = SWP_NOOWNERZORDER
    SWP_NOSIZE = &H1
    SWP_NOZORDER = &H4
    SWP_SHOWWINDOW = &H40
End Enum
    
Public m_hMod As Long

'Prepair the controls to get the modern visual styles.
Public Sub InitializeStyles()

    On Local Error GoTo Err
    
    Dim iccex As tagInitCommonControlsEx
    
    m_hMod = LoadLibrary(StrPtr("shell32.dll"))
    
        With iccex
          .lngSize = LenB(iccex)
          .lngICC = ICC_USEREX_CLASSES
        End With
    InitCommonControlsEx iccex
    
    Exit Sub
    
Err:
    
End Sub

Public Sub TerminateStyles()
    If m_hMod <> 0 Then FreeLibrary m_hMod
End Sub

'This public procedure uses to connect to the databse.
Public Sub Connect_Db()
    
    On Error GoTo Db_Error
    Set dbCon = New Connection
    
    
    dbCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & App.Path & "\dbDemo.mdb;" & _
    "Persist Security Info=False"
                             
    dbCon.Open
    Exit Sub
    
'Error handling for database connection problems.
Db_Error:
    MsgBox "Database Connection Error." & vbCrLf & _
           "Error No: " & Err.Number & vbCrLf & _
           "Error Description: " & Err.Description, vbCritical
           TerminateStyles
           'Exit the application.
           End
           
End Sub

Sub Main()

    InitializeStyles
    CheckDB
    
End Sub

Private Sub CheckDB()

    If Len(Dir$(App.Path & "\dbDemo.mdb")) = 0 Then
        If Len(Dir$(App.Path & "\_dbEmpty")) = 0 Then
            MsgBox "_dbEmpty file not found!, " & _
            "please retry by placing _dbEmpty file in the application location.", vbCritical: TerminateStyles: End
        Else
            Call FileCopy(App.Path & "\_dbEmpty", _
            App.Path & "\dbDemo.mdb")
            frmDataFeed.Show
        End If
    Else
        'frmDemo.Show
        frmSplash.Show
    End If
    
End Sub

Public Sub SetTopMost(ByVal hwd As Long, ByVal bStatus As Boolean)
    SetWindowPos hwd, IIf(bStatus = True, HWND_TOPMOST, HWND_NOTOPMOST), _
    1, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End Sub
