I'm calling a function, and in that function is where I set the popup_register and popup_show - then i stick it in a while loop for 5 seconds waiting for user activity, and if none, then i dispose of the popup and go back to my main loop.
i get the error sometimes (but not everytime, probably only once every 20 times) within those 5 seconds.
#AutoIt3Wrapper_icon=.\logoff.ico
#include <GuiRichEdit.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <timers.au3>
#include <ad.au3>
#include <WinAPI.au3>
#include <array.au3>
#include <file.au3>
#Include <GDIPlus.au3>
#Include <Pop-ups.au3>
;~ #include <GuiListBox.au3>
;~ #include <GuiListView.au3>
;~ #include <ProgressConstants.au3>
#include <ButtonConstants.au3>
#include <guiedit.au3>
AutoItSetOption("TrayIconHide", 1)
OnAutoItExitRegister("_FontCleanUp")
Global $ahFontEx[1] = [0]
Global $array_limit, $port, $time_lbl, $hWnd, $idletime, $dispname, $hGUI_OV, $lapse, $EditM, $EditV, $logdataF, $vn_idle, $iidletime, $begin_Fade, $lapse_timout, $vidletime
Global $mmoveflag = 42
Global $gui_up = 0
$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 78);sm_virtualwidth
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
$VirtualDesktopHeight = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 79);sm_virtualheight
$VirtualDesktopHeight = $VirtualDesktopHeight[0]
$VirtualDesktopX = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 76);sm_xvirtualscreen
$VirtualDesktopX = $VirtualDesktopX[0]
$VirtualDesktopY = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", 77);sm_yvirtualscreen
$VirtualDesktopY = $VirtualDesktopY[0]
HotKeySet("{ESC}", "_hide")
HotKeySet("!{F9}", "_quit")
HotKeySet("!{F2}", "_fade")
$textfont = "Bell MT Regular"
$clientfile = "c:\post\client.txt"
$picfile = "c:\post\fadeout\images\userpic.png"
Global $max_trans = 255 ; How transparent do you want the window, 0 = hidden, 255 = fully shown
Global $GUIFADE_MAXTRANS = 255 ; the current max transparency level
Dim $hGUI, $maxtime = 0
$rev = 0
$seconds = 1000
; ===Settings that can be changed based on Informatics or Leadership decision===
;
; $inittime + $free_out is the total time a user has to interact with the computer without being bothered with verification/question prompt
;
$inittime =60 * $seconds ;time before fade begins after inactivity
$first_delay = 5 * $seconds ;time fade screen pauses at first fade step down
$second_delay = 10 * $seconds ;time fade screen pauses at second fade step down
$free_out = 30 * $seconds ; should NEVER be less than $first_delay + $second_delay - this is the time that a user can interact with the computer after the fade begins before being forced to verify by photo
$verify_timeout = 5 * $seconds ;time photo verify stays up (without user interaction) before going back to screensaver
; ~~~~~~~~~~~ END CONF ~~~~~~~~~~~
Func _main
()
While 1
$iIdleTime = _Timer_GetIdleTime()
If FileExists($clientfile) And $mmoveflag <> 1 Then
$mpos = MouseGetPos()
MouseMove($mpos[0] + 1, $mpos[1] + 1,2)
$mmoveflag = 1
Sleep(2)
EndIf
$iIdleTime = _Timer_GetIdleTime()
If $iIdleTime >= $inittime And WinExists("_fadeout") <> 1 And FileExists($clientfile) = 1 Then
$begin_Fade = TimerInit()
_Fade
()
While FileExists($clientfile) = 1 or $iidletime >= $inittime
If $iidletime < $vn_idle Then
$vn_idle = 0
ExitLoop
EndIf
$iIdleTime = _Timer_GetIdleTime()
If $iIdleTime < $inittime Then
Select
Case TimerDiff($begin_Fade) <= $free_out or FileExists($picfile) = 0
_FadeGUIOut
($hGUI)
ContinueLoop 2
Case TimerDiff($begin_Fade) > $free_out; and TimerDiff($lapse_timout) > 1000
$iIdleTime = $iIdleTime + $inittime
_VerifyUser
()
EndSelect
If $lapse = 5 Then
ContinueLoop
Else
Return 99
EndIf
ExitLoop
EndIf
If $iIdleTime < $inittime and WinExists("_fadeout") = 1 or FileExists($clientfile) = 0 Then
EndIf
;~ Sleep(100)
If GUICtrlRead($time_lbl) <> @HOUR & ":" & @MIN Then
GUICtrlSetData($time_lbl, @HOUR & ":" & @MIN)
EndIf
sleep(100)
WEnd
EndIf
sleep(100)
WEnd
EndFunc
Func _Fade
() ;Creates blank black screen gui with full transparency, fades in to non-transparent (by calling _FadeGuiIn) , adds Display Name, time, and text
$hGUI = GuiCreate("_fadeout", $VirtualDesktopWidth + 10, $VirtualDesktopHeight + 100, -10,-10, $WS_POPUP + $WS_DLGFRAME, $WS_EX_APPWINDOW + $WS_EX_TOPMOST)
GUISetBkColor(0)
_FadeGUIIn
($hGUI,$max_trans)
$dispname = FileReadLine("c:\post\client.txt")
If StringLen($dispname) < 20 Then
$fontsize = 60
$offset = 250
ElseIf StringLen($dispname) > 30 Then
$fontsize = 40
$offset = 230
Else
$fontsize = 50
$offset = 240
EndIf
$Label3 = GUICtrlCreateLabel("____________________________________________", 150 , (@DesktopHeight / 2) - 50, 850, 20)
GUICtrlSetColor($Label3, 0xFFFFFF)
GUICtrlSetFont($Label3, 12, 400, 0, $textfont, 4)
$label2 = GUICtrlCreateLabel("Not you? Tap your badge to login.", 150 , (@DesktopHeight / 2) - 20, 450, 80)
GUICtrlSetColor($Label2, 0xFFFFFF)
GUICtrlSetFont($Label2, 20, 500, 0, $textfont, 4)
$verticalline = GUICtrlCreateLabel("______________________________________________", @DesktopWidth - 480, (@DesktopHeight /2) - 55 , 400, 400, 0x001)
GUICtrlSetColor($verticalline, 0xFF7738)
_GuiCtrlSetFont
($verticalline, 12, 400, 0, -90, $textfont, 4)
$time_lbl = GUICtrlCreateLabel(@HOUR & ":" & @MIN, @DesktopWidth - 360, (@DesktopHeight /2) - 40, 300, 100)
GUICtrlSetColor($time_lbl, 0xFF7738)
GUICtrlSetFont($time_lbl, 70, 600, 0, $textfont, 4)
$Label1 = GUICtrlCreateLabel($dispname, 150 , (@DesktopHeight / 2) - $offset, 950, 105, $SS_LEFTNOWORDWRAP)
GUICtrlSetColor($Label1, 0xFFFFFF)
GUICtrlSetFont($Label1, $fontsize, 600, 0, $textfont, 4)
$Label4 = GUICtrlCreateLabel("is logged in", 250 , (@DesktopHeight / 2) - 150, 850, 20)
GUICtrlSetColor($Label4, 0xFFFFFF)
GUICtrlSetFont($Label4, 12, 400, 0, $textfont, 4)
EndFunc
Func _FadeGUIIn
($hWnd,$iMax=255) ;called from _Fade function
$GUIFADE_MAXTRANS = $iMax
WinSetTrans($hWnd, "", 0)
GUISetState(@SW_SHOW)
For $i = 1 To 85 Step 2
WinSetTrans($hWnd, "", $i)
Next
_CheckIdle
($first_delay, 1)
For $i = 86 To 170 Step 2
WinSetTrans($hWnd, "", $i)
Next
_CheckIdle
($first_delay + $second_delay, 2)
For $i = 171 To 255 Step 2
WinSetTrans($hWnd, "", $i)
Next
EndFunc ;==>_FadeGUIIn
Func _FadeGUIOut
($hWnd)
GuiSetState($hWnd, @SW_HIDE)
GUIDelete($hWnd)
$gui_up = 0
$maxtime = 0
EndFunc ;==>_FadeGUIOut
Func _quit
()
Exit
EndFunc
Func _CheckIdle
($maxtime, $rev)
$iIdleTime = _Timer_GetIdleTime()
While $iIdleTime < $inittime + $maxtime
If $iIdleTime < $inittime Then
_FadeGUIOut
($hGUI)
Return 1
EndIf
Sleep(100)
$iIdleTime = _Timer_GetIdleTime()
WEnd
If $iIdleTime < $inittime Then
_FadeGUIOut
($hGUI)
Return 1
Else
EndIf
$maxtime = 0
EndFunc
Func _FontCleanUp
()
For $i = 1 To $ahFontEx[0]
_WinAPI_DeleteObject($ahFontEx[$i])
Next
EndFunc
Func _GuiCtrlSetFont
($controlID, $size, $weight = 400, $attribute = 0, $rotation = 0, $fontname= "", $quality = 2)
Local $fdwItalic = BitAND($attribute, 1)
Local $fdwUnderline = BitAND($attribute, 2)
Local $fdwStrikeOut = BitAND($attribute, 4)
ReDim $ahFontEx[UBound($ahFontEx) + 1]
$ahFontEx[0] += 1
$ahFontEx[$ahFontEx[0]] = _WinAPI_CreateFont($size, 0, $rotation * 10, $rotation, $weight, _
$fdwItalic, $fdwUnderline, $fdwStrikeOut, -1, 0, 0, $quality, 0, $fontname)
GUICtrlSendMsg($controlID, 48, $ahFontEx[$ahFontEx[0]], 1)
EndFunc
Func _Hide
()
GUIDelete($hWnd)
EndFunc
Func _VerifyUser
()
$vIdleTime = _Timer_GetIdleTime()
If $vidletime > $verify_timeout Then
Return 1
EndIf
Opt("Guioneventmode", 1)
Global $hPopup2 = _Popup
_Register
()
Global $hPopup1 = _Popup
_Register
()
;~ $image = @ScriptDir & "\dummyimage.png"
;~ $image = @ScriptDir & "\NOimage.png"
$xrand = Random(25, @DesktopWidth - 545)
_GDIPlus_Startup()
$hGUI_OV = GuiCreate("_fOverlay", $VirtualDesktopWidth + 10, $VirtualDesktopHeight + 100, -10,-10, $WS_POPUP + $WS_DLGFRAME, $WS_EX_APPWINDOW + $WS_EX_TOPMOST)
$greybar = GUICtrlCreateLabel("", 0, $VirtualDesktopHeight - (($VirtualDesktopHeight/3) - 20), @DesktopWidth - 1, ($VirtualDesktopHeight/3) + 20)
GUICtrlSetState($greybar, $GUI_DISABLE)
$youq = GUICtrlCreateLabel("YOU?", $xrand, @DesktopHeight - 630 , 270, 105)
GUICtrlSetColor($youq, 0xFFFFFF)
GUICtrlSetFont($youq, 72, 800, 0, $textfont, 4)
GUICtrlSetBkColor($greybar, 0x3F3F3F)
$Label_smname = GUICtrlCreateLabel($dispname, $xrand, @DesktopHeight - 140,545, 40, $SS_LEFTNOWORDWRAP)
GUICtrlSetColor($Label_smname, 0xFFFFFF)
GUICtrlSetFont($Label_smname, 26, 400, 0, $textfont, 4)
GUICtrlSetBkColor($Label_smname, 0x3F3F3F)
GUISetBkColor(0)
GUISetState()
$Button1 = GUICtrlCreateButton("NO", @DesktopWidth - 280, @DesktopHeight - 70,260,70, BitOR($BS_FLAT,$BS_BITMAP), $WS_EX_STATICEDGE)
GUICtrlSetImage($Button1, @ScriptDir & "\nobtn.bmp", -1)
GUICtrlSetOnEvent($Button1, "_NoBtnClick")
$Button2 = GUICtrlCreateButton("YES", $xrand + 5, @DesktopHeight - 70 , 260, 70, BitOR($BS_FLAT,$BS_BITMAP), $WS_EX_STATICEDGE)
GUICtrlSetImage($Button2, @ScriptDir & "\yesbtn.bmp", -1)
GUICtrlSetOnEvent($Button2, "_YesBtnClick")
$hImage1 = _GDIPlus_ImageLoadFromFile($picfile)
_Popup
_Show
($hPopup1, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage1), 1, $xrand + 130, @DesktopHeight - 350, -1, 0)
$vIdleTime = _Timer_GetIdleTime()
Do
$vIdleTime = _Timer_GetIdleTime()
sleep(1)
Until $vidletime >= $verify_timeout or WinExists("_fOverlay") <> 1
$maxtime = 0
$lapse = 5
If $hPopup1 <> "" Then _popup
_hide
($hPopup1)
GUISetState(@SW_Hide)
if $hPopup1 <> "" Then _Popup
_Unregister
($hPopup1)
_GDIPlus_Shutdown()
GUIDelete($hGUI_OV)
EndFunc
Func _NoBtnClick
()
GUISetState($hGUI, @SW_HIDE)
GUIDelete($hGUI)
_popup
_hide
($hPopup1)
_Popup
_Unregister
($hPopup1)
_GDIPlus_Shutdown()
GUISetState("hGui_OV", @sw_hide)
GUIDelete($hGUI_OV)
Send("{F6}")
Exit
EndFunc
Func _YesBtnClick
()
_popup
_hide
($hPopup1)
_Popup
_Unregister
($hPopup1)
_GDIPlus_Shutdown()
GUISetState("hGui_OV", @sw_hide)
GUIDelete($hGUI_OV)
GUIDelete($hGUI)
$maxtime = 0
_FadeGUIOut
($hGUI)
$vn_idle = $iidletime + $inittime
EndFunc
Func _LogToEdit
($ctrl_ID, $data)
GUICtrlSetData($ctrl_ID, $data)
EndFunc
_main
()