Sign in to follow this  
Followers 0
GioVit

Notify Window

41 posts in this topic

#1 ·  Posted (edited)

This is a sliding popup window with a clickable notification text and timeout feature, useful for remind and take a decision before close.

Enjoy it !

Don't forget to download the attached image at the botom of this post (save as exit.jpg)

#include <GUIConstants.au3>
#include <Color.au3>
Opt("GuiOnEventMode",1)
Dim $Label
Dim $move, $Xpos, $Ypos, $TrayWnd, $Xexit, $Yexit
Dim $iStartColor = 0x0000ff, $iEndColor = 0xffffff
Dim $iSize = -1, $iWeight = -1, $iAttribute = 4, $iFontName = -1
Dim $Clicked = 0
Dim $iWinWidth = 160, $iWinHeight = 160

;========== Test
_SetPopupBackground(0xffff00, 0xffffff)
$Ret = _Popup("MyPopup", "You have 3 mails", 3000)
if $Ret = 0 Then
    $Mensa = "Time out"
ElseIf $Ret = -1 Then
    $Mensa = "Exit Pressed"
Else
    $Mensa = "Seleccionado " & $Ret
EndIf
MsgBox(0,"Test", $Mensa,2)
Exit

;========= End Test

;===============================================================================
;
; Function Name:    _SetPopupSize()
; Description:      Set the size of the Popup Window
;
; Parameter(s):     $WinWidth       - Popup window width
;                   $WinHeight      - Popup window height
;
; Requirement(s):   None
; Return Value(s):  None
;
; Author(s):        GioVit <gvitale@cantv.net>
;
;===============================================================================



Func _SetPopupSize($WinWidth, $WinHeight)
    $iWinWidth = $winWidth
    $iWinHeight = $WinHeight
EndFunc


;===============================================================================
;
; Function Name:    _SetPopupBackround()
; Description:      Set the Attributes of the font the Hyperlink Label
;
; Parameter(s):     $Size            - Font size
;                   $Weight            - Font weight
;                    $Attibutes        - Font Attributes
;                    $FontName        - Self explanatory
;
; Requirement(s):   None
; Return Value(s):  None
;
; Author(s):        GioVit <gvitale@cantv.net>
;
;===============================================================================

Func _SetPopupFont($Size, $Weight= - 1, $Attribute = 4, $FontName = -1)
    $iSize = $Size
    $iWeight = $Weight
    $Attribute = Bitor($Attribute, 4)
    $iAttribute = $Attribute
    $iFontName = $FontName
EndFunc

;===============================================================================
;
; Function Name:    _SetPopupBackround()
; Description:      Set the Popup Window gradient colors
;
; Parameter(s):     $StartColor        - Popup window width
;                   $EndColor        - Popup window height
;
; Requirement(s):   None
; Return Value(s):  None
;
; Author(s):        GioVit <gvitale@cantv.net>
;
;===============================================================================


Func _SetPopupBackground($StartColor, $EndColor)
    $iStartColor = $StartColor
    $iEndColor = $EndColor
EndFunc

;===============================================================================
;
; Function Name:    _Popup()
; Description:      Display a sliding popup window from the taskbar displaying a Clickable Control Label
;
; Parameter(s):     $Title            - A window Title (Not Shown)
;                   $Message        - The Clickable text displayed in the window
;                    $Timeout        - [optional] Timeout in miliseconds. After the timeout has elapsed the popup window will be automatically closed.
;
; Requirement(s):   None
; Return Value(s):  -1 = Exit Button was Clicked
;                    0  = Timeout elapsed
;                    1  = Message was Clicked
;
; Author(s):        GioVit <gvitale@cantv.net>
;
;===============================================================================

