Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Notification Window (Like MSN Messenger Popups)


  • Please log in to reply
9 replies to this topic
beardboy
  • Members
  • 443 posts
  • Last active: May 27 2017 08:41 AM
  • Joined: 02 Mar 2004
I'm not sure if someone has already posted something like this, but if not here you go. Include this file in any script and use one line to popup notifications like MSN Messenger Popups. The popup plays a sound if wanted, rolls up, waits X number of milliseconds, then rolls back down and disapears.

Posted Image

Example of adding it to your AHK File:
#NoTrayIcon
beardboyTray("Meeting","`n`nDon't forget you have a meeting!!!`nTime: 11:00am`nPlace: Conference Room",1,2000) ; Play sound and custom 2 second delay
WinWaitClose, Meeting
ExitApp

#Include beardboyTray.ahk

beardboyTray.ahk
; Program: Beardboy Tray
; Version: .00
; Last Modified: 2005.09.06
; Last Changes: First Version

/*
Example of how to popup a message
beardboyTray(title,text,sound,timeout)
beardboyTray("beardboy's TrayTip","This is a Test") ; No sound and Default 4 second timeout
beardboyTray("beardboy's TrayTip","This is a Test",0,10000) ; No sound and Custom 10 second timeout.
beardboyTray("beardboy's TrayTip","This is a Test",1,0) ; Sound and User must close TrayTip
*/

beardboyTray(title,text, sound = 0, timeout = 4000)
{
  global
  bt_title = %title%
  x := % A_ScreenWidth - 185
  y := % A_ScreenHeight - 30
  gui, 99:+ToolWindow +border
  gui, 99:color, FFFFFF
  gui, 99:Margin, 0, 0
  gui, 99:Add, Text, center w175 h90 cBlue, %text%
  Gui, 99:Show, x%x% y%y%, %title%

  if sound <> 0
    SoundPlay, %SystemRoot%\Media\notify.wav
  SetWinDelay, 5
  WinGetPos,, guiy,,, %title%
  Loop, 55
  {
    guiy -= 2
    WinMove, %title%,,, %guiy%
  }
  if timeout <> 0
    SetTimer, CloseTray, %timeout%
}

99GuiClose:
Gui, 99:Destroy
return

CloseTray:
SetTimer, CloseTray, Off
SetWinDelay, 5
WinGetPos,, guiy,,, %bt_title%
Loop, 55
{
  guiy += 2
  WinMove, %bt_title%,,, %guiy%
}
Gui, 99:Destroy
return

thanks,
beardboy

Mon
  • Members
  • 12 posts
  • Last active: Sep 07 2005 11:25 AM
  • Joined: 21 Aug 2005
Wow...this is nice.
Smooth in window move and looks great!
I also love the use of #Include *.ahk, smart(yes, another lesson from great script :D)

...I just configured my script to use #Include.
It made everthing a lot easier to control!! :D

Thank you for the hint :),
Mon

Nice modification Andre :D

Andre
  • Members
  • 52 posts
  • Last active: May 22 2006 10:08 AM
  • Joined: 22 Jul 2005
hi,

some mods.
Like alwaysontop & Transparent

; Program: Beardboy Tray 
; Version: .00 
; Last Modified: 2005.09.06 
; Last Changes: First Version 

/* 
Example of how to popup a message 
beardboyTray(title,text,sound,timeout) 
beardboyTray("beardboy's TrayTip","This is a Test") ; No sound and Default 4 second timeout 
beardboyTray("beardboy's TrayTip","This is a Test",0,10000) ; No sound and Custom 10 second timeout. 
beardboyTray("beardboy's TrayTip","This is a Test",1,0) ; Sound and User must close TrayTip 
*/ 

beardboyTray(title,text, sound = 0, timeout = 4000) 
{ 
  global 
  bt_title = %title% 
  x := % A_ScreenWidth - 185 
  y := % A_ScreenHeight - 30 
  gui, 99:+ToolWindow +border +AlwaysOnTop
  gui, 99:
  gui, 99:color, FFFFFF 
  gui, 99:Margin, 0, 0 
  gui, 99:Add, Text, center w175 h90 cBlue, %text% 
  Gui, 99:Show, x%x% y%y%, %title% 
  
  WinSet, Transparent, 150, %title%
  
  if sound <> 0 
    SoundPlay, %SystemRoot%\Media\notify.wav 
  SetWinDelay, 5 
  WinGetPos,, guiy,,, %title% 
  Loop, 55 
  { 
    guiy -= 2 
    WinMove, %title%,,, %guiy% 
  } 
  if timeout <> 0 
    SetTimer, CloseTray, %timeout% 
} 

99GuiClose: 
Gui, 99:Destroy 
return 

CloseTray: 
SetTimer, CloseTray, Off 
SetWinDelay, 5 
WinGetPos,, guiy,,, %bt_title% 
Loop, 55 
{ 
  guiy += 2 
  WinMove, %bt_title%,,, %guiy% 
} 
Gui, 99:Destroy 
return

