Jump to content
Sign in to follow this  
JonF

Detect clicking on any control

Recommended Posts

JonF

I'm writing a "Pre-shell" to set up system parameters when booting LiveXP (a Windows PE 1 based system) befoer starting the shell. I want to have a countdown timer that activates the "Start Shell" button after N seconds unless the user clicks on any control. The buttons are easy, but the others ... not so much. I tried an idea for intercepting the Windows event of any control getting the focus (picked up form another post in this forum), but it isn't working. What am I doing wrong?

CODE
#NoTrayIcon

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#include <String.au3>

Global Const $CBN_SETFOCUS = 3

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=E:\PreSHell.kxf

$PreShell = GUICreate("PreShell", 426, 279, 194, 126)

GUISetFont(10, 400, 0, "MS Sans Serif")

$TotalRAMLabel = GUICtrlCreateLabel("Total RAM", 16, 8, 148, 20)

$FreeRAMLabel = GUICtrlCreateLabel("Free RAM", 176, 8, 161, 20)

$StartShell = GUICtrlCreateButton("Start Shell", 296, 248, 121, 25)

$PageFileGroup = GUICtrlCreateGroup("Page file", 8, 32, 409, 121)

$DriveCombo = GUICtrlCreateCombo("", 80, 56, 169, 25)

$Label3 = GUICtrlCreateLabel("Drive", 40, 60, 36, 20)

$Label4 = GUICtrlCreateLabel("Size", 48, 92, 30, 20)

$Label5 = GUICtrlCreateLabel("MB", 176, 92, 24, 20)

$ApplyPageFile = GUICtrlCreateButton("Apply", 288, 120, 121, 25, 0)

$Label6 = GUICtrlCreateLabel("File name", 16, 124, 63, 20)

$PageFileName = GUICtrlCreateInput("PE_PageFile", 80, 120, 177, 24)

$PageFileSize = GUICtrlCreateCombo("PageFileSize", 80, 88, 89, 25)

GUICtrlSetData(-1, "64|128|256|512|768|1024|1280|1536|1792|2048","512")

$Information = GUICtrlCreateLabel("Information", 8, 252, 281, 20)

GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlSetOnEvent($StartShell, "StartShellClick")

GUICtrlSetOnEvent($ApplyPageFile, "ApplyPageFileClick")

#EndRegion ### END Koda GUI section ###

Func StartShellClick()

StopTimer()

RegWrite("HKEY_LOCAL_MACHINE\TMP\Setup","CmdLine","REG_SZ","explorer.exe")

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","Shell","REG_SZ","explorer.exe")

GUISetState(@SW_HIDE)

RunWait(EnvGet("SystemRoot") & "\EXPLORER.EXE")

GUISetState(@SW_SHOW)

EndFunc

Func ApplyPageFileClick()

StopTimer()

If FileExists(@ScriptDir & "\SetPageFile.exe") Then

$DrivePath = StringLeft(GUICtrlRead($DriveCombo),1) & ":\" & GUICtrlRead($PageFileName)

If FileExists($DrivePath) Then FileDelete($DrivePath)

$Result = ShellExecuteWait(@ScriptDir & "\SetPageFile.exe",$DrivePath & " " & GUICtrlRead($PageFileSize))

If FileExists($DrivePath) Then

MsgBox(0,"Result","Page file created.")

Else

MsgBox(0,"Result","Page file creation failed!!")

EndIf

Else

MsgBox(0,"Error","Can't find SetPageFile.exe!")

EndIf

EndFunc

Func StopTimer()

$TimerOn = False

GUICtrlSetData($Information,"Shell will not start automatically")

EndFunc

; For detecting when a non-button control is clicked (i.e. gets focus)

Func CheckForGotFocus($hWnd, $msg, $wParam, $lParam)

Local $nID = _LoWord($wParam)

If $nID = $CBN_SETFOCUS Then StopTimer()

EndFunc

Func _HiWord($x)

Return BitShift($x, 16)

EndFunc ;==>_HiWord

Func _LoWord($x)

Return BitAND($x, 0xFFFF)

EndFunc ;==>_LoWord

; Set up to detect when non-button controls get focus

GUIRegisterMsg($WM_COMMAND, "CheckForGotFocus")

$mem = MemGetStats()

GUICtrlSetData($TotalRAMLabel,"Total RAM " & _StringAddThousandsSep(Round($mem[1]/1024)) & " MB")

GUICtrlSetData($FreeRAMLabel,"Free RAM " & _StringAddThousandsSep(Round($mem[2]/1024)) & " MB")

; Populate the drive list

$DriveList = ""

$FixedDrives = DriveGetDrive("FIXED")

If Not @error Then

For $i = 1 To $FixedDrives[0]

$DriveList = $DriveList & "|" & StringUpper($FixedDrives[$i]) & " (" & _StringAddThousandsSep(Round(DriveSpaceFree($FixedDrives[$i] & "\"))) & " MB free)"

Next

$DriveList = StringTrimLeft($DriveList, 1)

$DriveArray = StringSplit($DriveList, "|")

GUICtrlSetData($DriveCombo, $DriveList, $DriveArray[1])

EndIf

GUISetState(@SW_SHOW)

$TimerOn = True

$TimerTenths = 0

$TimerSeconds = 10

GUICtrlSetData($Information,"Shell starts automatically in " & $TimerSeconds & " seconds.")

While 1

Sleep(100)

If $TimerOn Then

$TimerTenths += 1

If $TimerTenths = 10 Then

$TimerTenths = 0

$TimerSeconds -= 1

GUICtrlSetData($Information,"Shell starts automatically in " & $TimerSeconds & " seconds.")

If $TimerSeconds = 0 Then StartShellClick()

EndIf

EndIf

WEnd

Edited by JonF

Share this post


Link to post
Share on other sites
rasim

JonF

unless the user clicks on any control

Any control of the AutoIt GUI?

Share this post


Link to post
Share on other sites
ProgAndy

Hmm, you should use OnEventMode :mellow:

GUICreate("test")
$butt = GUICtrlCreateButton("HI",10,10)
$Information = GUICtrlCreateLabel("",10,90,380,30)
$TimerOn = True
$TimerSeconds = 30
$TimerStart = TimerInit()
GUISetState()
While 1
    $MSG = GUIGetMsg()
    If $MSG > 2 Then
        $TimerOn = False
        GUICtrlSetData($Information,"Shell won't start automatically.")
    EndIf
    If $TimerOn And TimerDiff($TimerStart) > 999 Then
        $TimerSeconds -= 1
        $TimerStart = TimerInit()
        GUICtrlSetData($Information,"Shell starts automatically in " & $TimerSeconds & " seconds.")
        If $TimerSeconds = 0 Then 
            StartShellClick()
            ExitLoop
        EndIf
    EndIf
    Switch $MSG
        Case $butt
            MsgBox(0, '', "kk")
        Case -3
            ExitLoop
    EndSwitch
WEnd

Func StartShellClick()
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.