WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Systray Icon Questions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Notification Balloon

 Keywords: ShellTrayModifyTip Shell_NotifyIconA Shell_NotifyIcon IntControl 1007 Notification Tray Systray Notify Message Dialog Notice Balloon Non-Active _NOTIFYICONDATA

Question:

Is there a way with WinBatch to open a notification message that doesn't make the notification window "active"? I want to notify my end user but don’t want to take the cursor out of the field they are typing in even for a second if that is possible.

Answer:

Any of the standard message boxes in WIL would automatically change window activation. So I got to thinking, maybe this could be handled via an icon sitting in the systemtray. Here is what I came up with:
; NOTIFICATION IN SYSTRAY
; This is a system tray icon example.
;
; NOTE:  This example will not work in WinBatch Studio in debug mode, as IntControl 1007 and WinBatch Studio debug mode are not compatible.

#DefineFunction ShellTrayModifyTip(title, text)
   ;typedef struct _NOTIFYICONDATA {
   ;[Size]                         [Offset]
   ;  4  DWORD cbSize;              0
   ;  4  HWND hWnd;                 4
   ;  4  UINT uID;                  8
   ;  4  UINT uFlags;               12
   ;  4  UINT uCallbackMessage;     16
   ;  4  HICON hIcon;               20
   ; 128  TCHAR szTip[128];         24
   ;  4  DWORD dwState;             152
   ;  4  DWORD dwStateMask;         156
   ;256  TCHAR szInfo[256];         160
   ;    union {
   ;  4      UINT uTimeout;         416
   ;  4      UINT uVersion;
   ;    };
   ; 64   TCHAR szInfoTitle[64];   420
   ;  4  DWORD dwInfoFlags;        484
   ;  16  GUID guidItem;           488
   ;  4  HICON hBalloonIcon;       504
   ;} NOTIFYICONDATA, *PNOTIFYICONDATA

   IDI_TRAYICON = 100 ;!!!DO NOT CHANGE!!!. Special value defined by Winbatch.
   cbsize = 504
   bbnid = BinaryAlloc(cbsize)
   BinaryPoke4(bbnid, 0, cbsize) ;cbSize
   BinaryPoke4(bbnid, 4, DllHwnd("")) ;hWnd
   BinaryPoke4(bbnid, 8, IDI_TRAYICON) ;uID 100 unique identifier defined by WinBatch
   BinaryPoke4(bbnid, 12, 16) ;uFlags NIF_INFO - Use a balloon ToolTip instead of a standard ToolTip. The szInfo, uTimeout,
   ;szInfoTitle, and dwInfoFlags members are valid.
   ;BinaryPoke4(bbnid, 16, 0) ;uCallbackMessage
   ;BinaryPoke4(bbnid, 20, 0) ;hIcon
   ;BinaryPokeStr(bbnid, 24, "My Tool Tip") ;szTip[64]
   ;BinaryPoke4(bbnid, 152, 0) ;dwState;
   ;BinaryPoke4(bbnid, 156, 0) ;dwStateMask
   BinaryPokeStr(bbnid, 160, text) ;szInfo[256]  text for a balloon ToolTip. It can have a maximum of 255 characters
   ;Union
     BinaryPoke4(bbnid, 416, 10000 ); uTimeout The timeout value, in milliseconds, for a balloon ToolTip.
   ; or
   ; BinaryPoke4(bbnid, 416, 0 ); uVersion
   BinaryPokeStr(bbnid, 420, title) ;szInfoTitle[64] string containing a title for a balloon ToolTip
   BinaryPoke4(bbnid, 484, 1 );dwInfoFlags;
   ;BinaryPoke4(bbnid, 488, 0 );guidItem reserved
   ;BinaryPoke4(bbnid, 504, 0 );hBalloonIcon

   BinaryEodSet( bbnid, cbsize )
   ;Call Shell_NotifyIcon(NIM_MODIFY, nid)
   NIM_MODIFY = 1
   user32=StrCat(DirWindows(1),"shell32.dll")
   ret = DllCall(user32,long:"Shell_NotifyIconA", long:NIM_MODIFY, lpbinary:bbnid)
   If ret == 0
        Message("Shell_NotifyIcon Error",DllLastError())
   EndIf
   Return(ret)
#EndFunction

title = "My Balloon Tip Title"
text =  "My Balloon Tip Text"

; Add script to systemtray
IntControl(1007, 1, 1, "", 0)

; Display Notification  for 9 seconds
ret = ShellTrayModifyTip(title, text)
TimeDelay(9)

; Remove script from systemtray
IntControl(1007, 2,0, "", "")
Exit


Reference:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa511497.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762159(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762242(v=vs.85).aspx


Article ID:   W18296
Filename:   Notification Balloon.txt
File Created: 2013:02:27:09:37:20
Last Updated: 2013:02:27:09:37:20