Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

How to make Toast - BugFix version 16 Jul 14


  • Please log in to reply
249 replies to this topic

#1 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,477 posts

Posted 17 January 2010 - 04:20 PM

*
POPULAR

[BUGFIX VERSION] - 16 Jul 14

Fixed: Bug when adding a PNG in x64. Thanks to guinness and UEZ for the fix. :thumbsup:

New UDF and example in the zip below. :)

Previous versions: Attached File  Changelog.txt   1.94KB   35 downloads

 
A forum query about the small pop-ups that some apps produce from the systray led me to create my version of how this can be done. By the way, I call these small GUIs "Toasts" for obvious reasons! :D

A zip containing the UDF, an example script and my StringSize UDF (which is also required): Attached File  Toast.zip   12.33KB   137 downloads

As always, kind comments and constructive criticisms welcome - particularly the former! :)

M23

Edited by Melba23, 16 July 2014 - 07:21 AM.

  • footswitch, jmon, careca and 3 others like this
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items







#2 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,059 posts

Posted 17 January 2010 - 04:48 PM

It will work on xp :D Other than that, I think it would be very cool to have a MsgBox copy :huggles:

[autoi]Func ToastBox($nIcon, $sTitle, $sText, $nTimeout = -1, $hWnd)[/autoit]

That would be very cool!

#3 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,477 posts

Posted 17 January 2010 - 05:03 PM

Mat,

You want it, you write it! :D

Seriously, if I need user interaction I tend to use a MsgBox (or one of my own ExtMsgBox) and centre it on the app that needs the information. I use Toasts more for passing information to the user - "Indexing, please be patient", "The playing track is...." sort of stuff.

M23
  • debugcs likes this
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#4 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,059 posts

Posted 17 January 2010 - 05:30 PM

kk, Well what about icon support? Proof of concept (you will probably want to rewrite it though :D )

