Attribute VB_Name = "modul_Calaym_ShutDown"
' Copyright (C) 2002-2011 Jan Vorel
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.

' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.

' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

' If you have any questions, suggestions or bug reports about this product,
' contact me: info@ctuser.net; Do not contact me about general B.A.S.I.C.
' language or A.P.I. issues

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
