Jump to content

Recommended Posts

Posted

Hi All

 

I've been tinkering with building a PC lock screen that I can add corporate branding and the IT help desk contact details to 

I've managed to get a transparent overlay  with a button, what I want to happen if a user clicks anywhere on the screen the child form pops up telling them the machine is locked please contact... then for that to disappear after a few seconds. 

I want to put a couple of buttons on the child form, one which hides it and one to allow admin to enter a password to close the application but if I use sleep to pause the script it doesn't recognise the button presses. 

I did find an example on the forum using adlibregister which i tried to adapt but that resulted in the child form flashing on and off every few seconds once it was triggered. 

 

All help greatly appreciated as always

 

Thanks

Grant

 

 

 

 

 

  • 2 weeks later...
Posted (edited)

You would probably be wanting to look into:

AdlibRegister:

https://www.autoitscript.com/autoit3/docs/functions/AdlibRegister.htm

 

EDIT: sorry I just noticed you have looked into it. Let me see if I can make an example for you.

 

Here is a rudimentary way of achieving this but there is probably a much more elegant/better way:

#NoTrayIcon
#include-once
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <StringSize.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>

$desktoparea = _DesktopDimensions() ;grab full dimensions of desktop so that we can cover all screens (for multi-screen environments) - probably needs some work to make it more comperehensive
$totaldesktopwidth = $desktoparea[3]
$mainscreenwidth = $desktoparea[1]
$maxdesktopheight = 0
$mouseclicked = False
$closetimer = 0
$sec = 0
$idletimer = 0

For $i = 2 to Ubound($desktoparea) - 1 Step 2
    If $i > Ubound($desktoparea) - 1 Then
        ExitLoop
    Else
        $maxdesktopheight = $desktoparea[$i]
    EndIf
Next

$lockedoverlay = GUICreate("", $totaldesktopwidth, $maxdesktopheight, 0, 0, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST, WinGetHandle(AutoItWinGetTitle()))
GUISetBkColor(0x000, $lockedoverlay)
WinSetTrans($lockedoverlay, "", 100)
WinMove($lockedoverlay, "", -$mainscreenwidth, 0)

GUISetState(@SW_DISABLE, $lockedoverlay)
GUISetState(@SW_SHOW, $lockedoverlay)

$messagegui = GUICreate("Locked", 360, 250, -1, -1, Default, $WS_EX_TOPMOST)
$messagegui_lbl1 = _StringSize("This computer is locked,"&@CRLF&"please enter password to unlock.", 15.5, Default, Default, "Calibri")
GUISwitch($messagegui)
$lbl_width = $messagegui_lbl1[2]
$lbl_height = $messagegui_lbl1[3]
$messagegui_lbl1 = GUICtrlCreateLabel("This computer is locked,"&@CRLF&"please enter password to unlock.", (360 - $lbl_width)/2, 20, $lbl_width, $lbl_height, $SS_CENTER)
GUICtrlSetFont(-1, 15.5, Default, Default, "Calibri", $CLEARTYPE_QUALITY)
$prevcontrol = ControlGetPos($messagegui, "", $messagegui_lbl1)
$messagegui_pw_in = GUICtrlCreateInput("", (360-220)/2, $prevcontrol[1] + $prevcontrol[3] + 20, 220, 30, $ES_PASSWORD)
GUICtrlSetFont(-1, 15.5, Default, Default, "Calibri", $CLEARTYPE_QUALITY)
$prevcontrol = ControlGetPos($messagegui, "", $messagegui_pw_in)
$messagegui_bn_unlock = GUICtrlCreateButton("Unlock", (360-175)/2, $prevcontrol[1] + $prevcontrol[3] + 20, 175, 40)
GUICtrlSetFont(-1, 15.5, Default, Default, "Calibri", $CLEARTYPE_QUALITY)
$prevcontrol = ControlGetPos($messagegui, "", $messagegui_bn_unlock)
$messagegui_lbl2 = _StringSize("This window will close automatically in XXX seconds.", 11.5, Default, Default, "Calibri")
GUISwitch($messagegui)
$lbl_width = $messagegui_lbl2[2]
$lbl_height = $messagegui_lbl2[3]
$messagegui_lbl2 = GUICtrlCreateLabel("", (360 - $lbl_width)/2, $prevcontrol[1] + $prevcontrol[3] + 20, $lbl_width, $lbl_height, $SS_CENTER)
GUICtrlSetFont(-1, 11.5, Default, Default, "Calibri", $CLEARTYPE_QUALITY)

