Jump to content

need help with Shell_NotifyIconW please


jennico
 Share

Recommended Posts

studying ModernMenu, what am i doing wrong ? trayicon does not change:

Global Const $NIF_ICON = 0x00000002;Const 
Global Const $NIM_MODIFY = 0x00000001;Const 
Global $sNOTIFYICONDATAW                    =   "dword;" & _ ; Struct size
                                                "hwnd;" & _ ; Callback window handle
                                                "uint;" & _ ; Icon ID
                                                "uint;" & _ ; Flags
                                                "uint;" & _ ; Callback message ID
                                                "hwnd;" ; Icon handle

        $sNOTIFYICONDATAW &= "wchar[128];" & _ ; ToolTip text
                            "dword;" & _ ; Icon state
                            "dword;" & _ ; Icon state mask
                            "wchar[256];" & _ ; Balloon ToolTip text
                            "uint;" & _ ; Timeout / Version -> NIM_SETVERSION values 0, 3, 4
                            "wchar[64];" & _ ; Balloon ToolTip title text
                            "dword" ; Balloon ToolTip info flags

$S32="shell32.dll"

$gui=GUICreate("Shell_NotifyIconW")

GUISetState()

_TraySetIcon(999,"shell32.dll",1)


Do
Until GUIGetMsg()=-3



Func _TraySetIcon($nID = -1, $sIconFile = @AutoItExe, $nIconID = 0)

;   $nIconID = _GetIconID($nIconID, $sIconFile)
    
    Local $hIcon = 0
    
    Local $stIcon = DllStructCreate("hwnd")
        
    If ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1) > 0 Then
        $hIcon = DllStructGetData($stIcon, 1)
    Else
;       $hIcon = LoadIcon(0, 32516)
    EndIf
    
    Local $stNID    = DllStructCreate($sNOTIFYICONDATAW)
    DllStructSetData($stNID, 1, DllStructGetSize($stNID))
    DllStructSetData($stNID, 2, $gui)
    DllStructSetData($stNID, 3, $nID)
    DllStructSetData($stNID, 4, $NIF_ICON)
    DllStructSetData($stNID, 6, $hIcon)

    
    Local $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))

    Return $nResult
EndFunc

Func LoadIcon($hInstance, $nIcon)
    Local $hIcon = DllCall($hUser32Dll, "hwnd", "LoadIcon", _
                                                "hwnd", $hInstance, _
                                                "int", $nIcon)
    Return $hIcon[0]
EndFunc

Func ExtractIconExW($sIconFile, $nIconID, $ptrIconLarge, $ptrIconSmall, $nIcons)
    Local $nCount = DllCall($S32, "int", "ExtractIconExW", _
                                                "wstr", $sIconFile, _
                                                "int", $nIconID, _
                                                "ptr", $ptrIconLarge, _
                                                "ptr", $ptrIconSmall, _
                                                "int", $nIcons)
    Return $nCount[0]
EndFunc

Func Shell_NotifyIcon($nMessage, $pNID)
    Local $nResult = DllCall($S32, "int", "Shell_NotifyIconW", _
                                                    "int", $nMessage, _
                                                    "ptr", $pNID)
    Return $nResult[0]
EndFunc

maybe bcos i don't know $nID ?

thx

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

jennico

You need to add an icon to the system tray.

#NoTrayIcon ;Hide AutoIt default icon

Global Const $NIM_ADD = 0x00000000
Global Const $NIF_ICON = 0x00000002
Global Const $NIM_MODIFY = 0x00000001

Global $sNOTIFYICONDATAW = "dword;" & _ ; Struct size
        "hwnd;" & _ ; Callback window handle
        "uint;" & _ ; Icon ID
        "uint;" & _ ; Flags
        "uint;" & _ ; Callback message ID
        "hwnd;" ; Icon handle

$sNOTIFYICONDATAW &= "wchar[128];" & _ ; ToolTip text
        "dword;" & _ ; Icon state
        "dword;" & _ ; Icon state mask
        "wchar[256];" & _ ; Balloon ToolTip text
        "uint;" & _ ; Timeout / Version -> NIM_SETVERSION values 0, 3, 4
        "wchar[64];" & _ ; Balloon ToolTip title text
        "dword" ; Balloon ToolTip info flags

$S32 = "shell32.dll"

$gui = GUICreate("Shell_NotifyIconW", 1, 1, 9999, 9999, -1, 0x00000080)

GUISetState()

ShowWindow($gui, @SW_HIDE)

_TraySetIcon("Test", "shell32.dll", 1)

Do
Until GUIGetMsg() = -3

Func _TraySetIcon($nID = -1, $sIconFile = @AutoItExe, $nIconID = 0)

    ;   $nIconID = _GetIconID($nIconID, $sIconFile)

    Local $hIcon = 0

    Local $stIcon = DllStructCreate("hwnd")

    If ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1) > 0 Then
        $hIcon = DllStructGetData($stIcon, 1)
    Else
        ;      $hIcon = LoadIcon(0, 32516)
    EndIf

    Local $stNID = DllStructCreate($sNOTIFYICONDATAW)
    DllStructSetData($stNID, 1, DllStructGetSize($stNID))
    DllStructSetData($stNID, 2, $gui)
    DllStructSetData($stNID, 3, $nID)
    DllStructSetData($stNID, 4, $NIF_ICON)
    DllStructSetData($stNID, 6, $hIcon)

    ;Local $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
    
    Shell_NotifyIcon($NIM_ADD, DllStructGetPtr($stNID)) ;Adds an icon to the status area

    ;Return $nResult
