Jump to content

TraySetIcon() with handle?


Recommended Posts

Link to comment
Share on other sites

#include <Constants.au3>
#include <WinAPI.au3>
#cs
TraySetIcon('shell32.dll', -1)
Sleep(1000)
Exit
#ce

Global Const $NIM_MODIFY = 1
Global Const $NIF_MESSAGE = 1   ; The uCallbackMessage member is valid.
Global Const $NIF_ICON = 2      ; The hIcon member is valid.
Global Const $NIF_TIP = 4       ; The szTip member is valid.
Global Const $NIF_STATE = 8     ; The dwState and dwStateMask members are valid.
Global Const $NIF_INFO = 16     ; Use a balloon ToolTip instead of a standard ToolTip.
                                ; The szInfo, uTimeout, szInfoTitle, and dwInfoFlags members 
Global Const $NIF_GUID = 32     ; Reserved
Global Const $NIF_REALTIME = 64 ; Windows Vista (Shell32.dll version 6.0.6) and later.
Global Const $NIF_SHOWTIP = 128  ; Windows Vista (Shell32.dll version 6.0.6) and later. Use the standard ToolTip

Global Const $tagNOTIFYICONDATAW = _
    'dword cbSize;' & _
    'hwnd hWnd;' & _
    'uint uID;' & _
    'uint uFlags;' & _
    'uint uCallbackMessage;' & _
    'hwnd hIcon;' & _
    'wchar szTip[128];' & _
    'dword dwState;' & _
    'dword dwStateMask;' & _
    'wchar szInfo[256];' & _
    'uint uVersion;' & _
    'wchar szInfoTitle[64];' & _
    'dword dwInfoFlags;' ; & $tagGUID
    
Global $hDll = _WinAPI_LoadLibrary('shell32.dll')
Global $hIcon = _LoadIcon($hDll, "152")
Global $tNID = DllStructCreate($tagNOTIFYICONDATAW), $pNID = DllStructGetPtr($tNID)
Global $hWnd = WinGetHandle(AutoItWinGetTitle())

DllStructSetData($tNID, 'cbSize', DllStructGetSize($tNID))
DllStructSetData($tNID, 'hWnd', $hWnd)
DllStructSetData($tNID, 'uID', 1)
DllStructSetData($tNID, 'uFlags', $NIF_ICON)
DllStructSetData($tNID, 'hIcon', $hIcon)

_Shell_NotifyIcon($NIM_MODIFY, $pNID)
Sleep(2000)
_WinAPI_DestroyIcon($hIcon)
_WinAPI_FreeLibrary($hDll)
Exit


Func _LoadIcon($hInstance, $sIconName)
    Local $aRet
    
    $aRet = DllCall('user32.dll', 'hwnd', 'LoadIconA', 'hwnd', $hInstance, 'uint', $sIconName)
    If @error Then Return SetError(1, 0, 0)
    Return $aRet[0]
EndFunc

Func _Shell_NotifyIcon($iMessage, $pdata)
    Local $aRet
    
    $aRet = DllCall('shell32.dll', 'int', 'Shell_NotifyIconW', 'dword', $iMessage, 'ptr', $pdata)
    If @error Then Return SetError(1, 0, 0)
    Return $aRet[0]
EndFunc

Link to comment
Share on other sites

#include <Constants.au3>
#include <WinAPI.au3>
#cs
TraySetIcon('shell32.dll', -1)
Sleep(1000)
Exit
#ce

Global Const $NIM_MODIFY = 1
Global Const $NIF_MESSAGE = 1   ; The uCallbackMessage member is valid.
Global Const $NIF_ICON = 2      ; The hIcon member is valid.
Global Const $NIF_TIP = 4       ; The szTip member is valid.
Global Const $NIF_STATE = 8     ; The dwState and dwStateMask members are valid.
Global Const $NIF_INFO = 16     ; Use a balloon ToolTip instead of a standard ToolTip.
                                ; The szInfo, uTimeout, szInfoTitle, and dwInfoFlags members 
Global Const $NIF_GUID = 32     ; Reserved
Global Const $NIF_REALTIME = 64 ; Windows Vista (Shell32.dll version 6.0.6) and later.
Global Const $NIF_SHOWTIP = 128  ; Windows Vista (Shell32.dll version 6.0.6) and later. Use the standard ToolTip

Global Const $tagNOTIFYICONDATAW = _
    'dword cbSize;' & _
    'hwnd hWnd;' & _
    'uint uID;' & _
    'uint uFlags;' & _
    'uint uCallbackMessage;' & _
    'hwnd hIcon;' & _
    'wchar szTip[128];' & _
    'dword dwState;' & _
    'dword dwStateMask;' & _
    'wchar szInfo[256];' & _
    'uint uVersion;' & _
    'wchar szInfoTitle[64];' & _
    'dword dwInfoFlags;' ; & $tagGUID
    
Global $hDll = _WinAPI_LoadLibrary('shell32.dll')
Global $hIcon = _LoadIcon($hDll, "152")
Global $tNID = DllStructCreate($tagNOTIFYICONDATAW), $pNID = DllStructGetPtr($tNID)
Global $hWnd = WinGetHandle(AutoItWinGetTitle())

DllStructSetData($tNID, 'cbSize', DllStructGetSize($tNID))
DllStructSetData($tNID, 'hWnd', $hWnd)
DllStructSetData($tNID, 'uID', 1)
DllStructSetData($tNID, 'uFlags', $NIF_ICON)
DllStructSetData($tNID, 'hIcon', $hIcon)

_Shell_NotifyIcon($NIM_MODIFY, $pNID)
Sleep(2000)
_WinAPI_DestroyIcon($hIcon)
_WinAPI_FreeLibrary($hDll)
Exit


Func _LoadIcon($hInstance, $sIconName)
    Local $aRet
    
    $aRet = DllCall('user32.dll', 'hwnd', 'LoadIconA', 'hwnd', $hInstance, 'uint', $sIconName)
    If @error Then Return SetError(1, 0, 0)
    Return $aRet[0]
EndFunc

Func _Shell_NotifyIcon($iMessage, $pdata)
    Local $aRet
    
    $aRet = DllCall('shell32.dll', 'int', 'Shell_NotifyIconW', 'dword', $iMessage, 'ptr', $pdata)
    If @error Then Return SetError(1, 0, 0)
    Return $aRet[0]
EndFunc
It`s exelent, Authenticity! I also played with Shell_NotifyIcon, but not decided how to define "uID".

Thanks.

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...