Func _Popup($Title, $Message, $Timeout = 0)
    $OldEventMode = AutoItSetOption("GuiOnEventMode",1)
    $PreviousMode = AutoItSetOption("WinTitleMatchMode", 4)
    $TrayWnd = WinGetPos("classname=Shell_TrayWnd")
    AutoItSetOption("WinTitleMatchMode", $PreviousMode)    
    $pos = ControlGetPos("Program Manager", "", "SysListView321")
    $x = $pos[0]
    $y = $pos[1]
    $w = $pos[2]
    $h = $pos[3]
    
    If $TrayWnd[1] > 0 Then
        $move = "Up"
        $Xpos = @DesktopWidth - $iWinWidth - 10
        $Ypos = $TrayWnd[1]
        $Xexit = 4
        $Yexit = 4
    Elseif $TrayWnd[0] > 0 Then
        $move = "Left"
        $Xpos = $TrayWnd[0]
        $Ypos = @DesktopHeight - $iWinHeight - 10
        $Xexit = 4
        $Yexit = 4
    ElseIf $TrayWnd[2] = @DesktopWidth Then
        $move = "Down"
        $Xpos = @DesktopWidth - $iWinWidth - 10
        $Ypos = $TrayWnd[1] + $TrayWnd[3] - $iWinHeight
        $Xexit = 4
        $Yexit = $iWinHeight - 19
    ElseIf $TrayWnd[3] = @DesktopHeight Then
        $move = "Right"
        $Xpos = $TrayWnd[0] + $TrayWnd[2] - $iWinWidth
        $Ypos = @DesktopHeight - $iWinHeight - 10
        $Xexit = $iWinWidth - 19
        $Yexit = 4
    EndIf
            
    $handle = GUICreate($Title, $iWinWidth, $iWinHeight, $Xpos, $Ypos, $WS_POPUPWINDOW,$WS_EX_TOOLWINDOW);$WS_SIZEBOX + $WS_POPUPWINDOW)
    _GUICtrlCreateGradient($iStartColor, $iEndColor, 1, 1, $iWinWidth, $iWinHeight,"H")
    $Label = _GuiCtrlCreateHyperlink($Message, 5, 24, $iWinWidth - 10, $iWinHeight - 48, 0x000000, 'Click Here', BitOR($GUI_SS_DEFAULT_LABEL, $SS_CENTER))
    GuiCtrlSetOnEvent($Label,"_Label")

    $EXIT = GUICtrlCreatePic ("exit.jpg",$Xexit, $Yexit,15,15,0x0100 )

    GUICtrlSetTip(-1, "Exit")
    GuiCtrlSetOnEvent($Exit,"_Exit")

    GUISetState(@SW_SHOW)
    ShowPopup($Title, $move)
    $i = 1
    if $Timeout > 0 Then
        while $i*10 < $Timeout
            Sleep(10)
            $i += 1
            if $Clicked Then ExitLoop
        WEnd
    Else
        While 1
            if $Clicked Then ExitLoop
        WEnd
    EndIf
    HidePopup($Title, $move)
    AutoItSetOption("GuiOnEventMode", $OldEventMode)
    Return $Clicked
EndFunc

Func ShowPopup($Title, $move)
    Select
    Case $move = "Down"
        GUIMove($Title, 0, $iWinHeight)
    Case $move = "Up"
        GUIMove($Title, 0, -$iWinHeight)
    Case $move = "Left"
        GUIMove($Title, -$iWinWidth, 0)
    Case $move = "Right"
        GUIMove($Title, $iWinWidth, 0)
    EndSelect
    
EndFunc

Func HidePopup($Title, $move)
    $Pxy = WinGetPos($Title)
    Select
    Case $move = "Down"
        GUIMove($Title, 0, -$Pxy[1]-$Pxy[3], 400, False)
    Case $move = "Up"
        GUIMove($Title, 0, @DesktopHeight-$Pxy[1], 400, False)
    Case $move = "Left"
        GUIMove($Title, @DesktopWidth - $Pxy[0], 0, 400, False)
    Case $move = "Right"
        GUIMove($Title, -$Pxy[0] - $Pxy[2], 0, 400, False)
    EndSelect