AutoIt         
; #FUNCTION# ========================================================================================================= ; Name...........: _Toast_Show ; Description ...: Shows a slice message from the systray ; Syntax.........: _Toast_Show($nIcon, $sTitle, $sMessage, [$iDelay [, $fWait]]) ; Parameters ....: $nIcon    - The icon to show. Default (0) is none. Can be on of the following: ;                            |1 - App window ;                            |2 - Warning triangle ;                            |3 - Question mark ;                            |4 - Stop sign ;                            |5 - Info sign ;                            |6 - Security sign (Vista+) ;                  $sTitle   - Text to display on Title bar ;                  $sMessage - Text to display in Toast body ;                  $iDelay   - The delay in seconds before the Toast retracts or script continues (Default = 0) ;                              If negative, an [X] is added to the title bar. Clicking [X] retracts/continues immediately ;                  $fWait    - True  - Script waits for delay time before continuing and Toast remains visible ;                              False - Script continues and Toast retracts automatically after delay time ; Requirement(s).: v3.3.1.5 or higher - AdlibRegister/Unregister used in _Toast_Show ; Return values .: Success: Returns 2-element array: [Toast width, Toast height] ;                  Failure: Returns -1 and sets @error as follows: ;                           1 = Toast GUI creation failed ;                           2 = Taskbar not found ; Author ........: Melba23, based on some original code by GioVit for the Toast, Prog@ndy and Zedna for the [X] ; Notes .........; Any visible Toast is retracted by a subsequent _Toast_Hide or _Toast_Show, or clicking a visible [X] ; Example........; Yes ;===================================================================================================================== _Toast_Show(6, "test", "this is a test" & @CRLF & @CRLF & "And yet another test!") Sleep(10000) Func _Toast_Show($nIcon, $sTitle, $sMessage, $iDelay = 0, $fWait = True)     ; Store current GUI mode and set Message mode     Local $nOldOpt = Opt('GUIOnEventMode', 0)     ; Retract any Toast already in place     If $hToast_Handle <> 0 Then _Toast_Hide()     ; Reset non-reacting Close [X] ControlID     $hToast_Close_X = 9999     ; Set default auto-sizing Toast widths     Local $iToast_Width_max = 500     Local $iToast_Width_min = 150     ; Get message label size     Local $aLabel_Pos = _StringSize($sMessage, $iToast_Font_Size, Default, Default, $sToast_Font_Name, $iToast_Width_max - 20)     ; Reset text to match rectangle     $sMessage = $aLabel_Pos[0]     ;Set line height for this font     Local $iLine_Height = $aLabel_Pos[1]     ; Set label size     Local $iLabelwidth  = $aLabel_Pos[2]     Local $iLabelheight = $aLabel_Pos[3]     ; Set Toast size     Local $iToast_Width = $iLabelwidth + 20     If $iToast_Width < $iToast_Width_min Then         ; Increase if below min size         $iToast_Width = $iToast_Width_min         $iLabelwidth  = $iToast_Width_min - 20     EndIf     ; Set title bar height - with minimum for [X]     Local $iTitle_Height = 0     If $sTitle = "" Then         If $iDelay < 0 Then $iTitle_Height = 5     Else         $iTitle_Height = $iLine_Height + 2         If $iDelay < 0 Then             If $iTitle_Height < 17 Then $iTitle_Height = 17         EndIf     EndIf     ; Set Toast height as label height + title bar + bottom margin     Local $iToast_Height = $iLabelheight + $iTitle_Height + 20     If $nIcon <> 0 Then $iToast_Width += 34     ; Get Toast starting position and direction     Local $aToast_Data = _Toast_Locate($iToast_Width, $iToast_Height)     ; Create Toast slice with $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW style and $WS_EX_TOPMOST extended style     $hToast_Handle = GUICreate("", $iToast_Width, $iToast_Height, $aToast_Data[0], $aToast_Data[1], 0x80880000, BitOr(0x00000080, 0x00000008))     If @error Then         $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)         Return SetError(1, 0, -1)     EndIf         GUISetFont($iToast_Font_Size, Default, Default, $sToast_Font_Name)         GUISetBkColor($iToast_Message_BkCol)     ; Set centring parameter     Local $iLabel_Style = 0 ; $SS_LEFT     If BitAND($iToast_Style, 1) = 1 Then         $iLabel_Style = 1 ; $SS_CENTER     ElseIf BitAND($iToast_Style, 2) = 2 Then         $iLabel_Style = 2 ; $SS_RIGHT     EndIf     ; Create title bar if required     If $sTitle <> "" Then         ; Create disabled background strip         GUICtrlCreateLabel("", 0, 0, $iToast_Width, $iTitle_Height)             GUICtrlSetBkColor(-1, $iToast_Header_BkCol)             GUICtrlSetState(-1, 128) ; $GUI_DISABLE         ; Set title bar width to offset text         Local $iTitle_Width = $iToast_Width - 10         ; Create closure [X] if needed         If $iDelay < 0 Then             ; Create [X]             Local $iX_YCoord = Int(($iTitle_Height - 17) / 2)             $hToast_Close_X = GUICtrlCreateLabel("T", $iToast_Width - 18, $iX_YCoord, 17, 17)                 GUICtrlSetFont(-1, 14, Default, Default, "Wingdings 2")                 GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT                 GUICtrlSetColor(-1, $iToast_Header_Col)             ; Reduce title bar width to allow [X] to activate             $iTitle_Width -= 18         EndIf         ; Create Title label with bold text, centred vertically in case bar is higher than line         GUICtrlCreateLabel($sTitle, 10, 0, $iTitle_Width, $iTitle_Height, 0x0200) ; $SS_CENTERIMAGE             GUICtrlSetBkColor(-1,$iToast_Header_BkCol)             GUICtrlSetColor(-1, $iToast_Header_Col)             If BitAND($iToast_Style, 4) = 4 Then GUICtrlSetFont(-1, $iToast_Font_Size, 600)     Else         If $iDelay < 0 Then             ; Only need [X]             $hToast_Close_X = GUICtrlCreateLabel("T", $iToast_Width - 18, 0, 17, 17)                 GUICtrlSetFont(-1, 14, Default, Default, "Wingdings 2")                 GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT                 GUICtrlSetColor(-1, $iToast_Message_Col)         EndIf     EndIf     ; Create Message label     GUICtrlCreateLabel($sMessage, 10 + (($nIcon <> 0) * 34), 10 + $iTitle_Height, $iLabelwidth, $iLabelheight)         GUICtrlSetStyle(-1, $iLabel_Style)         If $iToast_Message_Col <> Default Then GUICtrlSetColor(-1, $iToast_Message_Col)     If $nIcon >= 6 Then $nIcon = 7     If $nIcon <> 0 Then GUICtrlCreateIcon("user32.dll", -$nIcon, 2, ($iToast_Height - 32) / 2)     ; Slide Toast Slice into view from behind systray and activate     DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 1000, "long", $aToast_Data[2])     ; Activate Toast without stealing focus     GUISetState(@SW_SHOWNOACTIVATE, $hToast_Handle)     ; If script is to pause     If $fWait = True Then         ; Begin timeout counter         Local $iTimeout_Begin = TimerInit()         ; Wait for timeout or closure         While 1             If GUIGetMsg() = $hToast_Close_X Or TimerDiff($iTimeout_Begin) / 1000 >= Abs($iDelay) Then ExitLoop         WEnd     ; If script is to continue and delay has been set     ElseIf Abs($iDelay) > 0 Then         ; Store timer info         $iToast_Timer = Abs($iDelay * 1000)         $iToast_Start = TimerInit()         ; Register Adlib function to run timer         AdlibRegister("_Toast_Timer_Check", 100)         ; Register message handler to check for [X] click         GUIRegisterMsg(0x0021, "_Toast_WM_EVENTS") ; $WM_MOUSEACTIVATE     EndIf     ; Reset original mode     $nOldOpt = Opt('GUIOnEventMode', $nOldOpt)     ; Create array to return Toast dimensions     Local $aToast_Data[3] = [$iToast_Width, $iToast_Height, $iLine_Height]     Return $aToast_Data EndFunc ; => _Toast_Show