EndFunc   ;==>_TraySetIcon

Func LoadIcon($hInstance, $nIcon)
    Local $hIcon = DllCall("User32.dll", "hwnd", "LoadIcon", _
            "hwnd", $hInstance, _
            "int", $nIcon)
    Return $hIcon[0]
EndFunc   ;==>LoadIcon

Func ExtractIconExW($sIconFile, $nIconID, $ptrIconLarge, $ptrIconSmall, $nIcons)
    Local $nCount = DllCall($S32, "int", "ExtractIconExW", _
            "wstr", $sIconFile, _
            "int", $nIconID, _
            "ptr", $ptrIconLarge, _
            "ptr", $ptrIconSmall, _
            "int", $nIcons)
    Return $nCount[0]
EndFunc   ;==>ExtractIconExW

Func Shell_NotifyIcon($nMessage, $pNID)
    Local $nResult = DllCall($S32, "int", "Shell_NotifyIconW", _
            "int", $nMessage, _
            "ptr", $pNID)
    Return $nResult[0]
EndFunc   ;==>Shell_NotifyIcon

Func ShowWindow($hWnd, $nState)
    DllCall("Shell32.dll", "int", "ShowWindow", _
                                "hwnd", $hWnd, _
                                "int", $nState)
EndFunc

:)

Link to comment
Share on other sites

thx, but i still fail in changing it:

#NoTrayIcon ;Hide AutoIt default icon

Global Const $NIM_ADD = 0x00000000
Global Const $NIF_ICON = 0x00000002
Global Const $NIM_MODIFY = 0x00000001

Global $sNOTIFYICONDATAW = "dword;" & _ ; Struct size
        "hwnd;" & _ ; Callback window handle
        "uint;" & _ ; Icon ID
        "uint;" & _ ; Flags
        "uint;" & _ ; Callback message ID
        "hwnd;" ; Icon handle

$sNOTIFYICONDATAW &= "wchar[128];" & _ ; ToolTip text
        "dword;" & _ ; Icon state
        "dword;" & _ ; Icon state mask
        "wchar[256];" & _ ; Balloon ToolTip text
        "uint;" & _ ; Timeout / Version -> NIM_SETVERSION values 0, 3, 4
        "wchar[64];" & _ ; Balloon ToolTip title text
        "dword" ; Balloon ToolTip info flags

$S32 = "shell32.dll"

$gui = GUICreate("Shell_NotifyIconW")

GUISetState()

$trayicon=_TraySetIcon("Test", "shell32.dll", 1)
Sleep(4000)
DestroyIcon($trayicon)
$trayicon=_TraySetIcon("Test", "shell32.dll", 2)

Do
Until GUIGetMsg() = -3

Func _TraySetIcon($nID = -1, $sIconFile = @AutoItExe, $nIconID = 0)

    ;   $nIconID = _GetIconID($nIconID, $sIconFile)

    Local $hIcon = 0

    Local $stIcon = DllStructCreate("hwnd")

    If ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1) > 0 Then
        $hIcon = DllStructGetData($stIcon, 1)
    Else
        ;      $hIcon = LoadIcon(0, 32516)
    EndIf

    Local $stNID = DllStructCreate($sNOTIFYICONDATAW)
    DllStructSetData($stNID, 1, DllStructGetSize($stNID))
    DllStructSetData($stNID, 2, $gui)
    DllStructSetData($stNID, 3, $nID)
    DllStructSetData($stNID, 4, $NIF_ICON)
    DllStructSetData($stNID, 6, $hIcon)

    ;Local $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
    
    Shell_NotifyIcon($NIM_ADD, DllStructGetPtr($stNID)) ;Adds an icon to the status area
Return $hIcon
    ;Return $nResult
EndFunc   ;==>_TraySetIcon

Func LoadIcon($hInstance, $nIcon)
    Local $hIcon = DllCall("User32.dll", "hwnd", "LoadIcon", _
            "hwnd", $hInstance, _
            "int", $nIcon)
    Return $hIcon[0]
EndFunc   ;==>LoadIcon

Func ExtractIconExW($sIconFile, $nIconID, $ptrIconLarge, $ptrIconSmall, $nIcons)
    Local $nCount = DllCall($S32, "int", "ExtractIconExW", _
            "wstr", $sIconFile, _
            "int", $nIconID, _
            "ptr", $ptrIconLarge, _
            "ptr", $ptrIconSmall, _
            "int", $nIcons)
    Return $nCount[0]
EndFunc   ;==>ExtractIconExW

Func Shell_NotifyIcon($nMessage, $pNID)
    Local $nResult = DllCall($S32, "int", "Shell_NotifyIconW", _
            "int", $nMessage, _
            "ptr", $pNID)
    Return $nResult[0]
EndFunc   ;==>Shell_NotifyIcon

Func DestroyIcon($hIcon)
    Local $bResult = DllCall("User32.Dll", "int", "DestroyIcon", _
                                                "hwnd", $hIcon)
    Return $bResult[0]
EndFunc

i create it, then i destroy it, i recreate it - but somehow it doesn't do what i want.

j.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

yes i know, but i want to understand it. and modernmenu is not written very userfriendly. i ve been thinking of cleaning the lines and make a standard UDF out of it, but it's hard to mork through.

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

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