regards,
Andre

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
Don't know if it's the case when included in another script, but when run on its own, it needs a "Return" added at the end of the section which is above "99GuiClose:".

Thanks for sharing though - useful script.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005

Don't know if it's the case when included in another script, but when run on its own, it needs a "Return" added at the end of the section which is above "99GuiClose:".

It is a function, so AFAIK it should not need a return. But I didn't test. But in general you should include this file into your script and call the function it is not ment to run by itself.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Nice :) . Thanks for sharing beardboy :D

I wanted to use it as a stand-alone app that I could launch using Run/RunWait so I made a modified version for that purpose with a few other modifications. Here's the modified version in case you find any of it useful... Thanks again :D .
; Program: Beardboy Tray 
; Version: corr0.02 
; Last Modified: 2005.09.12 
; Last Changes: Modified Version - Corrupt

; - Modified: from include file to stand-alone script (use Runwait to launch)
; - Modified: AlwaysOnTop method to prevent showing message window over taskbar
; - Modified: WinMove method to API call "MoveWindow" for speed/smoothing
; - Added: click anywhere on the message to close the message window
; - Modified: Window always moves back down before closing

; RunWait, beardboytray.ahk "title" "text" "sound" "timeout"

; All params are optional (default values will be used if not specified)
; Set timeout to 0 to manually dismiss message (click on message window to close)

#SingleInstance, Ignore
#NoTrayIcon
  title = %1%
  if !title
    title = Beardboy Tray
  text = %2%
  If !text
    text = `nBeardboy Tray`n`nModified by: Corrupt`nVersion: corr.02
  sound = %3%
  If !sound  
    sound := 0
  timeout = %4%
  If timeout= 
    timeout := 4000

  x := % A_ScreenWidth - 191 
  y := % A_ScreenHeight - 30
  gui, Add, Text, center w175 h90 cRed, %text%
  gui, +ToolWindow +border
  gui, color, FFFFFF 
  gui, Margin, 0, 0 
  Gui, Show, x%x% y%y% , %title% 
  WinSet, Transparent, 200, %title%
  WinWait, %title%
  WinHWND := WinExist(title)
  OnMessage(0x201, "WM_LBUTTONDOWN")
  if sound <> 0 
    SoundPlay, %SystemRoot%\Media\notify.wav 
  SetWinDelay, 5
  WinGetPos,, guiy,,, %title%
  Loop, 60 
  { 
    guiy -= 2
    DllCall("MoveWindow", "UINT", WinHWND, "INT", x, "INT", guiy, "INT", 190, "INT", "120", "INT", "1")
    WinActivate, %title% 
  }
  WinSet, AlwaysOnTop, On
  if timeout <> 0 
    SetTimer, CloseTray, %timeout%
Return

WM_LBUTTONDOWN(wParam, lParam)
{
if !closing
  SetTimer, CloseTray, 200
}

GuiClose:
CloseTray:
closing := True 
WinSet, AlwaysOnTop, Off, %title%
SetWinDelay, 5 
WinGetPos,, guiy,,, %title% 
Loop, 60 
{ 
  guiy += 2
  DllCall("MoveWindow", "UINT", WinHWND, "INT", x, "INT", guiy, "INT", 190, "INT", "120", "INT", "1")
  WinActivate, %title% 
} 
SetTimer, CloseTray, Off 
ExitApp
Return

Sample calling script:
#NoTrayIcon
title = Meeting
Message = `nDon't forget you have a meeting!!!`nTime: 11:00am`nPlace: Conference Room
sound = 
timeout = 2000

RunWait, Autohotkey beardboytray.ahk "%title%" "%Message%" 1 0

RunWait, Autohotkey beardboytray.ahk "This is a Modified Version" "`nBeardboy Tray`n`nModified by Corrupt" 1 
ExitApp


toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Hi Corrupt,
nice idea,

What are the "%" doing in these lines
x := % A_ScreenWidth - 191 
  y := % A_ScreenHeight - 30
It should work without them, don't it?
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
To get the command line params could look like this
var1 = Beardboy Tray 

 var2 = `nBeardboy Tray`n`nModified by: Corrupt`nVersion: corr.02 

 var3 := 0 

 var4 := 4000

Loop, %0%

     var%A_index% = %A_Index%

But this is just personal likings. The drawback is that you loose the speaking names.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
I would suggest to get the UniqueID for the GUI and use it for the gui manipulation, so that it is more robust (compared to using %title%)
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

Hi Corrupt,
nice idea,

What are the "%" doing in these lines

x := % A_ScreenWidth - 191 
  y := % A_ScreenHeight - 30
It should work without them, don't it?


Hi toralf :) ,

Yes, it should work ok without them. Although I made a few modifications much of the original code remained.

I would suggest to get the UniqueID for the GUI and use it for the gui manipulation, so that it is more robust (compared to using %title%)

I had actually made that change and then reverted back (along with a few other changes) to troubleshoot a pesky bug that I had introduced. After troubleshooting I didn't end up putting it back in... :lol: . Maybe beardboy will made the change in the next version (if there is going to be a next version)...