'Option Strict Off
'Option Explicit On
Imports VB = Microsoft.VisualBasic

Public Module modXpStyles

	'=========================================================

    'Example Usage:

    'Private Sub Form_Initialize()
    '    InitXpStyles
    'End Sub

    'This can either be in the same folder as your executable called appname.exe.manifest
    'or it can be embedded in a resource file with a type of 24 and an ID of 1.

    'Now, to make these work properly, you need to call the InitCommonControls function
    'before any forms are loaded. This can either be in the startup forms Initialize event or in Sub Main()

    Public Structure tagInitCommonControlsEx
        Dim lngSize As Integer
        Dim lngICC As Integer
    End Structure
    Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (ByRef iccex As tagInitCommonControlsEx) As Boolean
    Public Declare Sub InitCommonControls Lib "comctl32.dll" 
    Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Integer
    Public Const ICC_USEREX_CLASSES As Short = &H200S

    Public Sub InitXpStyles()
        On Error Resume Next
        LoadLibrary("shell32.dll")
        InitCommonControls()
        On Error GoTo 0
    End Sub

'#Const defUse_InitXpStylesEx = True
#If defUse_InitXpStylesEx
    Public Sub InitXpStylesEx()
        ' we need to call InitCommonControls before we
        ' can use XP visual styles.  Here I'm using
        ' InitCommonControlsEx, which is the extended
        ' version provided in v4.72 upwards (you need
        ' v6.00 or higher to get XP styles)
        On Error Resume Next
        LoadLibrary("shell32.dll")

        ' this will fail if Comctl not available
        Dim iccex As tagInitCommonControlsEx
        iccex.lngSize = LenB(iccex)
        iccex.lngICC = ICC_USEREX_CLASSES

        InitCommonControlsEx(iccex)

        ' now start the application
        On Error GoTo 0
        'frmTestControls.Show
    End Sub
#End If


End Module