Jump to content

Joemonkey

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by Joemonkey

  1. Thanks UEZ, I see what you did and it makes sense. However, I've recently found this script and it's working great! Here's how I have it coded with a 5 minute countdown and a repop to center ever 0.6 minutes: #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Timers.au3> #include <Date.au3> Global $iCountdown = 300 AutoItSetOption("GUIEventOptions", 1) Global $i_DPI_Ratio = _GetDPI() $i_DPI_Ratio = $i_DPI_Ratio[2] $Form1 = GUICreate("", 633, 350, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_WINDOWEDGE) ;GUISetBkColor(0x9F79EE) $Label1 = GUICtrlCreateLabel("Mesage header", 10, 10, 596, 50, $SS_CENTER) GUICtrlSetFont(-1, 20, 800, 0, "Arial") ;GUICtrlSetColor(-1, 0xffff00);Yellow $Label2 = GUICtrlCreateLabel('Message Text...' & @CRLF & @CRLF & "and then click the OK button below.", 20, 58, 590, 170) GUICtrlSetFont(-1, 14, 800, 0, "Arial") $Label3 = GUICtrlCreateLabel("(Message Note)", 20, 228, 588, 25, $SS_CENTER) GUICtrlSetFont(-1, 12, 800, 6, "Arial") ;GUICtrlSetColor(-1, 0x00008B);Dark Blue $Button = GUICtrlCreateButton("OK", 240, 265, 145, 41, 0) $Label4 = GUICtrlCreateLabel(" This Window will automatically close and continue the installation in 5 minutes. Time: " & _SecsToTime($iCountdown), 24, 325, 588, 25) GUISetState(@SW_SHOW) $wPos = WinGetPos($Form1) $timer = TimerInit() ;added initial timestamp _Timer_SetTimer($Form1, 1000, '_Countdown') While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button Run("notepad.exe") Exit EndSwitch If TimerDiff($timer) > 36000 Then $newPos = WinGetPos($Form1) If $newPos[0] <> $wPos[0] Or $newPos[1] <> $wPos[1] Then WinMove($Form1, "", $wPos[0], $wPos[1]) $timer = TimerInit();resets the timestamp EndIf WEnd Func _Countdown($hWnd, $iMsg, $iIDTimer, $dwTime) $iCountdown -= 1 If $iCountdown > 0 Then GUICtrlSetData($Label4, " This Window will automatically close and continue the installation in 5 minutes. Time: " & _SecsToTime($iCountdown)) ElseIf $iCountdown = 0 Then _Timer_KillTimer($hWnd, $iIDTimer) ControlClick($Form1, '', $Button) EndIf EndFunc ;==>_Countdown Func _SecsToTime($iSecs) Local $iHours, $iMins, $iSec_s _TicksToTime($iSecs*1000,$iHours,$iMins,$iSec_s) Return StringFormat("%02i:%02i",$iMins, $iSec_s) EndFunc Func _GetDPI() Local $a1[3] Local $iDPI, $iDPIRat, $Logpixelsy = 90, $Form1 = 0 Local $hDC = DllCall("user32.dll", "long", "GetDC", "long", $Form1) Local $aRet = DllCall("gdi32.dll", "long", "GetDeviceCaps", "long", $hDC[0], "long", $Logpixelsy) Local $hDC = DllCall("user32.dll", "long", "ReleaseDC", "long", $Form1, "long", $hDC) $iDPI = $aRet[0] ;; Set a ratio for the GUI dimensions based upon the current DPI value. Select Case $iDPI = 0 $iDPI = 96 $iDPIRat = 94 Case $iDPI < 84 $iDPIRat = $iDPI / 105 Case $iDPI < 121 $iDPIRat = $iDPI / 96 Case $iDPI < 145 $iDPIRat = $iDPI / 95 Case Else $iDPIRat = $iDPI / 94 EndSelect $a1[0] = 2 $a1[1] = $iDPI $a1[2] = $iDPIRat ;; Return the array Return $a1 EndFunc ;==>_GetDPI Func _GUICtrlSetFont_Ex($icontrolID = -1, $iSize = 8.5, $iweight = 400, $iattribute = 0, $sfontname = Default, $iquality = 2) GUICtrlSetFont($icontrolID, $iSize / $i_DPI_Ratio, $iweight, $iattribute, $sfontname, $iquality) EndFunc ;==>_GUICtrlSetFont_Ex Func _GUISetFont_Ex($iSize = 12, $iweight = 400, $iattribute = 0, $sfontname = Default, $Form1 = Default, $iquality = 2) If Not IsHWnd($Form1) Then $Form1 = WinGetHandle($Form1) ;<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISwitch($Form1) ;<<<<<<<<<<<<<<<<<<<< ConsoleWrite("GUISwitch(0)" & @TAB & $Form1 & @TAB & WinGetTitle($Form1) & @CRLF) ConsoleWrite("WinGetHandle([ACTIVE])" & @TAB & WinGetHandle("[ACTIVE]") & @TAB & WinGetTitle(WinGetHandle("[ACTIVE]")) & @CRLF) GUISetFont($iSize / $i_DPI_Ratio, $iweight, $iattribute, $sfontname, $Form1, $iquality) EndFunc ;==>_GUISetFont_Ex
  2. that's not exactly what I want, and now I see a problem with having 2 timers. The TimerDiff section of my existing script is there in case someone moves the popup box off the screen. Every hour it will check for the GUI's coordinates and if they don't match the original it will move it back. I'll probably end up changing that to every 30 minutes, but I'd like to have a timer that counts down from say 2 hours then runs the Yes button command. For example: case 1: GUI shows up with a 2 hour counting down timer, user clicks Yes, notepad.exe is ran. case 2: GUI shows up with a 2 hour counting down timer, user moves it off the screen, 30 minutes later it repops to center, user clicks Yes, notepad.exe is ran. case 3: GUI shows up with a 2 hour counting down timer, user does nothing for 2 hours, notepad.exe is ran
  3. I have this script that works great for a GUI box with a Yes button that thanks to you guys takes DPI into consideration and also repops to the center of the screen every hour if someone moves it #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> AutoItSetOption("GUIEventOptions", 1) Global $i_DPI_Ratio = _GetDPI() $i_DPI_Ratio = $i_DPI_Ratio[2] $Form1 = GUICreate("Title", 447, 205, -1, -1, Default, $WS_EX_TOPMOST) _GUISetFont_Ex(12, 400, 0, 'Arial', $Form1) ; GUICtrlCreateLabel("Line 1", 10, 10) GUICtrlCreateLabel("Line 2", 10, 28) GUICtrlCreateLabel("Line 3 ", 10, 46) GUICtrlCreateLabel("YES?", 26, 152) $Yesbutton = GUICtrlCreateButton("YES", 274, 152, 75, 25) GUISetState(@SW_SHOW) $wPos = WinGetPos($Form1) $timer = TimerInit() ;added initial timestamp While 1 $msg = GUIGetMsg() Select Case $msg = $Yesbutton Run("notepad.exe") Exit EndSelect If TimerDiff($timer) > 3600000 Then $newPos = WinGetPos($Form1) If $newPos[0] <> $wPos[0] Or $newPos[1] <> $wPos[1] Then WinMove($Form1, "", $wPos[0], $wPos[1]) $timer = TimerInit();resets the timestamp EndIf WEnd Func _GetDPI() Local $a1[3] Local $iDPI, $iDPIRat, $Logpixelsy = 90, $Form1 = 0 Local $hDC = DllCall("user32.dll", "long", "GetDC", "long", $Form1) Local $aRet = DllCall("gdi32.dll", "long", "GetDeviceCaps", "long", $hDC[0], "long", $Logpixelsy) Local $hDC = DllCall("user32.dll", "long", "ReleaseDC", "long", $Form1, "long", $hDC) $iDPI = $aRet[0] ;; Set a ratio for the GUI dimensions based upon the current DPI value. Select Case $iDPI = 0 $iDPI = 96 $iDPIRat = 94 Case $iDPI < 84 $iDPIRat = $iDPI / 105 Case $iDPI < 121 $iDPIRat = $iDPI / 96 Case $iDPI < 145 $iDPIRat = $iDPI / 95 Case Else $iDPIRat = $iDPI / 94 EndSelect $a1[0] = 2 $a1[1] = $iDPI $a1[2] = $iDPIRat ;; Return the array Return $a1 EndFunc ;==>_GetDPI Func _GUICtrlSetFont_Ex($icontrolID = -1, $iSize = 8.5, $iweight = 400, $iattribute = 0, $sfontname = Default, $iquality = 2) GUICtrlSetFont($icontrolID, $iSize / $i_DPI_Ratio, $iweight, $iattribute, $sfontname, $iquality) EndFunc ;==>_GUICtrlSetFont_Ex Func _GUISetFont_Ex($iSize = 12, $iweight = 400, $iattribute = 0, $sfontname = Default, $Form1 = Default, $iquality = 2) If Not IsHWnd($Form1) Then $Form1 = WinGetHandle($Form1) ;<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISwitch($Form1) ;<<<<<<<<<<<<<<<<<<<< ConsoleWrite("GUISwitch(0)" & @TAB & $Form1 & @TAB & WinGetTitle($Form1) & @CRLF) ConsoleWrite("WinGetHandle([ACTIVE])" & @TAB & WinGetHandle("[ACTIVE]") & @TAB & WinGetTitle(WinGetHandle("[ACTIVE]")) & @CRLF) GUISetFont($iSize / $i_DPI_Ratio, $iweight, $iattribute, $sfontname, $Form1, $iquality) EndFunc ;==>_GUISetFont_Ex I'm trying to add in a countdown that will, when counted down to zero, perform the same action as clicking the YES button. I found lots of good countdown code here by searching but when I try to insert it various places I either get no countdown, or clicking the Yes button doesn't work. I'm trying to inject most of the code found here: I think my problem is I don't know how to have both the While and Do run simultaneously. Ideally I'd like to have a "Line 4" that displays the countdown in HH:MM:SS and when the time is up does the action assigned to the Yes button. Any help is greatly appreciated!
  4. After I read through the code a few times it made sense and I was able to implement it. Thanks!
  5. Is there any way to code it to read the setting (100%, 125%, 150%) and if it's set to 100%, run the GUI, but if it's set to 125 or 150 it reads that value in, sets it to 100%, then on GUI exit set it back to the way it was? Sorry if this is considered thread necromancy, I'm having the same issue and didn't want to start a new thread
  6. Thanks for the fast reply Realm, I had code similar to that working but I only want the window to check every 60 minutes to see if it needs to reposition itself, not instantly. It seems if I put a Sleep command in there it breaks the functionality of my Yes button.
  7. Is there a way to incorporate this into a GUI that also has a button? It seems if I try to use this along with a button the sleep prevents the button from being pushed. What I would like to do is have my GUI pop up, the user can hit Yes at any time (not waiting for a Sleep function) but have the GUI re-pop to center once every 60 minutes. Here is my existing code #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> AutoItSetOption("GUIEventOptions", 1) $Form1 = GUICreate("title", 447, 205, -1, -1, Default, $WS_EX_TOPMOST) GUISetFont(12) GUICtrlCreateLabel("blah blah blah click Yes to reboot. ", 10, 10) $Yesbutton = GUICtrlCreateButton("Yes", 274, 152, 75, 25) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $Yesbutton Run("shutdown.exe /r /t 0") Exit EndSelect WEnd
×
×
  • Create New...