Attribute VB_Name = "modul_Calaym_ShutDown"
' Calaym - Media player GUI for sound systems
' Copyright (C) 2002-2012 Jan Vorel
'
' You can redistribute the official software packages under the terms of the
' User-friendly Open-source License Version 1.00, published by Jan Vorel
'
' You can use this software under the terms of the
' User-friendly Software License Version 1.00, published by Jan Vorel
'
' You should have received copies of the licenses along with this program. If
' not, contact the author.
'
' If you want to use or distribute this software under a different license, ask
' the author.
'
' The software is provided "as is" without warrenty of any kind. The Licensor
' cannot be held responsible for any damage caused by using, extracting or
' installing the software.

Option Explicit
Option Base 0
        
Public hwndShutDownProgress As Long
        
Public ShutDownInitTime As Long
Public Const ShutDownTimerMax As Long = 32000&
Public Const ShutDownTimerMaxDiv As Long = ShutDownTimerMax \ 100&

Public Sub StartShutDownStuff()
  WantsShutdownDialog = False
  DialogTimer True
  Call LoadResEx_Dialog(MainHWnd, 2950&, 2959&, 0&, AddressOf ShutdownDialogProc)
  DialogTimer False
  Select Case QuitMode
    Case 1&
      'Debug.Print "Shut down!!!"
      'QuitMode = 0&
      MainForm_UnloadP
    Case 2&
      ShutdownWindowsEx SDWE_Hibernate
      QuitMode = 0&
    Case 3&
      ShutdownWindowsEx SDWE_Standby
      QuitMode = 0&
    Case 4&
      ShutdownWindowsEx SDWE_MonitorsOff
      QuitMode = 0&
    End Select
  End Sub

Public Function ShutdownDialogProc(ByVal HWndDialog As Long, ByVal Msg As Long, ByVal ControlID As Long, ByVal ControlHWnd As Long) As Long
  If Msg = &H110& Then
    ShutDownInitTime = DoEventsEx_GetTickCount
    hwndShutDownDialog = HWndDialog
    If KioskDown Then
      LoadResEx_Dialog_Enable HWndDialog, 2959&, False
      End If
    hwndShutDownProgress = GetDlgItem(HWndDialog, 2950&)
    Call SetWindowText(HWndDialog, LoadResEx_String(2949& + QuitModePending))
    ElseIf Msg = &H111& Then
    QuitModePending = 0&
    ShutdownDialogProc = 1&
    ElseIf Msg = &H12& Then
    hwndShutDownDialog = 0&
    End If
  End Function