EndFunc

Func GUIMove($Title, $Dx=0, $Dy=0, $Time=700, $Showing = True)
Dim $Incx, $Incy, $IncTime, $Offsetx, $Offsety
    $Incx = $Dx/($Time/15)
    $Incy = $Dy/($Time/15)
    $IncTrans = 255/($Time/15)
    $Pxy = WinGetPos($Title)
    $i = 1
    While 1
        if $Showing Then
            WinSetTrans($Title, "", $IncTrans*$i)
        Else
            WinSetTrans($Title, "", 255 - $IncTrans*$i)
        EndIf    
        WinMove($Title,"", $Pxy[0]+$Incx*$i, $Pxy[1]+$Incy*$i)
        Sleep(15)
        if abs($Incx*$i) >= Abs($Dx) and Abs($Incy*$i) >= Abs($Dy) then ExitLoop
        $i += 1
        
    WEnd
EndFunc
Func _Exit()
    $Clicked = -1
EndFunc

Func _Label()
;MsgBox(0,"Info", "Click")
    $Clicked = 1
    Return 1
EndFunc


;===============================================================================
; Others Authors Code
;===============================================================================

;===============================================================================
;
; Function Name:    _GuiCtrlCreateHyperlink()
; Description:      Creates a label that acts as a hyperlink
;
; Parameter(s):     $s_Text       - Label text
;                   $i_Left          - Label left coord
;                   [$i_Top]      - Label top coord
;                    [$i_Width]      - Label width
;                   [$i_Height]      - Label height
;                    [$i_Color]      - Text Color
;                    [$s_ToolTip]  - Hyperlink ToolTip
;                    [$i_Style]      - Label style
;                    [$i_ExStyle]  - Label extended style
;
; Requirement(s):   None
; Return Value(s):  Control ID
;
; Author(s):        Saunders <krawlie@hotmail.com>
;
;===============================================================================

Func _GuiCtrlCreateHyperlink($s_Text, $i_Left, $i_Top, $i_Width = -1, $i_Height = -1, $i_Color = 0x0000ff, $s_ToolTip = '', $i_Style = -1, $i_ExStyle = -1)
    Local $i_CtrlID
    $i_CtrlID = GUICtrlCreateLabel($s_Text, $i_Left, $i_Top, $i_Width, $i_Height, $i_Style, $i_ExStyle)
    If $i_CtrlID <> 0 Then
        GUICtrlSetFont (-1, $iSize, $iWeight, $iAttribute, $iFontName)
        GUICtrlSetImage (-1, "shell32.dll",22)
        GuiCtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetColor(-1, $i_Color)
        GUICtrlSetCursor(-1, 0)
        If $s_ToolTip <> '' Then
            GUICtrlSetTip(-1, $s_ToolTip)
        EndIf
    EndIf
    Return $i_CtrlID
EndFunc;==>_GuiCtrlCreateHyperlink

Func _GUICtrlCreateGradient($nStartColor, $nEndColor, $nX, $nY, $nWidth = 255, $nHeight = 20,$s_type="V")
   Local $colorR = _ColorGetRed($nStartColor)
   Local $colorG = _ColorGetGreen($nStartColor)
   Local $colorB = _ColorGetBlue($nStartColor)

   Local $nStepR,$nStepG,$nStepB

   GuiCtrlCreateGraphic($nX, $nY, $nWidth, $nHeight)
    If(StringUpper($s_type) == "V") Then
        $nStepR = (_ColorGetRed($nEndColor) - $colorR) / $nWidth
        $nStepG = (_ColorGetGreen($nEndColor) - $colorG) / $nWidth
        $nStepB = (_ColorGetBlue($nEndColor) - $colorB) / $nWidth
        For $i = 0 To $nWidth
            $sColor = "0x" & StringFormat("%02X%02X%02X", $colorR+$nStepR*$i, $colorG+$nStepG*$i, $colorB+$nStepB*$i)
                GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff)
            GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $i, 0)
            GUICtrlSetGraphic(-1, $GUI_GR_LINE, $i, $nHeight)
        Next
    ElseIf(StringUpper($s_type) == "H") Then
        $nStepR = (_ColorGetRed($nEndColor) - $colorR) / $nHeight
        $nStepG = (_ColorGetGreen($nEndColor) - $colorG) / $nHeight
        $nStepB = (_ColorGetBlue($nEndColor) - $colorB) / $nHeight
        For $i = 0 To $nHeight
            $sColor = "0x" & StringFormat("%02X%02X%02X", $colorR+$nStepR*$i, $colorG+$nStepG*$i, $colorB+$nStepB*$i)
                GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff)
            GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
            GUICtrlSetGraphic(-1, $GUI_GR_LINE, $nWidth, $i)
        Next

    EndIf
    GUICtrlSetState(-1, $GUI_DISABLE)
