Bild von Webseite werden nicht im Label der EXE aktualisiert

  • Hallo zusammen,

    Ich möchte in einer EXE auf einem Label ein Bild aus dem Internet zeigen. Hierbei hat mir der Link von UEZ recht gut weiter geholfen.

    Da ich bereits einen Counter im Script habe, welche von 20 bis 1 runter zählt und dann wieder bei 20 anfängt, dachte ich, das hier eine geeignete Stelle für die Aktualisierung ist. Leider wird das Bild immer nur beim Starten der EXE vom Internet gezogen und danach nicht mehr aktualisiert.

    Hier wird das Bild vom Server geholt

    [autoit]

    _GDIPlus_Startup()
    Global $STM_SETIMAGE = 0x0172
    Global $hBmp = Load_BMP_From_Mem(InetRead("http://my.fqdn.tl/mypic.jpg"), True) ;to load an image from the net

    [/autoit][autoit]

    AdlibRegister("CountDown", 1000)

    [/autoit]

    Hier wird das Bild das erste mal eingefügt

    [autoit]

    $foto = GUICtrlCreatePic("", $varBilderMitte - 100, $varGUIWindowHeight - 200, $iWidth, $iHeight, 0x0200, 0x00000001)
    _WinAPI_DeleteObject(GUICtrlSendMsg($foto, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp))
    GUISetState()

    [/autoit]

    und hier die Funktion "Countdown"

    [autoit]

    Func CountDown()
    Static $iRest = 20
    $iRest -= 1
    If $iRest = -1 Then $iRest = 20; Counter wird wieder auf 20 gesetzt
    If $iRest = 20 Then _IEAction($IE, "refresh"); papacontrol wird refreshed
    If $iRest = 10 Then $hBmp = Load_BMP_From_Mem(InetRead("http://papacontrol.hasenmueller.de/mypapa.jpg"), True) ; wenn der Counter auf 10 ist, soll das Bild nochmals aus dem Internet in den Speicher geladen werden (hoffe ich :)
    If $iRest = 1 Then _WinAPI_DeleteObject(GUICtrlSendMsg($foto, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)); wenn der Counter auf 1 ist, "sollte" das Bild erneuert werden, macht es aber nicht
    ;~ If $iRest = 15 Then GUICtrlSetImage($foto, $hBmp)
    ;~ If $iRest = 20 Then GUISetState(@SW_SHOW)
    GUICtrlSetData($Label01, "In " & $iRest & " Sekunden wird die Seite automatisch neu geladen")
    GUISetState()
    EndFunc ;==>CountDown

    [/autoit]

    Ich habe hier vermutlich auch ein Verständnisproblem, da ja viel Code "nur geklaut" ist und man daher nicht unbedient alles genau versteht.

    Würde mich sehr über ein paar Tips freuen.

    Gruss Hassan

  • Hallo HassanMullah,

    poste bitte dein komplettes Skript. Da es sich um ein komplexeres Problem handelt bezweifle ich dass es anhand derCodeschnipsel gelöst werden kann,

    Edit: Tippfehlerteufel verjagt

    mfg autoBert

    Einmal editiert, zuletzt von autoBert (23. Juni 2012 um 13:12)

  • Probiere es mal damit:

    Spoiler anzeigen
    [autoit]


    ;coded by UEZ 2012
    #include <GUIConstantsEx.au3>
    #include <GDIPlus.au3>
    #Include <Memory.au3>

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

    Global $aLinks2Images[5] = [ _
    "http://www.autoitscript.com/forum/public/style_images/autoit/logo.png", _
    "http://www.autoit.de/wcf/images/future/autoit_logo_gtaspider.png", _
    "http://www.autoitscript.com/autoit3/files/graphics/autoit_builder_wall_800x600.jpg", _
    "http://www.autoitscript.com/autoit3/files/graphics/autoit_matrix_wall_800x600.jpg", _
    "http://www.autoitscript.com/autoit3/files/graphics/autoit_fire_wall_1024x768.jpg"]

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

    _GDIPlus_Startup()

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

    Global Const $IMAGE_BITMAP = 0
    Global Const $STM_SETIMAGE = 0x0172
    Global Const $hGUI = GUICreate("Image from Web 2 GUI Directly", 0, 0)
    GUISetBkColor(0x000000, $hGUI)
    Global Const $idPic = GUICtrlCreatePic("", 0, 0, 0, 0)
    GUISetState()
    Global Const $iYCaption = _WinAPI_GetSystemMetrics(4)
    Global Const $iYFixedFrame = _WinAPI_GetSystemMetrics(8)
    Global Const $iXFixedFrame = _WinAPI_GetSystemMetrics(7)

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

    Load2Ctrl($aLinks2Images[Random(0, UBound($aLinks2Images) -1, 1)])

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

    AdlibRegister("Slideshow", 5000)

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

    While True
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    AdlibUnRegister("Slideshow")
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
    EndSwitch
    WEnd

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

    Func Slideshow()
    Load2Ctrl($aLinks2Images[Random(0, UBound($aLinks2Images) -1, 1)])
    EndFunc

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

    Func Load2Ctrl($sUrl)
    Local $bin = InetRead($sUrl)
    If @error Then Return SetError(1, 0, 0)
    Local Const $hBitmap= Load_BMP_From_Mem($bin)
    Local Const $iWidth = _GDIPlus_ImageGetWidth($hBitmap)
    Local Const $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    WinMove($hGUI, "", (@DesktopWidth - $iWidth) / 2, (@DesktopHeight - $iHeight) / 2, $iWidth + 2 * $iXFixedFrame, $iHeight + $iYCaption + 2 * $iYFixedFrame, 2)
    GUICtrlSetPos($idPic, 0, 0, $iWidth, $iHeight)
    Local Const $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, 0))
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP))
    _WinAPI_DeleteObject($hHBITMAP)
    _GDIPlus_BitmapDispose($hBitmap)
    Return
    EndFunc

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

    ;======================================================================================
    ; Function Name: Load_BMP_From_Mem
    ; Description: Loads an image which is saved as a binary string and converts it to a bitmap or hbitmap
    ;
    ; Parameters: $bImage: the binary string which contains any valid image which is supported by GDI+
    ; Optional: $hHBITMAP: if false a bitmap will be created, if true a hbitmap will be created
    ;
    ; Remark: hbitmap format is used generally for GUI internal images, $bitmap is more a GDI+ image format
    ;
    ; Requirement(s): GDIPlus.au3, Memory.au3 and _GDIPlus_BitmapCreateDIBFromBitmap() from WinAPIEx.au3
    ; Return Value(s): Success: handle to bitmap or hbitmap, Error: 0
    ; Error codes: 1: $bImage is not a binary string
    ; 2: unable to create stream on HGlobal
    ; 3: unable to create bitmap from stream
    ;
    ; Author(s): UEZ
    ; Additional Code: thanks to progandy for the MemGlobalAlloc and tVARIANT lines
    ; Version: v0.97 Build 2012-01-04 Beta
    ;=======================================================================================
    Func Load_BMP_From_Mem($bImage, $hHBITMAP = False)
    If Not IsBinary($bImage) Then Return SetError(1, 0, 0)
    Local $aResult
    Local Const $memBitmap = Binary($bImage) ;load image saved in variable (memory) and convert it to binary
    Local Const $len = BinaryLen($memBitmap) ;get length of image
    Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002)
    Local Const $pData = _MemGlobalLock($hData) ;translate the handle into a pointer
    Local $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct
    DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
    _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE
    $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents
    If @error Then SetError(2, 0, 0)
    Local Const $hStream = $aResult[3]
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) ;Creates a Bitmap object based on an IStream COM interface
    If @error Then SetError(3, 0, 0)
    Local Const $hBitmap = $aResult[2]
    Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
    DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _
    "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak
    $tMem = 0
    $tVARIANT = 0
    If $hHBITMAP Then
    Local Const $hHBmp = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hHBmp
    EndIf
    Return $hBitmap
    EndFunc ;==>Load_BMP_From_Mem

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

    Func _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0
    $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($Ret[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate('dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword')
    DllStructSetData($tBIHDR, 1, DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 2, $Ret[2])
    DllStructSetData($tBIHDR, 3, $Ret[3])
    DllStructSetData($tBIHDR, 4, 1)
    DllStructSetData($tBIHDR, 5, 32)
    DllStructSetData($tBIHDR, 6, 0)
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult[0]) Then
    DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $Ret[2] * $Ret[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
    $hResult = $hResult[0]
    Else
    $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
    EndFunc ;==>_GDIPlus_BitmapCreateDIBFromBitmap

    [/autoit]

    So komplex ist es auch wiederum nicht!

    oiste butte ...


    :rofl:

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    2 Mal editiert, zuletzt von UEZ (23. Juni 2012 um 00:31)