GUICtrlSetImage Icon und Bild problem

  • Hallo,

    ich hab ein Problem.

    Mein Problem ist, wenn ich mit GUICtrlSetImage ein Pfad von Dateien wie .exe angebe werden die Icons auf die Butten gesetzt. Jedoch bei Bildern nicht.
    Ich will, wenn ich ein Bild wähle z. B. .jpg soll es diesen JPG als Bild zeigen.

    Ich programmiere zuzeit sowas wie Shortcuts.

    [autoit]


    local $ShortcutPath = $Shortcuts[$ValueRow][1]

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

    if not FileExists($ShortcutPath) then ContinueLoop

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

    local $Width = 60, $Height = 60
    local $GUI_BUTTON_ID = GUICtrlCreateButton($ShortcutPath, mod($ValueRow - 1, 4) * $Width, int(($ValueRow - 1)/ 4) * $Height, $Width, $Height)
    local $Ret = GUICtrlSetImage($GUI_BUTTON_ID, $ShortcutPath, 0, 1)

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

    ;~ if $Ret == 0 Then
    ;~ $Ret = GUICtrlSetImage($GUI_BUTTON_ID, $ShortcutPath)
    ;~ EndIf

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

    ConsoleWrite($Ret & " " & $ShortcutPath & " " & $GUI_BUTTON_ID & @CRLF)

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

    if not $Buttons_Info[$GUI_BUTTON_ID] Then
    $Buttons_Info[$GUI_BUTTON_ID] = $ShortcutPath
    EndIf

    [/autoit]

    Einmal editiert, zuletzt von MaZy (8. April 2012 um 13:49)

  • Also es hat trotzdem nicht funktioniert.
    Sogar das das Gegenteil wurde bewirkt. Jetzt sehe ich nicht mal irgendein Icon auf den Button.

    [autoit]


    Local $GUI_BUTTON_ID = GUICtrlCreateButton($ShortcutPath, mod($ValueRow - 1, 4) * $Width, int(($ValueRow - 1)/ 4) * $Height, $Width, $Height, $BS_BITMAP)
    local $Ret = GUICtrlSetImage($GUI_BUTTON_ID, $ShortcutPath, 0, 1)

    [/autoit]
  • Das mit Icons funktionert ja schon. Ich will mich aber auf die Dateipfade beziehen. Die ganzen Dateien die mit .exe ihre Icons werden ja in der Gui angezeigt
    Jedoch, wenn ich als Shortcut in Gui z.B. ein Bild habe, wird es nicht angezeigt. Da ist ja so ein komisches Bild bzw. Icon von Windows. Ist ja auch egal. Ich will lieber das Bild selbst in Button anzeigen sozusagen als Minivorschaubild

    Ich hab das nun bissel erweitert

    [autoit]


    Local $typ
    Local $isExe = 1
    Local $GUI_BUTTON_ID

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

    $typ = getDatatyp($ShortcutPath)

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

    if StringLower($typ) <> "exe" Then $isExe = 0

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

    if not FileExists($ShortcutPath) then ContinueLoop

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

    local $Width = 60, $Height = 60
    if $isExe Then
    $GUI_BUTTON_ID = GUICtrlCreateButton($ShortcutPath, mod($ValueRow - 1, 4) * $Width, int(($ValueRow - 1)/ 4) * $Height, $Width, $Height, $BS_ICON)
    GUICtrlSetImage($GUI_BUTTON_ID, $ShortcutPath, 0, 1)
    Else
    $GUI_BUTTON_ID = GUICtrlCreatePic($ShortcutPath, mod($ValueRow - 1, 4) * $Width, int(($ValueRow - 1)/ 4) * $Height, $Width, $Height)
    ;GUICtrlSetImage($GUI_BUTTON_ID, $ShortcutPath, 0, 1)
    EndIf

    [/autoit]

    Das ist zwar ne alternative aber das ich GUICtrlCreatePic benutzen muss nervt bissel ^^.
    Dabei hab ich es mit $BS_BITMAP versucht und geht net

    Einmal editiert, zuletzt von MaZy (17. April 2012 um 17:49)

  • Ich denke es ist folgendes gemeint.

    Aus den Exe-Dateien werden die Icons angezeigt, aber handelt es sich um eine BMP-Datei, wird das Standard-Symbol von Windows angezeigt, es soll aber an der stelle das Bild selber als Icon erscheinen.

    Glaube das geht so nicht, den du muss erst die BMP-Datei auslesen und daraus ein Icon machen und das dann halt einfügen oder?

    Mal sehen was als Antwort kommen wird

  • Samson71
    Du hast mich verstanden :). Ich habe jetzt dafür ein UDF gefunden: http://www.autoitscript.com/forum/topic/92675-icons-udf/

    Aber leider reicht es mir nicht aus. Ich habe hier zum Beispiel ein Gimp Project File. Er hat die Endung .xcf. Der hat auch ein Icon. Ein Fuchs glaub ich mit einer Datei. Zum Bespiel will ich die Datei in meiner Gui hinzufügen und da soll dann das Icon angezeigt werden.

    Wahrscheinlich hat Greenhorn dort recht. Da muss ich es extrahrieren. Sowas wie "Create Icon from File" Funktion

    EDIT: Hab mal ein Bild hochgeladen wo ihr ungefähr vorstellen könnt wie ich das mein. Dort sieht ihr einige Icons aus Bilddateien (Bmp, Jpeg, png) oder ausführbaren Dateien (exe). Per Mausklick starten sie dann auch die mit gespeicherte Pfad zu der Datei.

  • Moin,

    also für Dateiendungen kannst Du schon einmal so etwas nutzen:

    Spoiler anzeigen
    [autoit]

    Global $sRes

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

    If (GetDefaultIcon ("jpg", $sRes)) Then
    ConsoleWrite (StringFormat ("Path: %s\n", $sRes[0]))
    ConsoleWrite (StringFormat ("Ordinal: %d\n", $sRes[1]))
    EndIf

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

    Func GetDefaultIcon ($sExtension, ByRef $sIconInfo)

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

    Local $sBuffer

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

    $sBuffer = StringFormat ("HKCR\\.%s", $sExtension)
    $sResult = RegRead ($sBuffer, "")
    $sBuffer = StringFormat ("HKCR\\%s\\DefaultIcon", $sResult)
    $sResult = RegRead ($sBuffer, "")
    $sResult = StringSplit ($sResult, ',', 2)

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

    If (IsArray ($sResult)) Then
    $sIconInfo = $sResult
    Return 1
    Else
    Return 0
    EndIf

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

    EndFunc

    [/autoit]

    Gruß
    Greenhorn