Jump to content

Pop-ups UDF


Yashied
 Share

Recommended Posts

LAST VERSION - 1.0

12-Jul-10

This library allows to create and manage a pop-up windows are based on your images (transparency also supported). Use this UDF is very simple: create or load the bitmap from a file and display it on desktop screen by using _Popup_Show() function (see example). Run the example that is below, and press SHIFT+1 or SHIFT+2 (several times). iKey and iSwitcher from my sig. also based on this "engine". Try playing with this UDF, and please post any comments and suggestions.

Pop-ups.png

Available functions

_Popup_Hide

_Popup_IsActive

_Popup_Register

_Popup_Show

_Popup_Unregister

_Popup_Update

Pop-ups UDF Library v1.0

Previous downloads: 122

Pop-ups.zip

Example

#Include <GDIPlus.au3>
#Include <Pop-ups.au3>

Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)

_GDIPlus_Startup()

Global $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image1.png'), $hImage2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image2.png')
Global $hPopup1 = _Popup_Register(), $hPopup2 = _Popup_Register()

HotKeySet('+1', '_Popup1') ; SHIFT+1
HotKeySet('+2', '_Popup2') ; SHIFT+2

While 1
    Sleep(1000)
WEnd

_GDIPlus_Shutdown()

Func _Popup1()

    Local $hGraphic, $hArea, $hBitmap, $hFamily, $hFont, $hFormat, $hBrush, $tLayout, $aData
    Local $Text = StringFormat('%01d:%02d', @HOUR, @MIN)

    ; Draw current time (xx:xx) on "Image1.png" and create bitmap
    $hArea = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 133, 133, $GDIP_PXF32ARGB)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hArea)
    $hFamily = _GDIPlus_FontFamilyCreate('Tahoma')
    $hFont = _GDIPlus_FontCreate($hFamily, 38, 0, 2)
    $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hBrush = _GDIPlus_BrushCreateSolid(0xC0FFFFFF)
    _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3)
    $aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat)
    $tLayout = $aData[0]
    DllStructSetData($tLayout, 1, (133 - DllStructGetData($tLayout, 3)) / 2)
    DllStructSetData($tLayout, 2, (133 - DllStructGetData($tLayout, 4)) / 2)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hArea)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_ImageDispose($hArea)

    ; Show pop-up image
    _Popup_Show($hPopup1, $hBitmap, 1)

EndFunc   ;==>_Popup1

Func _Popup2()
    ; Show or hide pop-up image ("Image2.png")
    If Not _Popup_IsActive($hPopup2) Then
        _Popup_Show($hPopup2, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage2), 1, @DesktopWidth - 90, @DesktopHeight - 110, -1)
    Else
        _Popup_Hide($hPopup2)
    EndIf
EndFunc   ;==>_Popup2

#Region GDI+ Functions

Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint)

    Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipSetTextRenderingHint', 'ptr', $hGraphics, 'int', $iTextRenderingHint)

    If @error Then
        Return SetError(1, 0, 0)
    Else
        If $aResult[0] Then
            Return SetError($aResult[0], 0, 0)
        EndIf
    EndIf
    Return 1
EndFunc   ;==>_GDIPlus_GraphicsSetTextRenderingHint

#EndRegion GDI+ Functions
Edited by Yashied
Link to comment
Share on other sites

This is pretty neat :blink:

Where did you get the images? Did you create them yourself? They are awesome.

But you really should change the HotKey's to:

HotKeySet('+{1}', '_Popup1') ; SHIFT+1
HotKeySet('+{2}', '_Popup2') ; SHIFT+2

Instead of telling people it's Shift+1 and Shift+2 when it isn't that at all.

Take a look at the Swedish layout as an example.

Having to press Shift+AltGr+2 or Shift+Alt+Ctrl+2 (Ctrl+Alt is the same as AltGr) is pretty confusing when you say Shift+2.

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 2 years later...
  • 3 weeks later...
  • 4 months later...

hopefully Yashied is still following this thread.  :) 

I may be using this pop-up in a way it wasn't intended, but I'm occasionally getting the "subscript used with non-array variable" error message.

(for line 412 - If $ppData[$i][9 ] Then )

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.

here is the simple do loop code:
 

Do
        $vIdleTime = _Timer_GetIdleTime()

        sleep(1)

    Until $vidletime >= $verify_timeout or WinExists("_fOverlay") <> 1

Here is my full messy code:

 

#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()
Edited by z0iid
Link to comment
Share on other sites

  • 6 months later...
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...