Prozessliste in Combobox laden mit Icons

  • Moin moin,

    ich habe folgendes Problem, ich habe alle aktiven Prozesse geschafft in eine Combobox zu laden, jetzt wollte ich aber das vor den Prozessen auch ein Icon ist, wie geht das? ^^
    Und wie kann man über einen Button die Liste akutalisieren falls neue Prozesse geöffnet werden?

    Mit freundlichen Grüßen

    volle

  • Hi,
    hier ein kleines Beispiel mit einer ImageList und einfachen farbigen Rechtecken...

    [autoit]

    #include <GuiComboBoxEx.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiImageList.au3>

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

    $Form1 = GUICreate("Form1", 250,20,100,100)
    $hCombo = _GUICtrlComboBoxEx_Create ($Form1, "", 0, 0, 150,200)
    $Button1 = GUICtrlCreateButton("Aktualisieren", 150,0,100,20)
    _GetProcess()
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    _GetProcess()
    EndSwitch
    WEnd

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

    Func _GetProcess()
    GUISetState(@SW_DISABLE)
    _GUICtrlComboBox_ResetContent($hCombo)
    Local $List = ProcessList()
    Local $hImage = _GUIImageList_Create (16,16, 5, 3)
    For $i = 1 to UBound($List,1)-1
    _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap ($hCombo, '0x' & StringRight(Hex(Random(0,16777215,1)),6), 16,16))
    Next
    _GUICtrlComboBoxEx_SetImageList ($hCombo, $hImage)
    For $i = 1 to UBound($List,1)-1
    _GUICtrlComboBoxEx_AddString($hCombo, $List[$i][0],$i,$i)
    Next
    _GUICtrlComboBox_SetCurSel($hCombo,0)
    GUISetState(@SW_ENABLE)
    EndFunc

    [/autoit]

    Ich hoffe es hilft,
    RapIt

  • Spoiler anzeigen
    [autoit]

    #region - Timestamp
    ;2011-11-05 13:03:11
    #endregion - Timestamp

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

    $sProcess = "opera.exe"
    $hGUI = GUICreate("", 100, 100)
    GUICtrlCreateIcon(_ProcessGetIcon($sProcess), 0, 4, 4, 32, 32)
    GUISetState()

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

    Do
    Until GUIGetMsg() = -3

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

    ;Autor unbekannt
    Func _ProcessGetIcon($vProcess)
    Local $iPID = ProcessExists($vProcess)
    If Not $iPID Then Return SetError(1, 0, -1)

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

    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If Not IsArray($aProc) Or Not $aProc[0] Then Return SetError(2, 0, -1)

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

    Local $vStruct = DllStructCreate('int[1024]')

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

    Local $hPsapi_Dll = DllOpen('Psapi.dll')
    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(3, 0, '')

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

    DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
    'hwnd', $aProc[0], _
    'ptr', DllStructGetPtr($vStruct), _
    'int', DllStructGetSize($vStruct), _
    'int_ptr', 0)
    Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
    'hwnd', $aProc[0], _
    'int', DllStructGetData($vStruct, 1), _
    'str', '', _
    'int', 2048)

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

    DllClose($hPsapi_Dll)

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

    If Not IsArray($aRet) Or StringLen($aRet[3]) = 0 Then Return SetError(4, 0, '')
    Return $aRet[3]
    EndFunc ;==>_ProcessGetIcon

    [/autoit]
  • funkey :rolleyes: Da hätte ich wirklich selber drauf kommen können. Aber normalerweise haben doch eh nur ca. 10% der Prozesse Icons, darum hab ich den Sinn nicht verstanden. Egal, jetzt hat es sich ja geklärt.

    Hier meine umgebaute Funktion:

    Spoiler anzeigen
    [autoit]

    #include <GuiComboBoxEx.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiImageList.au3>

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

    $Form1 = GUICreate("Form1", 250,20,100,100)
    $hCombo = _GUICtrlComboBoxEx_Create ($Form1, "", 0, 0, 150,200)
    $Button1 = GUICtrlCreateButton("Aktualisieren", 150,0,100,20)
    _GetProcess()
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    _GetProcess()
    EndSwitch
    WEnd

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

    Func _GetProcess()
    GUISetState(@SW_DISABLE)
    _GUICtrlComboBox_ResetContent($hCombo)
    Local $List = ProcessList()
    Local $hImage = _GUIImageList_Create (16,16, 5, 3)
    Local $HasIcon
    For $i = 1 to UBound($List,1)-1
    ;~ _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap ($hCombo, '0x' & StringRight(Hex(Random(0,16777215,1)),6), 16,16))
    $HasIcon = _GUIImageList_AddIcon($hImage,$List[$i][0])
    ConsoleWrite($HasIcon)
    If $HasIcon = 0 Then
    _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap ($hCombo, '0x' & StringRight(Hex(Random(0,16777215,1)),6), 16,16))
    EndIf
    Next
    _GUICtrlComboBoxEx_SetImageList ($hCombo, $hImage)
    For $i = 1 to UBound($List,1)-1
    _GUICtrlComboBoxEx_AddString($hCombo, $List[$i][0],$i-1,$i-1)
    Next
    _GUICtrlComboBox_SetCurSel($hCombo,0)
    GUISetState(@SW_ENABLE)
    EndFunc

    [/autoit]

    Allerdings ist i2c's Funktion wohl besser, aber auch komplizierter. :) Mit meinem Beispiel kriegt man halt nicht alle… Bei meinen Prozessen krieg ich mit seiner Funktion 9/26 Icons, mit dem Beispiel von oben nur 7/26
    RapIt