Jump to content



Photo

Pop-ups UDF


  • Please log in to reply
7 replies to this topic

#1 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 12 July 2010 - 09:50 PM

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.


Posted Image


Pop-ups UDF Library v1.0 (Example and all images included)
(Previous downloads: 22)

Attached File  Pop-ups.zip   32.07K   1043 downloads


Example

AutoIt         
#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, 15 July 2010 - 07:41 AM.






#2 AdmiralAlkex

AdmiralAlkex

    I'm on a boat

  • MVPs
  • 4,490 posts

Posted 12 July 2010 - 11:44 PM

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.

#3 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 13 July 2010 - 03:57 AM

But you really should change the HotKey's to...

Yes, you're right. Thanks.

Edited by Yashied, 13 July 2010 - 03:58 AM.


#4 4ggr35510n

4ggr35510n

    Wayfarer

  • Active Members
  • Pip
  • 91 posts

Posted 15 August 2010 - 07:11 PM

Better then grandmas pancakes!

#5 eracross

eracross

    Wayfarer

  • Active Members
  • Pip
  • 57 posts

Posted 10 October 2010 - 10:53 AM

Wow nice i rly like it ;)
btw how to make it transparent i mean click through it

#6 Aktonius

Aktonius

    Prodigy

  • Active Members
  • PipPipPip
  • 182 posts

Posted 03 December 2012 - 01:08 PM

very nice

#7 chandoi

chandoi

    Seeker

  • Active Members
  • 15 posts

Posted 23 December 2012 - 01:45 AM

oh nice

#8 z0iid

z0iid

    Seeker

  • Active Members
  • 28 posts

Posted 17 May 2013 - 05:58 PM

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:

 

AutoIt         
#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, 17 May 2013 - 06:02 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users