EndFunc
Edited by GioVit

Share this post


Link to post
Share on other sites



i get an error on line 200...

line 200 is a Func GUIMove declaration may you be more explicit with th error

what OS do you have installed?

btw it only is tested in windows XP.

Share this post


Link to post
Share on other sites

works nice...thanx


I believe we should all pay our tax with a smile. I tried - but they wanted cash!

Share this post


Link to post
Share on other sites

works nice...thanx

Thanks you kcIteam

btw it work with taskbar in any side of the desktop

any improvement feedback will be appreciated.

Share this post


Link to post
Share on other sites

Thanks you kcIteam

btw it work with taskbar in any side of the desktop

any improvement feedback will be appreciated.

Anybody know the value of $GUI_BKCOLOR_TRANSPARENT? My compiler balks at this.

Talking Clockhttp://www.autoitscript.com/forum/index.php?showtopic=20751Talking Headlineshttp://www.autoitscript.com/forum/index.php?showtopic=20655Sometimes, I sits and thinkssometimes, I just sits

Share this post


Link to post
Share on other sites

Anybody know the value of $GUI_BKCOLOR_TRANSPARENT? My compiler balks at this.

It's

Global Const $GUI_BKCOLOR_TRANSPARENT = -2


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I don't want to take a lot of someone's time, (I know nothing about GUI's), but I get the popup OK, and all controls seem to function OK, but I get just a black window, with a gradient frame (yellow to white) with the exit icon. No text anywhere. Any quick ideas?

Love the popup though.

Edited by leecole

Talking Clockhttp://www.autoitscript.com/forum/index.php?showtopic=20751Talking Headlineshttp://www.autoitscript.com/forum/index.php?showtopic=20655Sometimes, I sits and thinkssometimes, I just sits

Share this post


Link to post
Share on other sites

I don't want to take a lot of someone's time, (I know nothing about GUI's), but I get the popup OK, and all controls seem to function OK, but I get just a black window, with a gradient frame (yellow to white) with the exit icon. No text anywhere. Any quick ideas?

Love the popup though.

Try replacing this line:

$i_CtrlID = GUICtrlCreateLabel($s_Text, $i_Left, $i_Top, $i_Width, $i_Height, $i_Style, $i_ExStyle)

with this one:

$i_CtrlID = GUICtrlCreateLabel($s_Text, $i_Left, $i_Top, $i_Width, $i_Height)

Share this post


Link to post
Share on other sites

Try replacing this line:

$i_CtrlID = GUICtrlCreateLabel($s_Text, $i_Left, $i_Top, $i_Width, $i_Height, $i_Style, $i_ExStyle)

with this one:

$i_CtrlID = GUICtrlCreateLabel($s_Text, $i_Left, $i_Top, $i_Width, $i_Height)
Same result, I suspect that my original problem, $GUI_BKCOLOR_TRANSPARENT unkown, is a clue that I don't have the latest version of something. Before posting I went to the "C:\Program Files\AutoIt3\SciTe\Defs\UpdateDefs.exe" and ran it. I compile with beta 3.1.1.111.

Talking Clockhttp://www.autoitscript.com/forum/index.php?showtopic=20751Talking Headlineshttp://www.autoitscript.com/forum/index.php?showtopic=20655Sometimes, I sits and thinkssometimes, I just sits

Share this post


Link to post
Share on other sites

btw GioVit, the exit image i couldn't download!

it works fine without that too, but was just curious wat is that image :o


I believe we should all pay our tax with a smile. I tried - but they wanted cash!

Share this post


Link to post
Share on other sites

btw GioVit, the exit image i couldn't download!

it works fine without that too, but was just curious wat is that image :o

it's a red square like is shown at the bottom of the first post, I think you can save it by right clicking it and in the context menu select "save image as ... " or whatever... I don't know exactly how should say because my Operating System and my browser are in Spanish. Anyway you shold save it with the name "exit.jpg" at the same dirctory where you saved the source code.

The Popup window will show the image and you can click on it to close the Popup window before the timeout take place, this is in case you change the timeout parameter with a lager value, say 10000 milliseconds.

Share this post


Link to post
Share on other sites

ohh...that was the image?

so silly of me... :blushes: i thought the image was not available, so my silly browser had placed a red cross instead....

Neway, your notifier works fine...thank you


I believe we should all pay our tax with a smile. I tried - but they wanted cash!

Share this post


Link to post
Share on other sites

Mega quoted your code inside some other topic about Popups/Toasts and i really like it.

I changed it a bit, to make it suit my needs but i'm having trouble doing the following:

If a toast is shown, and a new one is there (for example 1 shown, 1 "queued"), i'd like to see that it stacks its toasts, just like Messenger does.

Is this possible, and if so? How? :whistle:

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

YES the second great script to day!

Thanks :whistle:

1 small problem: when you set the height of the popup less then 150 not the complete window shows.

Edited by nend

Share this post


Link to post
Share on other sites

@Sypher

If a toast is shown, and a new one is there (for example 1 shown, 1 "queued"), i'd like to see that it stacks its toasts, just like Messenger does.

Is this possible, and if so? How?

I Think it is possible, but I have to see the code again and will try to modify it this weekend

@nend

1 small problem: when you set the height of the popup less then 150 not the complete window shows.

I will check it this weekend.

many thanks.

Share this post


Link to post
Share on other sites

@Sypher

I Think it is possible, but I have to see the code again and will try to modify it this weekend

I tried it, by counting the popups, and checking the height of the last one, to put a new one on top.

The only problem i got was that the new popup would show underneath the other one, so you only see a few pixels (the height of the Systray)

Looking forward to your way :whistle:

Share this post


Link to post
Share on other sites

I tried it, by counting the popups, and checking the height of the last one, to put a new one on top.

The only problem i got was that the new popup would show underneath the other one, so you only see a few pixels (the height of the Systray)

Looking forward to your way :whistle:

Sypher, could this be done by setting the Z order of the message windows? I am not entirely sure how to do it myself, yet, but this program looks very cool. I am interested in using this in place of baloon messages. Its more noticeable.

Share this post


Link to post
Share on other sites

Sypher, could this be done by setting the Z order of the message windows? I am not entirely sure how to do it myself, yet, but this program looks very cool. I am interested in using this in place of baloon messages. Its more noticeable.

Sorry, I was thinking about multiple Notification Windows, and changes requires a lot of code:

1) Need an array of windows handles

2) Then need a function that check the TimeOut of each Notification Windows (with AdLibEnable()) and Close the window if time Expired

3) When Closing a Notification Window By scrolling It the program must scroll all the other Notification Windows that are shown above or have not expired time yet.

4) When Open a New Notification Window you must use WinSetOnTop() on the Notification Window that you prefer to see.

so is a lot of work and the part 3) is the most dificult to implement.

I will try to Modify it, but it will take some time.

Share this post


Link to post
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
Sign in to follow this  
Followers 0