Maybe custom icons...

#5 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,321 posts

Posted 17 January 2010 - 06:10 PM

Why is the close label created with the text "T"? I mean, shouldn't it be "[X]"? But If I change it then it is too far to the right and the ']' is missing, but if I move it to the left and reduce the title bar with to suit then the "]" is still missing, so over to you Melba23.

But more to the point, very nice script Melba23, thanks for 'donating' :D.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

#6 UEZ

UEZ

    Never say never

  • MVPs
  • 4,890 posts

Posted 17 January 2010 - 06:24 PM

Looks really nice!

Well done!

UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#7 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,477 posts

Posted 17 January 2010 - 06:29 PM

martin,

Why is the close label created with the text "T"?

The close label is created with character 0x54 from the WingDing 2 font (an X in a box) which I have translated as "T". If you replace the "T" with "[X]" it is hardly surprising that you cannot fit it in as the position is hardcoded for that character in that font in 14pt. :D

Do you not get the WingDings "X in a box" character when you run the script?

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#8 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,477 posts

Posted 17 January 2010 - 09:36 PM

Mat,

You wanted icons, you got icons: :D
; See first post

M23

Edit: Clear up - see first post for latest version

Edited by Melba23, 19 January 2010 - 09:03 AM.

StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#9 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,059 posts

Posted 17 January 2010 - 09:46 PM

:D

Have you tried this?

_Toast_Show(16, "testing!", "This is a test") Sleep (1000)


I get a slight overlap with the taskbar, so you need to offset it by about 2px.

One more thing. You should use OnAutoitExitRegister to fade out the control before the program exits. Then I think I'll have difficulty complaining about anything!

Great work though, Have you seen the GMail notifier? I have a plan to do something similar with the autoit forums. You can be very sure that this is project is going to play a big part in that!

#10 Fire

Fire

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 364 posts

Posted 17 January 2010 - 10:40 PM

WoW.Thank You MASTER M23.Great Job.
It works without any problems on my OS too:

Microsoft Windows XP Professional
5.1.2600 Service Pack 2 (ru) 2600


Thank you again Melba23 for Great Job.
Congrats.

#11 Michel Claveau

Michel Claveau

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 352 posts

Posted 17 January 2010 - 11:09 PM

Hi!

I developed this UDF on Vista ...
WinGetPos("[CLASS:Shell_TrayWnd]")
so if it does not work on other OSs