GUIRegisterMsg($wm_command, "WM_COMMAND")

While 1
    CheckForClick()
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $lockedoverlay
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $messagegui
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    AdlibUnRegister("IdleCheck")
                    GUISetState(@SW_HIDE, $messagegui)
                    WinSetOnTop($lockedoverlay, "", 1)
                    $mouseclicked = False
                    GUICtrlSetData($messagegui_pw_in, "")
                Case $messagegui_bn_unlock
                    ;exit for now, can do password check here
                    Exit
            EndSwitch
    EndSwitch
WEnd

Func WM_COMMAND($hwnd, $msg, $wparam, $lparam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord
    Local $iCode = BitShift($wParam, 16)    ;HiWord
    Switch $hwnd
        Case $messagegui
            Switch $iIDFrom
                Case $messagegui_pw_in
                    Switch $iCode
                        Case $EN_CHANGE
                            AdlibUnRegister("CloseMessageGUI")
                            GUICtrlSetData($messagegui_lbl2, "")
                            $idletimer = TimerInit()
                            AdlibRegister("IdleCheck")
                    EndSwitch
            EndSwitch
    EndSwitch
EndFunc

Func IdleCheck()
    Local $tdiff = TimerDiff($idletimer)
    If $tdiff >= 5000 Then
        AdlibUnRegister("IdleCheck")
        $closetimer = TimerInit()
        AdlibRegister("CloseMessageGUI")
    EndIf
EndFunc

Func CheckForClick()
    If _IsPressed(1) And Not $mouseclicked Then
        $mouseclicked = True
        GUISetState(@SW_SHOW, $messagegui)
        $closetimer = TimerInit()
        AdlibRegister("CloseMessageGUI")
    EndIf
EndFunc

Func CloseMessageGUI()
    Local $tdiff = TimerDiff($closetimer)
    If $tdiff >= 0 And $tdiff < 1000 Then
        $sec = 5
    ElseIf $tdiff >= 1000 And $tdiff < 2000 Then
        $sec = 4
    ElseIf $tdiff >= 2000 And $tdiff < 3000 Then
        $sec = 3
    ElseIf $tdiff >= 3000 And $tdiff < 4000 Then
        $sec = 2
    ElseIf $tdiff >= 4000 And $tdiff < 5000 Then
        $sec = 1
    EndIf
    If Not StringInStr(GUICtrlRead($messagegui_lbl2), $sec) Then GUICtrlSetData($messagegui_lbl2, "This window will close automatically in "&$sec&" seconds.")
    If $tdiff >= 5000 Then
        GUICtrlSetData($messagegui_lbl2, "This window will close automatically in 0 seconds.")
        AdlibUnRegister("CloseMessageGUI")
        GUISetState(@SW_HIDE, $messagegui)
        WinSetOnTop($lockedoverlay, "", 1)
        $mouseclicked = False
        GUICtrlSetData($messagegui_lbl2, "")
    EndIf
EndFunc

Func _DesktopDimensions()
    Local $aReturn = [_WinAPI_GetSystemMetrics($SM_CMONITORS), _ ; Number of monitors.
            _WinAPI_GetSystemMetrics($SM_CXSCREEN), _ ; Width or Primary monitor.
            _WinAPI_GetSystemMetrics($SM_CYSCREEN), _ ; Height or Primary monitor.
            _WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN), _ ; Width of the Virtual screen.
            _WinAPI_GetSystemMetrics($SM_CYVIRTUALSCREEN)] ; Height of the Virtual screen.
    Return $aReturn
EndFunc   ;==>_DesktopDimensions

 

Edited by mpower

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...