Icon dynamisch erstellen

  • Ihr kennt doch sicher so Programme die im Tray menü zum Beispiel die CPU-Temperatur in Form eines Icons anzeigen.

    Dazu hab ich 3 Frage:

    1. Ist es auch in AutoIT möglich icons dynamisch zu erstellen und anzeigen zu lassen?
    2. Wenn ja, muss man das Icon auf der Festplatte zwischenspeichern oder kann man es auch nur im RAM anlegen?
    3. Hab in der Hilfe die Funktion _WinAPI_DrawIconEx gefunden. Gehts damit? Hat da jemand ein Beispiel für? Werde nämlich aus den Angaben nicht wirklich schlau.

    Edit: Gibt in der MSDN Die Funktion CreateIcon wobei ich da aus den Parametern auch nicht schlauer werd.

    2 Mal editiert, zuletzt von Bitboy (14. April 2009 um 08:02)

  • Hab es mal mit einem Trick versucht :D

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    TraySetIcon("Shell32.dll", -50)
    Opt('TrayIconHide', 0)
    Opt('GUIOnEventMode', 1)

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet('{ESC}', '_Ende')

    [/autoit] [autoit][/autoit] [autoit]

    Global $Titel = 'Icon-Fake'

    [/autoit] [autoit][/autoit] [autoit]

    Global $IconGui = GUICreate($Titel, 17, 18, 0, 0, $WS_POPUP)
    GUISetOnEvent(-3, '_Ende')
    GUISetBkColor(0x00FF00)
    DllCall("user32.dll", "int", "SetParent", "hwnd", $IconGui, "hwnd", _FindTrayToolbarWindow())
    WinMove($IconGui, "", 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    Global $Label = GUICtrlCreateLabel(@SEC, 0, 0, 17, 18, 0x201)
    GUICtrlSetTip(-1, 'Sekunden')

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    AdlibEnable('_Zyklus', 1000)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(10000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Zyklus()
    GUICtrlSetData($Label, @SEC)
    EndFunc ;==>_Zyklus

    [/autoit] [autoit][/autoit] [autoit]

    Func _Ende()
    Exit
    EndFunc ;==>_Ende

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Function Name: _FindTrayToolbarWindow
    ; Description: Utility function for finding Toolbar window hwnd
    ; Parameter(s): None
    ;
    ; Requirement(s): AutoIt3 Beta
    ; Return Value(s): On Success - Returns Toolbar window hwnd
    ; On Failure - returns -1
    ;
    ; Author(s): Tuape
    ;
    ;===============================================================================
    Func _FindTrayToolbarWindow()
    Local $hWnd = DLLCall("user32.dll","hwnd","FindWindow", "str", "Shell_TrayWnd", "int", 0)

    if @error Then return -1
    $hWnd = DLLCall("user32.dll","hwnd","FindWindowEx", "hwnd", $hWnd[0], "int", 0, "str", "TrayNotifyWnd", "int", 0);FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
    if @error Then return -1
    If @OSVersion <> "WIN_2000" Then
    $hWnd = DLLCall("user32.dll","hwnd","FindWindowEx", "hwnd", $hWnd[0], "int", 0, "str", "SysPager", "int", 0);FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
    if @error Then return -1
    EndIf
    $hWnd = DLLCall("user32.dll","hwnd","FindWindowEx", "hwnd", $hWnd[0], "int", 0, "str", "ToolbarWindow32", "int", 0);FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
    if @error Then return -1

    Return $hWnd[0]
    EndFunc

    [/autoit]
  • Ich habe es so Probiert, aber ich bekomme es nicht hin das er die Grafic als ICON speichert:(

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $hWnd = GUICreate("TrayIcon", 190, 52, 193, 125)
    $Slider1 = GUICtrlCreateSlider(2, 2, 150, 45)
    GUICtrlSetLimit(-1, 16, 0)
    GUICtrlSetData (-1,8)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $Pen1 = _GDIPlus_PenCreate(0xFF0000FF,16)
    $Pen2 = _GDIPlus_PenCreate(0xFFFF0000,16)
    _GDIPlus_GraphicsDrawLine($hGraphics, 170, 10, 170, 26 - GUICtrlRead ($Slider1),$Pen1)
    _GDIPlus_GraphicsDrawLine($hGraphics, 170, 10 +GUICtrlRead ($Slider1), 170, 26,$Pen2)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case -3
    Exit
    Case $Slider1
    _Ico(GUICtrlRead ($Slider1))
    EndSwitch
    WEnd
    Func _Ico($Status)
    _GDIPlus_GraphicsDrawLine($hGraphics, 170, 10, 170, 10 + $Status,$Pen1)
    _GDIPlus_GraphicsDrawLine($hGraphics, 170, 10 +$Status, 170, 26,$Pen2)
    _GDIPlus_ImageSaveToFile(_GDIPlus_BitmapCreateFromGraphics(16,16, $hGraphics),@ScriptDir & "\1.ico")
    EndFunc

    [/autoit]

    mfg. Jam00

  • Jetzt habe ich es nochmal verändert. So bleibt das Icon immer an erster Stelle.

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include 'systray.au3'

    [/autoit] [autoit][/autoit] [autoit]

    TraySetIcon("Shell32.dll", -50)
    Opt('TrayIconHide', 0)
    Opt('GUIOnEventMode', 1)

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet('{ESC}', '_Ende')

    [/autoit] [autoit][/autoit] [autoit]

    Global $aPos, $iIconIndex, $Titel = 'Icon-Fake', $sProcess = 'Autoit3.exe'
    If @Compiled Then $sProcess = @ScriptName

    [/autoit] [autoit][/autoit] [autoit]

    $iIconIndex = _SysTrayIconIndex($sProcess)
    $aPos = _SysTrayIconPosSize($iIconIndex)

    [/autoit] [autoit][/autoit] [autoit]

    Global $IconGui = GUICreate($Titel, $aPos[2], $aPos[3], 0, 0, $WS_POPUP)
    GUISetOnEvent(-3, '_Ende')
    GUISetBkColor(0x00FF00)
    DllCall("user32.dll", "int", "SetParent", "hwnd", $IconGui, "hwnd", _FindTrayToolbarWindow())

    [/autoit] [autoit][/autoit] [autoit]

    Global $Label = GUICtrlCreateLabel(@SEC, 0, 0, 17, 18, 0x201)
    GUICtrlSetTip(-1, 'Sekunden')

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    AdlibEnable('_Zyklus', 1000)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(10000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Zyklus()
    Local $iIconIndexNew = _SysTrayIconIndex($sProcess)
    If $iIconIndex <> $iIconIndexNew Then
    _SysTrayIconMove($iIconIndexNew, 0)
    EndIf
    $iIconIndex = $iIconIndexNew
    GUICtrlSetData($Label, @SEC)
    EndFunc ;==>_Zyklus

    [/autoit] [autoit][/autoit] [autoit]

    Func _Ende()
    Exit
    EndFunc ;==>_Ende

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Function Name: _SysTrayIconPosSize($iIndex=0)
    ; Description: Gets x & y position of systray icon,
    ; You get also width and height
    ; Parameter(s): $iIndex = icon index (Note: starting from 0)
    ;
    ; Requirement(s): AutoIt3 Beta
    ; Return Value(s): On Success - Returns x [0] and y [1] position of icon
    ; [2] for width and [3] for height
    ; On Failure - Returns -1 if icon is hidden (Autohide on XP etc.)
    ; Sets error to 1 if some internal error happens
    ;
    ; Author(s): Tuape
    ; Modified: funkey, just width and height
    ;
    ;===============================================================================
    Func _SysTrayIconPosSize($iIndex = 0)
    ;=========================================================
    ; Create the struct _TBBUTTON
    ; struct {
    ; int iBitmap;
    ; int idCommand;
    ; BYTE fsState;
    ; BYTE fsStyle;
    ;
    ; #ifdef _WIN64
    ; BYTE bReserved[6] // padding for alignment
    ; #elif defined(_WIN32)
    ; BYTE bReserved[2] // padding for alignment
    ; #endif
    ; DWORD_PTR dwData;
    ; INT_PTR iString;

    [/autoit] [autoit][/autoit] [autoit]

    ; }
    ;=========================================================
    Local $str = "int;int;byte;byte;byte[2];dword;int"
    Dim $TBBUTTON = DllStructCreate($str)
    Dim $TBBUTTON2 = DllStructCreate($str)
    Dim $ExtraData = DllStructCreate("dword[2]")
    Dim $lpData
    Dim $RECT

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Local $pId
    Local $text
    Local $procHandle
    Local $index = $iIndex
    Local $bytesRead
    Local $info
    Local $pos[4]
    Local $hidden = 0
    Local $trayHwnd
    Local $ret

    [/autoit] [autoit][/autoit] [autoit]

    $trayHwnd = _FindTrayToolbarWindow()
    If $trayHwnd = -1 Then
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    $ExtraData = 0
    SetError(1)
    Return -1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $ret = DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $trayHwnd, "int*", -1)
    If Not @error Then
    $pId = $ret[2]
    Else
    ConsoleWrite("Error: Could not find toolbar process id, " & @error & @LF)
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    $ExtraData = 0
    SetError(1)
    Return -1
    EndIf
    $procHandle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $PROCESS_ALL_ACCESS, 'int', False, 'int', $pId)
    If @error Then
    ConsoleWrite("Error: Could not read toolbar process memory, " & @error & @LF)
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    $ExtraData = 0
    SetError(1)
    Return -1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $lpData = DllCall("kernel32.dll", "int", "VirtualAllocEx", "int", $procHandle[0], "int", 0, "int", DllStructGetSize($TBBUTTON), "int", 0x1000, "int", 0x04)
    If @error Then
    ConsoleWrite(@CRLF & "VirtualAllocEx Error" & @LF)
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    $ExtraData = 0
    SetError(1)
    Return -1
    Else
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $trayHwnd, "int", $TB_GETBUTTON, "int", $index, "ptr", $lpData[0])
    DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $procHandle[0], 'int', $lpData[0], 'ptr', DllStructGetPtr($TBBUTTON2), 'int', DllStructGetSize($TBBUTTON), 'int', $bytesRead)
    DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $procHandle[0], 'int', DllStructGetData($TBBUTTON2, 6), 'int', DllStructGetPtr($ExtraData), 'int', DllStructGetSize($ExtraData), 'int', $bytesRead)

    [/autoit] [autoit][/autoit] [autoit]

    $info = DllStructGetData($ExtraData, 1, 1)
    If Not BitAND(DllStructGetData($TBBUTTON2, 3), 8) Then ; 8 = TBHIDDEN

    [/autoit] [autoit][/autoit] [autoit]

    $str = "int;int;int;int"
    $RECT = DllStructCreate($str)

    [/autoit] [autoit][/autoit] [autoit]

    DllCall("user32.dll", "int", "SendMessage", "hwnd", $trayHwnd, "int", $TB_GETITEMRECT, "int", $index, "ptr", $lpData[0])
    DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $procHandle[0], 'int', $lpData[0], 'ptr', DllStructGetPtr($RECT), 'int', DllStructGetSize($RECT), 'int', $bytesRead)

    [/autoit] [autoit][/autoit] [autoit]

    $ret = DllCall("user32.dll", "int", "MapWindowPoints", "hwnd", $trayHwnd, "int", 0, 'ptr', DllStructGetPtr($RECT), "int", 2)
    ;~ ConsoleWrite("Info: " & $info & "RECT[0](left): " & DllStructGetData($RECT, 1) & "RECT[1](top): " & DllStructGetData($RECT, 2) & "RECT[2](right): " & DllStructGetData($RECT, 3) & "RECT[3](bottom): " & DllStructGetData($RECT, 4) & @LF)

    [/autoit] [autoit][/autoit] [autoit]

    $pos[0] = DllStructGetData($RECT, 1)
    $pos[1] = DllStructGetData($RECT, 2)
    $pos[2] = DllStructGetData($RECT, 3) - $pos[0]
    $pos[3] = DllStructGetData($RECT, 4) - $pos[1]
    $RECT = 0
    Else
    $hidden = 1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    DllCall("kernel32.dll", "int", "VirtualFreeEx", "int", $procHandle[0], "ptr", $lpData[0], "int", 0, "int", 0x8000) ;DllStructGetSize ( $TBBUTTON ), "int", 0x8000)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $procHandle[0])
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    $ExtraData = 0

    [/autoit] [autoit][/autoit] [autoit]

    If $hidden <> 1 Then
    Return $pos
    Else
    Return -1
    EndIf
    EndFunc ;==>_SysTrayIconPosSize

    [/autoit]
  • Hier bitte, ein echtes TrayIcon mit GDIPlus. (Skript kommentiert)

    Spoiler anzeigen
    [autoit]

    #include<GDIplus.au3>
    #include<WindowsConstants.au3>
    #include<GUIConstants.au3>
    #include<Constants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ; Windows Konstanten
    Global Const $WM_RBUTTONDBLCLK = 0x206
    Global Const $WM_RBUTTONDOWN = 0x204
    Global Const $WM_RBUTTONUP = 0x205
    Global Const $WM_LBUTTONDBLCLK = 0x203
    Global Const $WM_LBUTTONDOWN = 0x201
    ;~ Global Const $WM_LBUTTONUP = 0x202
    Global Const $WM_MBUTTONDBLCLK = 0x209
    Global Const $WM_MBUTTONDOWN = 0x207
    Global Const $WM_MBUTTONUP = 0x208

    [/autoit] [autoit][/autoit] [autoit]

    #Region NotifyIcon Constants
    Select
    Case @OSBuild < 2195
    $tagNOTIFYICONDATAW_TEMP = "DWORD cbSize; HWND hWnd; UINT uID; UINT uFlags; UINT uCallbackMessage; ptr hIcon; WCHAR szTip[64];"
    Case Else
    $tagNOTIFYICONDATAW_TEMP = "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;"
    EndSelect
    Global Const $tagNOTIFYICONDATAW = $tagNOTIFYICONDATAW_TEMP
    Global Const $tagNOTIFYICONDATA = $tagNOTIFYICONDATAW

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $NIN_BALLOONSHOW = $WM_USER + 2
    Global Const $NIN_BALLOONHIDE = $WM_USER + 3
    Global Const $NIN_BALLOONTIMEOUT = $WM_USER + 4
    Global Const $NIN_BALLOONUSERCLICK = $WM_USER + 5

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global Const $NIM_ADD = 0x00000000
    Global Const $NIM_MODIFY = 0x00000001
    Global Const $NIM_DELETE = 0x00000002
    Global Const $NIM_SETFOCUS = 0x00000003
    Global Const $NIM_SETVERSION = 0x00000004

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $NIF_MESSAGE = 0x00000001
    Global Const $NIF_ICON = 0x00000002
    Global Const $NIF_TIP = 0x00000004
    Global Const $NIF_STATE = 0x00000008
    Global Const $NIF_INFO = 0x00000010
    Global Const $NIF_GUID = 0x00000020
    Global Const $NIF_REALTIME = 0x00000040
    Global Const $NIF_SHOWTIP = 0x00000080

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $NIS_VISIBLE = 0x00000000
    Global Const $NIS_HIDDEN = 0x00000001
    Global Const $NIS_SHAREDICON = 0x00000002

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $NIIF_NONE = 0x00000000
    Global Const $NIIF_INFO = 0x00000001
    Global Const $NIIF_WARNING = 0x00000002
    Global Const $NIIF_ERROR = 0x00000003
    Global Const $NIIF_USER = 0x00000004
    Global Const $NIIF_NOSOUND = 0x00000010
    Global Const $NIIF_LARGE_ICON = 0x00000010
    Global Const $NIIF_RESPECT_QUIET_TIME = 0x00000080
    Global Const $NIIF_ICON_MASK = 0x0000000F

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $WM_TRAYICONPROC = $WM_USER+100

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $HWND_For_TrayNotifications = GUICreate(@ScriptName&"TrayMsgWin",1,1,0,0,0,0,-3)
    #EndRegion

    [/autoit] [autoit][/autoit] [autoit]

    ; function to add / modify / delete NotfyIcon
    Func _Shell_NotifyIcon($dwMessage, ByRef $lpdata)
    ; Prog@ndy
    Local $ptr
    If IsDllStruct($lpdata) Then
    $ptr = DllStructGetPtr($lpdata)
    Else
    $ptr = Ptr($lpdata)
    EndIf
    Local $result = DllCall("shell32.dll", "int", "Shell_NotifyIconW", "dword", $dwMessage, "ptr", $ptr)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($result[0] = 0, 0, $result[0])
    EndFunc ;==>_Shell_NotifyIcon

    [/autoit] [autoit][/autoit] [autoit]

    ; function to create an Icon from a GDIplus-Bitmap
    Func _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap)
    ; Prog@ndy
    Local $result = DllCall($ghGDIPDLL, "int", "GdipCreateHICONFromBitmap", "ptr", $hBitmap, "ptr*", 0)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($result[0], 0, $result[2])
    EndFunc ;==>_GDIPlus_BitmapCreateHICONFromBitmap

    [/autoit] [autoit][/autoit] [autoit]

    ; Ereignisse für die TrayIcons
    GUIRegisterMsg($WM_TRAYICONPROC, "TRAYICONPROC")

    [/autoit] [autoit][/autoit] [autoit]

    ; GDIPlus starten
    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphics = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(16, 16, $hGraphics)
    _GDIPlus_GraphicsDispose($hGraphics)

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $Brush1 = _GDIPlus_BrushCreateSolid(0xFF0000FF)
    $Brush2 = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    _GDIPlus_GraphicsFillRect($hGraphics, 0, 0, 16, 16, $Brush1)

    [/autoit] [autoit][/autoit] [autoit]

    Opt("TrayAutoPause",0)
    #Region ### START Koda GUI section ### Form=
    $hwnd = GUICreate("TrayIcon", 200, 52, 193, 125)
    $Slider1 = GUICtrlCreateSlider(2, 2, 150, 45)
    GUICtrlSetLimit(-1, 16, 0)
    GUICtrlSetData(-1, 0)
    $chkzufall = GUICtrlCreateCheckbox("zufall",155,10,45,20)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $hIcon = _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap) ; Icon aus Bitmap erstellen

    [/autoit] [autoit][/autoit] [autoit]

    $ICON_ID = 333

    [/autoit] [autoit][/autoit] [autoit]

    $NOTIFYICONDATAW = DllStructCreate($tagNOTIFYICONDATAW) ; Daten für das Icon
    DllStructSetData($NOTIFYICONDATAW, 1, DllStructGetSize($NOTIFYICONDATAW))
    DllStructSetData($NOTIFYICONDATAW, "hWnd", $HWND_For_TrayNotifications)
    DllStructSetData($NOTIFYICONDATAW, "uID", $ICON_ID) ; ID für das Icon
    DllStructSetData($NOTIFYICONDATAW, "uFlags", BitOR($NIF_ICON, $NIF_TIP,$NIF_MESSAGE)) ; welche Eigenschaften sollen gesetzt werden
    DllStructSetData($NOTIFYICONDATAW, "hIcon", $hIcon) ; Icon-Handle setzen
    DllStructSetData($NOTIFYICONDATAW, "szTip", "Wert: 0") ; Tooltip setzen
    DllStructSetData($NOTIFYICONDATAW, "uCallbackMessage", $WM_TRAYICONPROC) ; die WindowMessage zum Empfangen von Ereignissen festelgen

    [/autoit] [autoit][/autoit] [autoit]

    _Shell_NotifyIcon($NIM_ADD, $NOTIFYICONDATAW) ; Das Icon erzeugen

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_DestroyIcon($hIcon) ; Das Icon wieder löschen. Das TrayIcon hat eine Kopie davon erhalten.
    DllStructSetData($NOTIFYICONDATAW, "uFlags", BitOR($NIF_ICON, $NIF_TIP)) ; Die gleiche Struktur wird später auch verwendet, aber nur, um
    ; das Icon und den tooltip zu ändern.

    [/autoit] [autoit][/autoit] [autoit]

    $OldSlider = 0
    While 1
    Switch GUIGetMsg()
    Case - 3
    Exit
    Case $chkzufall
    If BitAND(GUICtrlRead($chkzufall),1)=1 Then
    AdlibEnable("ZufallsWert",400)
    Else
    AdlibDisable()
    EndIf
    EndSwitch
    $NewSlider = GUICtrlRead($Slider1)
    If $NewSlider <> $OldSlider Then
    ; Das Icon neu malen
    _GDIPlus_GraphicsFillRect($hGraphics, 0, 0, 16, 16, $Brush1)
    _GDIPlus_GraphicsFillRect($hGraphics, 0, 16-$NewSlider, 16, 16, $Brush2)
    ; Das Icon erzeugen
    $hIcon = _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap)
    ; Das Icon setzen
    DllStructSetData($NOTIFYICONDATAW, "hIcon", $hIcon)
    DllStructSetData($NOTIFYICONDATAW, "szTip", "Wert: " & GUICtrlRead($Slider1))
    ; Das TrayIcon erhält eine Kopie.
    _Shell_NotifyIcon($NIM_MODIFY, $NOTIFYICONDATAW)
    ; Das Icon löschen
    _WinAPI_DestroyIcon($hIcon)
    $OldSlider = $NewSlider
    EndIf

    WEnd
    Func ZufallsWert()
    GUICtrlSetData($Slider1,Random(0,16,1))
    EndFunc
    Func OnAutoItExit()
    AdlibDisable()
    ; Aufräumen
    _Shell_NotifyIcon($NIM_DELETE, $NOTIFYICONDATAW) ; das TrayIcon löschen
    ; GDIPlus freigeben
    _GDIPlus_BrushDispose($Brush1)
    _GDIPlus_BrushDispose($Brush2)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    EndFunc ;==>OnAutoItExit

    [/autoit] [autoit][/autoit] [autoit]

    Func TRAYICONPROC($hwnd, $uMsg, $wParam, $lParam)
    ; Ereignisse für das TrayIcon
    Local $uTrayMsg = _WinAPI_LoWord($lParam)
    Local $nID = _WinAPI_HiWord($lParam)
    Switch $uTrayMsg
    Case $NIN_BALLOONSHOW
    ConsoleWrite("Balloon show" & @CRLF)
    Case $NIN_BALLOONHIDE
    ConsoleWrite("Balloon hide" & @CRLF)
    Case $NIN_BALLOONTIMEOUT
    ConsoleWrite("Balloon timeout" & @CRLF)
    Case $NIN_BALLOONUSERCLICK
    ConsoleWrite("Balloon userclick" & @CRLF)
    Case $WM_LBUTTONUP
    ConsoleWrite("left mousebutton Up" & @CRLF)
    Case $WM_RBUTTONUP
    ConsoleWrite("right mousebutton Up" & @CRLF)
    Case $WM_LBUTTONDOWN
    ConsoleWrite("left mousebutton Down" & @CRLF)
    Case $WM_RBUTTONDOWN
    ConsoleWrite("right mousebutton Down" & @CRLF)
    Case $WM_CONTEXTMENU
    ConsoleWrite("Context Menu" & @CRLF)
    EndSwitch
    Return _WinAPI_DefWindowProc($hwnd, $uMsg, $wParam, $lParam)
    EndFunc ;==>TRAYICONPROC

    [/autoit]


    //Edit: Jam00 findet immer Tippfehler ... Jetzt hat sich das ganze Skript geändert :P

    2 Mal editiert, zuletzt von progandy (10. April 2009 um 10:33)

  • Das Zeug bis Zeile 88 kann man in eine extra UDF packen ;)
    Das sind nur Konstanten und Funktionsdeklaarationen.
    Wenn man keine Klick auf dem Tray-Icon haben will, kann man auch GUIRegisterMsg und TRAYICONPROC entfernen.

    Und dann bleibt gar nicht mehr so viel übrig...

  • :pinch: als Strafe musst du jetzt das Skript noch mal anschauen, da hat sich jetzt noch mehr geändert :P