For info, on Win-7 (32 bits) the CLASS is the same.
Your script run OK on Win-7.

#12 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,321 posts

Posted 18 January 2010 - 08:26 AM

Do you not get the WingDings "X in a box" character when you run the script?

M23

No, I get a 'T' which is why I tried to change it (I thought maybe it was for Toast!). I hadn't noticed that you had used WingDings 2, maybe I don't have that font. I'll have a look when I start my laptop up again.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

#13 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,477 posts

Posted 18 January 2010 - 02:31 PM

Mat,

Have you tried this?

Yes and it is fixed in the post above. :D

I get a slight overlap with the taskbar, so you need to offset it by about 2px

This is something I have tried to fix for a long time and given up on. On my 3 machines (a desktop and 2 laptops all running Vista but with different display resolutions) I could not find one solution to the Toast position coordinates which gives absolute satisfaction on all 3 - there was always one of them where the Toast was slightly high or low. So in the end I have gone with the coordinates that work best on my desktop. If you can solve it, please let me know. :huggles:

One more thing. You should use OnAutoitExitRegister to fade out the control before the program exits.

If you quit when a Toast is showing, the Toast vanishes - that is good enough for me! :'(

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#14 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,059 posts

Posted 18 January 2010 - 03:50 PM

Thanks again Melba, I hope that you will continue to spend a fair amount of time on the examples section of the forum, it seems you are spending way to long in General help and support when you could be doing stuff like this!

#15 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 12,607 posts

Posted 18 January 2010 - 04:42 PM

Great stuff, thanks for sharing.

Works a treat

Win 7 (32)

I also have the T instead of the wingding, it took me about 1 microsecond to get over it.

Cheers.

AutoIt Absolute Beginners Require a serial
 
 
OMG! Women are the cows of people.


#16 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,477 posts

Posted 18 January 2010 - 04:55 PM

JohnOne,

Is that because you do not have the WingDings 2 font in Win 7? If so , could you please look in Character Map (or whatever the Win 7 equivalent is) and see if there is another font with an "X in a box" character that could be used instead.

Thanks in advance. :D

M23

Edit: All is now clear - see post below

Edited by Melba23, 18 January 2010 - 07:04 PM.

StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#17 Michel Claveau

Michel Claveau

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 352 posts

Posted 18 January 2010 - 05:42 PM

Hi, (pêche) Melba!

could you please look in Character Map (or whatever the Win 7 equivalent is) and see if there is another font with an "X in a box" character that could be used instead.


If MS-office is installed, Arial-Unicode-MS is present, with more than 25 000 different chars...

Or... you can see DaFont

#18 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,477 posts

Posted 18 January 2010 - 06:59 PM

Hi all,

A bit of investigation shows that WingDings 2 is NOT a basic installed font - it is installed by any number of MS products, but does not come as standard with any Windows OS.

So I have changed the above posts to use a similar character from WingDings - this font IS installed as standard with all Windows OSs - and adjusted one constant to get the correct display. The character is not quite as nice to look at, but at least everyone will see the same thing. :D Unless they have uninstalled WingDings - and then I refuse all responsibility!

Apologies for the confusion, but I have never seen a machine without both WingDings fonts - some of you must be very resistant to Bill Gates' marketing dept! :huggles:

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#19 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 12,607 posts

Posted 18 January 2010 - 07:04 PM

JohnOne,

Is that because you do not have the WingDings 2 font in Win 7? If so , could you please look in Character Map (or whatever the Win 7 equivalent is) and see if there is another font with an "X in a box" character that could be used instead.

Thanks in advance. :D

M23



In the character map of wingdings, it says "Character code: 0x78"

bog standard installation, with no office .

Not wingdings 2 either.

Edited by JohnOne, 18 January 2010 - 07:06 PM.

AutoIt Absolute Beginners Require a serial
 
 
OMG! Women are the cows of people.


#20 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,321 posts

Posted 18 January 2010 - 08:06 PM

Great stuff, thanks for sharing.

Works a treat

Win 7 (32)

I also have the T instead of the wingding, it took me about 1 microsecond to get over it.

Cheers.


That's several thousand times faster than it took me to fail! How did you get over it?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users