_GUIImageList

  • Hiho,

    wollte mal mein Projekt: Window(s) Management mal wieder was aufpeppen und dazu unter anderen die icons der Programme in der Liste anzeigen lassen. Leider funktioniert es nicht, kann mir jmd erklären, warum???

    Spoiler anzeigen
    [autoit]

    #include <GuiImageList.au3>
    #include <GuiListView.au3>
    #include <Misc.au3>
    #include <Process.au3>
    #include <WinAPI.au3>
    #include <Constants.au3>
    #include <ListViewConstants.au3>
    #include <WindowsConstants.au3>

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

    ;-----------------------------------------------------------------------------
    ; 1 Instance
    ;-----------------------------------------------------------------------------

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

    If _Singleton(@ScriptName, 1) = 0 Then
    Msgbox(16,"Warning","An occurence is already running", 10)
    Exit
    EndIf

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

    ;-----------------------------------------------------------------------------
    ; Options
    ;-----------------------------------------------------------------------------

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

    Opt("GUIOnEventMode", 1)
    Opt("WinTitleMatchMode", 2)
    Opt("OnExitFunc", "_OnExitFunc")
    Opt("GUICloseOnESC", 0)
    Opt("MustDeclareVars", 0)

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

    Opt("TrayMenuMode",1)
    Opt("TrayOnEventMode",1)
    TraySetClick(8)

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

    Global $Title = "Window Management DeluxXx Edition V++"
    Global $i_transcolor, $Transparency

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

    #Region ### START Koda GUI section ### Form=o:\autoscripts\window management\form1.kxf

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

    $Form1_1 = GUICreate($Title, 510, 301, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU ,$DS_SETFOREGROUND), $WS_EX_TOPMOST)
    $contextmenu = GUICtrlCreateContextMenu()
    $TabSheet1 = GUICtrlCreateTabItem("Windows")
    $ListView1 = GUICtrlCreateListView("", 3, 23, 500, 228, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT));BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS), BitOR($LVS_EX_SUBITEMIMAGES, $WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_HEADERDRAGDROP,$LVS_EX_FULLROWSELECT))
    $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
    _GUICtrlListView_SetExtendedListViewStyle($ListView1, $exStyles)
    $hImage = _GUIImageList_Create();16, 16, 5, 3)
    _GUICtrlListView_AddColumn($ListView1, "Window", 80)
    _GUICtrlListView_AddColumn($ListView1, "Exe", 80)
    _GUICtrlListView_AddColumn($ListView1, "PID", 50)
    _GUICtrlListView_AddColumn($ListView1, "Dir", 160)
    _GUICtrlListView_AddColumn($ListView1, "Handle", 70)

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

    $Button1 = GUICtrlCreateButton("update", 3, 253, 500, 25, 0, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
    GUICtrlSetOnEvent($Button1, "_UpdateListView")

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

    GUISetState(@SW_SHOW, $Form1_1)

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

    While 1
    Sleep(100)
    WEnd

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

    Func _UpdateListView()
    _GUICtrlListView_DeleteAllItems($ListView1)
    $WinList = WinList()
    For $i = 1 to $WinList[0][0]
    If Not @error Then
    If $WinList[$i][0] <> "" AND IsVisible($WinList[$i][1]) Then
    $PID = WinGetProcess($WinList[$i][0])
    $ProcessName = _ProcessGetName($PID)
    $WinGetHandle = WinGetHandle($WinList[$i][0])
    $WinGetPath = _WinGetPath($PID)
    If $ProcessName = @ScriptName Then
    Else
    $GetIconCount = _GetIconCount($WinGetPath)
    If $WinGetPath <> @WindowsDir & "\Explorer.exe" then; AND $icon_exists <> 0 then
    If $GetIconCount <> 0 then
    $ImageAddIcon = _GUIImageList_AddIcon($hImage, $WinGetPath)
    If @error then $ImageAddIcon = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4)
    Else
    $ImageAddIcon = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 2)
    EndIf
    Else
    $ImageAddIcon = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4)
    EndIf
    _GUICtrlListView_AddItem($ListView1, $WinList[$i][0], _GUIImageList_GetImageCount($hImage)-1, _GUICtrlListView_GetItemCount($ListView1)+999)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $ProcessName, 1)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $PID, 2)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $WinGetPath, 3)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $WinGetHandle, 4)
    EndIf
    EndIf
    EndIf
    Next
    EndFunc

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

    ;check if win is "on top"
    Func _WinIsOnTop($WindowHandle)
    Local $long = _WinAPI_GetWindowLong(WinGetHandle($WindowHandle),$GWL_EXSTYLE)
    Return BitAND($long,8)=8 ; $WS_EX_TOPMOST = 8
    EndFunc ; Author(s): Prog@ndy

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

    ;check if window is visible
    Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
    Else
    Return 0
    EndIf
    EndFunc

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

    ;get transparency of a window
    Func _API_GetLayeredWindowAttributes($hwnd, ByRef $i_transcolor, ByRef $Transparency)
    $i_transcolor = -1
    $Transparency = -1
    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    Local Const $LWA_ALPHA = 0x2
    Local Const $LWA_COLORKEY = 0x1
    Local $Ret = DllCall("user32.dll", "int", "GetLayeredWindowAttributes", "hwnd", $hwnd, "long*", $i_transcolor, "byte*", $Transparency, "long*",0)
    Select
    Case @error
    Return SetError(@error,0,0)
    Case $ret[0] = 0
    Return SetError(4,0,0)
    Case Else
    $i_transcolor = $ret[2]
    $Transparency = $ret[3]
    Return $ret[4]
    EndSelect
    EndFunc ; Author(s): Prog@ndy

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

    Func _WinGetPath($proc_pid="", $sInResString="", $iWholeWord=1)
    Local $hKernel32_Dll = DllOpen('Kernel32.dll'), $hPsapi_Dll = DllOpen('Psapi.dll')
    Local $aOpenProc, $aProcPath, $sFileVersion
    If $hKernel32_Dll = -1 Then Return SetError(1, 0, '')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then Return SetError(2, 0, '')
    Local $vStruct = DllStructCreate('int[1024]')
    Local $pStructPtr = DllStructGetPtr($vStruct)
    Local $iStructSize = DllStructGetSize($vStruct)
    $aOpenProc = DllCall($hKernel32_Dll, 'hwnd', 'OpenProcess', _
    'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $proc_pid)
    DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
    'hwnd', $aOpenProc[0], _
    'ptr', $pStructPtr, _
    'int', $iStructSize, _
    'int_ptr', 0)
    $aProcPath = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
    'hwnd', $aOpenProc[0], _
    'int', DllStructGetData($vStruct, 1), _
    'str', '', _
    'int', 2048)
    Local $return = $aProcPath[3]
    DllClose($hKernel32_Dll)
    DllClose($hPsapi_Dll)
    Return $return
    EndFunc ; Author: Salin

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

    Func _GetIconCount($sFilename)
    Local $iCount= DllCall("Shell32", "int", "ExtractIconEx", "str", $sFilename, "int", -1, "ptr", 0, "ptr", 0, "int", 1)
    If not @error Then Return $iCount[0]
    Return 0
    EndFunc ; Author: Salin

    [/autoit]
    • Offizieller Beitrag

    Hab eben dein Script mal laufen lassen . Wie beendet man das ? Tray Menu ist net da , Esc Funzt net . Ein Klick auf X ist auch nicht von Erfolg gekrönt. Hilft eigentlich nur killen per Taskmanager .

    • Offizieller Beitrag

    Strg und Pause funzt net . Ohne ergebnis bleibt nur der Taskman.

    Wo in deimen Script Zeichnest du eigentlich die Icons ? Hab da nix gefunden .

    • Offizieller Beitrag

    Ich glaub ich habe die Lösung gefunden . Probier das mal aus :

    Spoiler anzeigen
    [autoit]

    Func _UpdateListView()
    _GUICtrlListView_DeleteAllItems($ListView1)
    $WinList = WinList()
    For $i = 1 to $WinList[0][0]
    If Not @error Then
    If $WinList[$i][0] <> "" AND IsVisible($WinList[$i][1]) Then
    $PID = WinGetProcess($WinList[$i][0])
    $ProcessName = _ProcessGetName($PID)
    $WinGetHandle = WinGetHandle($WinList[$i][0])
    $WinGetPath = _WinGetPath($PID)
    If $ProcessName = @ScriptName Then
    Else
    $GetIconCount = _GetIconCount($WinGetPath)
    If $WinGetPath <> @WindowsDir & "\Explorer.exe" then; AND $icon_exists <> 0 then
    If $GetIconCount <> 0 then
    $ImageAddIcon = _GUIImageList_AddIcon($hImage, $WinGetPath)
    If @error then $ImageAddIcon = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4)
    Else
    $ImageAddIcon = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 2)
    EndIf
    Else
    $ImageAddIcon = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4)
    EndIf
    _GUICtrlListView_SetImageList($ListView1, $hImage, 1)
    _GUICtrlListView_AddItem($ListView1, $WinList[$i][0], _GUIImageList_GetImageCount($hImage)-1, _GUICtrlListView_GetItemCount($ListView1)+999)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $ProcessName, 1)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $PID, 2)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $WinGetPath, 3)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $WinGetHandle, 4)
    EndIf
    EndIf
    EndIf
    Next
    EndFunc

    [/autoit]

    Hier das ganze Script (hab den OnEventMode gekappt um besser testen zu können

    Spoiler anzeigen
    [autoit]

    #include <GuiImageList.au3>
    #include <GuiListView.au3>
    #include <Misc.au3>
    #include <Process.au3>
    #include <WinAPI.au3>
    #include <Constants.au3>
    #include <ListViewConstants.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>
    ;-----------------------------------------------------------------------------
    ; 1 Instance
    ;-----------------------------------------------------------------------------

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

    If _Singleton(@ScriptName, 1) = 0 Then
    Msgbox(16,"Warning","An occurence is already running", 10)
    Exit
    EndIf

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

    ;-----------------------------------------------------------------------------
    ; Options
    ;-----------------------------------------------------------------------------

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

    Opt("GUIOnEventMode", 0)
    Opt("WinTitleMatchMode", 2)
    Opt("OnExitFunc", "_OnExitFunc")
    Opt("GUICloseOnESC", 1)
    Opt("MustDeclareVars", 0)

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

    Opt("TrayMenuMode",1)
    Opt("TrayOnEventMode",1)
    TraySetClick(8)

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

    Global $Title = "Window Management DeluxXx Edition V++"
    Global $i_transcolor, $Transparency

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

    #Region ### START Koda GUI section ### Form=o:\autoscripts\window management\form1.kxf

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

    $Form1_1 = GUICreate($Title, 510, 301, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU ,$DS_SETFOREGROUND), $WS_EX_TOPMOST)
    $contextmenu = GUICtrlCreateContextMenu()
    $TabSheet1 = GUICtrlCreateTabItem("Windows")
    $ListView1 = GUICtrlCreateListView("", 3, 23, 500, 228, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT));BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS), BitOR($LVS_EX_SUBITEMIMAGES, $WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_HEADERDRAGDROP,$LVS_EX_FULLROWSELECT))
    $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
    _GUICtrlListView_SetExtendedListViewStyle($ListView1, $exStyles)
    $hImage = _GUIImageList_Create()
    _GUICtrlListView_AddColumn($ListView1, "Window", 80)
    _GUICtrlListView_AddColumn($ListView1, "Exe", 80)
    _GUICtrlListView_AddColumn($ListView1, "PID", 50)
    _GUICtrlListView_AddColumn($ListView1, "Dir", 160)
    _GUICtrlListView_AddColumn($ListView1, "Handle", 70)

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

    $Button1 = GUICtrlCreateButton("update", 3, 253, 500, 25, 0, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
    GUICtrlSetOnEvent($Button1, "_UpdateListView")

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

    GUISetState(@SW_SHOW, $Form1_1)

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

    While 1
    $msg = GUIGetMsg()

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

    Select
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
    Case $Msg = $Button1
    _UpdateListView()
    EndSelect
    Sleep(100)
    WEnd

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

    Func _UpdateListView()
    _GUICtrlListView_DeleteAllItems($ListView1)
    $WinList = WinList()
    For $i = 1 to $WinList[0][0]
    If Not @error Then
    If $WinList[$i][0] <> "" AND IsVisible($WinList[$i][1]) Then
    $PID = WinGetProcess($WinList[$i][0])
    $ProcessName = _ProcessGetName($PID)
    $WinGetHandle = WinGetHandle($WinList[$i][0])
    $WinGetPath = _WinGetPath($PID)
    If $ProcessName = @ScriptName Then
    Else
    $GetIconCount = _GetIconCount($WinGetPath)
    If $WinGetPath <> @WindowsDir & "\Explorer.exe" then; AND $icon_exists <> 0 then
    If $GetIconCount <> 0 then
    $ImageAddIcon = _GUIImageList_AddIcon($hImage, $WinGetPath)
    If @error then $ImageAddIcon = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4)
    Else
    $ImageAddIcon = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 2)
    EndIf
    Else
    $ImageAddIcon = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4)
    EndIf
    _GUICtrlListView_SetImageList($ListView1, $hImage, 1)
    _GUICtrlListView_AddItem($ListView1, $WinList[$i][0], _GUIImageList_GetImageCount($hImage)-1, _GUICtrlListView_GetItemCount($ListView1)+999)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $ProcessName, 1)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $PID, 2)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $WinGetPath, 3)
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $WinGetHandle, 4)
    EndIf
    EndIf
    EndIf
    Next
    EndFunc

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

    ;check if win is "on top"
    Func _WinIsOnTop($WindowHandle)
    Local $long = _WinAPI_GetWindowLong(WinGetHandle($WindowHandle),$GWL_EXSTYLE)
    Return BitAND($long,8)=8 ; $WS_EX_TOPMOST = 8
    EndFunc ; Author(s): Prog@ndy

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

    ;check if window is visible
    Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
    Else
    Return 0
    EndIf
    EndFunc

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

    ;get transparency of a window
    Func _API_GetLayeredWindowAttributes($hwnd, ByRef $i_transcolor, ByRef $Transparency)
    $i_transcolor = -1
    $Transparency = -1
    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    Local Const $LWA_ALPHA = 0x2
    Local Const $LWA_COLORKEY = 0x1
    Local $Ret = DllCall("user32.dll", "int", "GetLayeredWindowAttributes", "hwnd", $hwnd, "long*", $i_transcolor, "byte*", $Transparency, "long*",0)
    Select
    Case @error
    Return SetError(@error,0,0)
    Case $ret[0] = 0
    Return SetError(4,0,0)
    Case Else
    $i_transcolor = $ret[2]
    $Transparency = $ret[3]
    Return $ret[4]
    EndSelect
    EndFunc ; Author(s): Prog@ndy

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

    Func _WinGetPath($proc_pid="", $sInResString="", $iWholeWord=1)
    Local $hKernel32_Dll = DllOpen('Kernel32.dll'), $hPsapi_Dll = DllOpen('Psapi.dll')
    Local $aOpenProc, $aProcPath, $sFileVersion
    If $hKernel32_Dll = -1 Then Return SetError(1, 0, '')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then Return SetError(2, 0, '')
    Local $vStruct = DllStructCreate('int[1024]')
    Local $pStructPtr = DllStructGetPtr($vStruct)
    Local $iStructSize = DllStructGetSize($vStruct)
    $aOpenProc = DllCall($hKernel32_Dll, 'hwnd', 'OpenProcess', _
    'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $proc_pid)
    DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
    'hwnd', $aOpenProc[0], _
    'ptr', $pStructPtr, _
    'int', $iStructSize, _
    'int_ptr', 0)
    $aProcPath = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
    'hwnd', $aOpenProc[0], _
    'int', DllStructGetData($vStruct, 1), _
    'str', '', _
    'int', 2048)
    Local $return = $aProcPath[3]
    DllClose($hKernel32_Dll)
    DllClose($hPsapi_Dll)
    Return $return
    EndFunc ; Author: Salin

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

    Func _GetIconCount($sFilename)
    Local $iCount= DllCall("Shell32", "int", "ExtractIconEx", "str", $sFilename, "int", -1, "ptr", 0, "ptr", 0, "int", 1)
    If not @error Then Return $iCount[0]
    Return 0
    EndFunc ; Author: Salin

    [/autoit]

    Verbesserungsvorschlag: Wenn du Update drückst sollte nichts hintenangehängt werden. Besser wäre ein Refresh

    • Offizieller Beitrag

    Kein Problem gern geschehen .