JonF Posted November 2, 2008 Share Posted November 2, 2008 (edited) 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 = 3Opt("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)EndFuncFunc 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!") EndIfEndFuncFunc 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()EndFuncFunc _HiWord($x) Return BitShift($x, 16)EndFunc ;==>_HiWordFunc _LoWord($x) Return BitAND($x, 0xFFFF)EndFunc ;==>_LoWord; Set up to detect when non-button controls get focusGUIRegisterMsg($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])EndIfGUISetState(@SW_SHOW)$TimerOn = True$TimerTenths = 0$TimerSeconds = 10GUICtrlSetData($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 EndIfWEnd Edited November 2, 2008 by JonF Link to comment Share on other sites More sharing options...
rasim Posted November 3, 2008 Share Posted November 3, 2008 JonFunless the user clicks on any controlAny control of the AutoIt GUI? Link to comment Share on other sites More sharing options...
JonF Posted November 3, 2008 Author Share Posted November 3, 2008 Yes. Any control. Link to comment Share on other sites More sharing options...
ProgAndy Posted November 3, 2008 Share Posted November 3, 2008 Hmm, you should use OnEventMode 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now