Jump to content

Get Shell_NotifyIcon to show tray balloon tip


wraithdu
 Share

Recommended Posts

EDIT - fixed

I'm stumped. This *should* work. I've followed the same method that AutoIt and AHK both use internally for the TrayTip() function. I can add a new icon, and destroy it, but the balloon tip will not show even though the function returns success. I've tested on Vista and XP and neither work. Any ideas would be appreciated!

#NoTrayIcon
#include <StructureConstants.au3>
#include <WinApi.au3>

Global Const $tagNOTIFYICONDATA = "dword cbSize;" & _
                                "hwnd hWnd;" & _
                                "uint uID;" & _
                                "uint uFlags;" & _
                                "uint uCallbackMessage;" & _
                                "ptr hIcon;" & _
                                "wchar szTip[128];" & _
                                "dword dwState;" & _
                                "dword dwStateMask;" & _
                                "wchar szInfo[256];" & _
                                "uint uTimeout;" & _
                                "wchar szInfoTitle[64];" & _
                                "dword dwInfoFlags;" & _
                                $tagGUID & ";" & _
                                "ptr hBalloonIcon"

Global Enum $NIM_ADD = 0, $NIM_MODIFY, $NIM_DELETE, $NIM_SETFOCUS, $NIM_SETVERSION
Global Const $NIF_ICON = 0x2, $NIF_INFO = 0x10, $NIF_TIP = 0x4, $NIF_MESSAGE = 0x1
Global Enum $NIIF_NONE = 0, $NIIF_INFO, $NIIF_WARNING, $NIIF_ERROR
Global Const $IMAGE_ICON = 1, $LR_DEFAULTSIZE = 0x40

$hIcon = DllCall("user32.dll", "ptr", "LoadImage", "ptr", _WinAPI_GetModuleHandle(0), "uint", 161, "uint", $IMAGE_ICON, "int", 16, "int", 16, "uint", 0)
$hIcon = $hIcon[0]
$gui = GUICreate("")

$NOTIFY = DllStructCreate($tagNOTIFYICONDATA)
_ZeroMemory($NOTIFY)
DllStructSetData($NOTIFY, "cbSize", DllStructGetSize($NOTIFY))
DllStructSetData($NOTIFY, "hWnd", $gui)
DllStructSetData($NOTIFY, "uID", 999)
DllStructSetData($NOTIFY, "hIcon", $hIcon)
DllStructSetData($NOTIFY, "uFlags", BitOR($NIF_ICON, $NIF_TIP))
DllStructSetData($NOTIFY, "szTip", "hover tooltip" & Chr(0))
$ret = DllCall("shell32.dll", "int", "Shell_NotifyIconW", "dword", $NIM_ADD, "ptr", DllStructGetPtr($NOTIFY))
ConsoleWrite($ret[0] & @CRLF)

Sleep(2000)

DllStructSetData($NOTIFY, "uFlags", $NIF_INFO)
;~ $szTitle = DllStructCreate("wchar[64]")
;~ DllStructSetData($szTitle, 1, "TITLE" & Chr(0))
;~ DllCall("msvcrt.dll", "ptr:cdecl", "strncpy", "ptr", DllStructGetPtr($NOTIFY, "szInfoTitle"), "ptr", DllStructGetPtr($szTitle), "uint", 64)
DllStructSetData($NOTIFY, "szInfoTitle", "TITLE" & Chr(0))
;~ $szTip = DllStructCreate("wchar[256]")
;~ DllStructSetData($szTip, 1, "this is the tip" & Chr(0))
;~ DllCall("msvcrt.dll", "ptr:cdecl", "strncpy", "ptr", DllStructGetPtr($NOTIFY, "szInfo"), "ptr", DllStructGetPtr($szTip), "uint", 256)
DllStructSetData($NOTIFY, "szInfo", "balloon tip" & Chr(0))
DllStructSetData($NOTIFY, "uTimeout", 15000)
DllStructSetData($NOTIFY, "dwInfoFlags", $NIIF_INFO)

$ret = DllCall("shell32.dll", "int", "Shell_NotifyIconW", "dword", $NIM_MODIFY, "ptr", DllStructGetPtr($NOTIFY))
ConsoleWrite($ret[0] & @CRLF)

Sleep(5000)

$ret = DllCall("shell32.dll", "int", "Shell_NotifyIconW", "dword", $NIM_DELETE, "ptr", DllStructGetPtr($NOTIFY))
ConsoleWrite($ret[0] & @CRLF)
$NOTIFY = 0

Func _ZeroMemory(ByRef $struct)
    Local $temp = DllStructCreate("byte[" & DllStructGetSize($struct) & "]", DllStructGetPtr($struct))
    For $i = 1 To DllStructGetSize($temp)
        DllStructSetData($temp, 1, 0, $i)
    Next
EndFunc
Edited by wraithdu
Link to comment
Share on other sites

ModernMenu includes this functionality.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

You've got to be kidding me, 1 f'ing struct element was wrong! MSDN said NOTHING about szTip being 128 TCHARS. Bastards....

Thanks for the nudge :)

MSDN

szTip

A null-terminated string that specifies the text for a standard ToolTip. It can have a maximum of 64 characters, including the terminating null character.

For Windows 2000 (Shell32.dll version 5.0 [ http://msdn.microsoft.com/en-us/library/bb776779(VS.85).aspx ] ) and later, szTip can have a maximum of 128 characters, including the terminating null character.

:)
Link to comment
Share on other sites

There is an #if ... MSDN

...
#if (NTDDI_VERSION < NTDDI_WIN2K)
    TCHAR szTip[64];
#endif
#if (NTDDI_VERSION >= NTDDI_WIN2K)
    TCHAR szTip[128];
    DWORD dwState;
...

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Shit. I have a locally installed MSDN library (from VS2008), and I don't have any of that -

typedef struct _NOTIFYICONDATA {
    DWORD cbSize;
    HWND hWnd;
    UINT uID;
    UINT uFlags;
    UINT uCallbackMessage;
    HICON hIcon;
    TCHAR szTip[64];
    DWORD dwState;
    DWORD dwStateMask;
    TCHAR szInfo[256];
    union {
        UINT uTimeout;
        UINT uVersion;
    };
    TCHAR szInfoTitle[64];
    DWORD dwInfoFlags;
    GUID guidItem;
    HICON hBalloonIcon;
} NOTIFYICONDATA, *PNOTIFYICONDATA;
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...