Attribute VB_Name = "mod_Enum"
Option Explicit

' MoveWindow is needed for the repositioning of the desktop windows.
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

' These hold the handles of the four desktop-related windows.
Public Progman, SHELLDLL_DefView, SysListView32, SysHeader32 As Long
' Declare the counter for use with EnumChildProc().
Public iCount As Integer
Public PMRect As RECT

Function EnumChildProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
    ' I'm sure there's a more efficient way to do this, but
    ' this basically checks the value of the counter and
    ' assigns the variables a value (The windows are found
    ' in order so we can do this without errors (I hope)).
    '
    ' NOTE: We get the handle to Progman in the Form_Load event.
    If iCount = 0 Then
        SHELLDLL_DefView = lhWnd
        iCount = iCount + 1
    ElseIf iCount = 1 Then
        SysListView32 = lhWnd
        iCount = iCount + 1
    ElseIf iCount = 2 Then
        SysHeader32 = lhWnd
        iCount = iCount + 1
    Else
        ' We've found too many windows! End the program
        ' before we do some real damage :)
        MsgBox "Too many windows were found!"
        End
    End If
    
    ' Continue the enumeration
    EnumChildProc = True
End Function

Public Sub RefreshDesktop()
    ' This function makes sure the desktop windows
    ' are displayed correctly. I kept getting errors when
    ' I minimized the form, so I made this to fix them.
    ' It also resizes picDesktop to fit the form.
    MoveWindow Progman, 0, 0, PMRect.Right, PMRect.Bottom, 1
    MoveWindow SHELLDLL_DefView, 0, 0, PMRect.Right, PMRect.Bottom, 1
    MoveWindow SysListView32, 0, 0, PMRect.Right, PMRect.Bottom, 1
    MoveWindow SysHeader32, 0, 0, PMRect.Right, PMRect.Bottom, 1
    
    ' Resize picDesktop
    frmMain.picDesktop(0).Move 5, 400, frmMain.Width - 100, frmMain.Height - 800
End Sub


