Sign in to follow this  
Followers 0
binarydigit0101

image inside a pic, inside a tab, doesn't load.

3 posts in this topic

I would load an image inside a pic, inside a tab, when the form loads.

here there are 2 examples: the first works, the second not. where is the problem? is it the menù?

BinaryImage.au3

#include-once
#include<Memory.au3>
#include<GDIPlus.au3>

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_ImageLoadFromHGlobal
; Description ...: Creates an Image object based on movable HGlobal memory block
; Syntax.........: _GDIPlus_ImageLoadFromHGlobal($hGlobal)
; Parameters ....: $hGlobal - Handle of a movable HGlobal memory block
; Return values .: Success    - Pointer to a new Image object
;                 Failure     - 0 and either:
;                 |@error and @extended are set if DllCall failed:
;                 | -@error = 1 if could not create IStream
;                 | -@error = 2 if DLLCall to create image failed
;                 |$GDIP_STATUS contains a non zero value specifying the error code
; Author ........: ProgAndy
; Modified.......:
; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources.
;                 The HGLOBAL will be owned by the image and freed automatically when the image is disposed.
; Related .......: _GDIPlus_ImageLoadFromStream, _GDIPlus_ImageDispose
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GDIPlus_ImageLoadFromHGlobal($hGlobal)
    Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $hGlobal, "bool", True, "ptr*", 0)
    If @error Or $aResult[0] <> 0 Or $aResult[3] = 0 Then Return SetError(1, @error, 0)
    Local $hImage = DllCall($ghGDIPDll, "uint", "GdipLoadImageFromStream", "ptr", $aResult[3], "int*", 0)
    Local $error = @error
    Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
    Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aResult[3], "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT))
    If $error Then Return SetError(2, $error, 0)
    If $hImage[2] = 0 Then Return SetError(3, 0, $hImage[2])
    Return $hImage[2]
EndFunc   ;==>_GDIPlus_ImageLoadFromHGlobal


; #FUNCTION# ====================================================================================================================
; Name...........: _MemGlobalAllocFromBinary
; Description ...: Greates a movable HGLOBAL memory block from binary data
; Syntax.........: _MemGlobalAllocFromBinary($bBinary)
; Parameters ....: $bBinary - Binary data
; Return values .: Success    - Handle of a new movable HGLOBAL
;                 Failure     - 0 and set @error:
;                 |1  - no data
;                 |2  - could not allocate memory
;                 |3  - could not set data to memory
; Author ........: ProgAndy
; Modified.......:
; Remarks .......:
; Related .......: _MemGlobalAlloc, _MemGlobalFree, _MemGlobalLock
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _MemGlobalAllocFromBinary(Const $bBinary)
    Local $iLen = BinaryLen($bBinary)
    If $iLen = 0 Then Return SetError(1, 0, 0)
    Local $hMem = _MemGlobalAlloc($iLen, $GMEM_MOVEABLE)
    If @error Or Not $hMem Then Return SetError(2, 0, 0)
    DllStructSetData(DllStructCreate("byte[" & $iLen & "]", _MemGlobalLock($hMem)), 1, $bBinary)
    If @error Then
        _MemGlobalUnlock($hMem)
        _MemGlobalFree($hMem)
        Return SetError(3, 0, 0)
    EndIf
    _MemGlobalUnlock($hMem)
    Return $hMem
EndFunc   ;==>_MemGlobalAllocFromBinary

; #FUNCTION# ====================================================================================================================
; Name...........: _MemGlobalAllocFromMem
; Description ...: Greates a movable HGLOBAL memory block and copies data from memory
; Syntax.........: _MemGlobalAllocFromMem($pSource, $iLength)
; Parameters ....: $pSource  - Pointer to memorybloc to copy from
;                 $iLength  - Length of data to copy
; Return values .: Success    - Handle of a new movable HGLOBAL
;                 Failure     - 0 and set @error:
;                 |1  - invalid $pSource
;                 |2  - invalid $iLength
;                 |3  - could not allocate memory
; Author ........: ProgAndy
; Modified.......:
; Remarks .......:
; Related .......: _MemGlobalAlloc, _MemGlobalFree, _MemGlobalLock
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _MemGlobalAllocFromMem($pSource, $iLength)
    If Not $pSource Then Return SetError(1, 0, 0)
    If $iLength < 1 Then Return SetError(2, 0, 0)
    Local $hMem = _MemGlobalAlloc($iLength, $GMEM_MOVEABLE)
    If @error Or Not $hMem Then Return SetError(3, 0, 0)
    _MemMoveMemory($pSource, _MemGlobalLock($hMem), $iLength)
    _MemGlobalUnlock($hMem)
    Return $hMem
EndFunc   ;==>_MemGlobalAllocFromMem

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlStatic_SetImage
; Description ...: Sets a HBITMAP to a static control like image or label
; Syntax.........: _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
; Parameters ....: $iCtrlId  - CtrlId or handle of Control in the current process
;                 $hBitmap  - Pointer top Windows HBITMAP
; Return values .: Success    - 1
;                 Failure     - 0 and set @error:
;                 |1  - invalid $pSource
;                 |1  - invalid $pSource
; Author ........: ProgAndy, Zedna
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    If IsHWnd($iCtrlId) Then
        If WinGetProcess($iCtrlId) <> @AutoItPID Then Return SetError(1,0,0)
    Else
        $iCtrlId = GUICtrlGetHandle($iCtrlId)
        If Not $iCtrlId Then Return SetError(2,0,0)
    EndIf
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE)
    If @error Then Return SetError(3, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(4, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "handle", "SendMessageW", "hwnd", $iCtrlId, "int", $STM_SETIMAGE, "wparam", $IMAGE_BITMAP, "handle", $hBitmap)
    If @error Then Return SetError(5, 0, 0)
    If $oldBmp[0] Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

_GDIPlus_Startup()
$s = Binary(FileRead(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\Torus.png"))
$hMem = _MemGlobalAllocFromBinary($s)
$hImage = _GDIPlus_ImageLoadFromHGlobal($hMem)
$gui = GUICreate("Just draw the created image", 300, 300)
; GUISetState()
$hGRaph = _GDIPlus_GraphicsCreateFromHWND($gui)
_GDIPlus_GraphicsDrawImage($hGRaph, $hImage, 5, 5)
_GDIPlus_GraphicsDispose($hGRaph)


; Do
; Until GUIGetMsg() = -3

WinSetTitle($gui, "", "Now using _GUICtrlStatic_SetImage")
_WinAPI_RedrawWindow($gui)

$iLabel = GUICtrlCreateLabel("", 0, 0, 193, 184)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_ImageDispose($hImage)
_GUICtrlStatic_SetImage($iLabel, $hBitmap)

; Do
; Until GUIGetMsg() = -3

this code works:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#include <INet.au3>
#include <BinaryImage.au3>

#Region ### START Koda GUI section ### Form=
$form_principale = GUICreate("Monitor your game server (by P3D's tools)", 350, 360)

; $file = GUICtrlCreateMenu("File")
; $esci = GUICtrlCreateMenuItem("Esci", $file)
; $informazioni = GUICtrlCreateMenu("Informazioni")
; $verifica_aggiornamenti = GUICtrlCreateMenuItem("Verifica aggiornamenti", $informazioni)
; $informazioni_sul_programma = GUICtrlCreateMenuItem("Informazioni sul programma", $informazioni)

$tab = GUICtrlCreateTab(15, 104, 320, 235)
GUICtrlCreateTabItem("Numero di giocatori")
GUICtrlCreateLabel("Grafico che rappresenta il numero dei giocatori durante la giornata di oggi.", 45, 130, 260, 35, $SS_CENTER)
$pic_giocatori = GUICtrlCreatePic("", 45, 160, 260, 170)
GUICtrlCreateTabItem("Mappe preferite")
GUICtrlCreateLabel("Grafico che rappresenta la percentuale con cui ciascuna mappa si presenta sul totale.", 45, 130, 260, 35, $SS_CENTER)
$pic_mappe = GUICtrlCreatePic("", 45, 160, 260, 170)
GUICtrlCreateTabItem("Posizione in classifica")
GUICtrlCreateLabel("Grafico che rappresenta la posizione in classifica attuale del server di gioco.", 45, 130, 260, 35, $SS_CENTER)
$pic_classifica = GUICtrlCreatePic("", 45, 160, 260, 170)

GUISetState(@SW_SHOW)

; acquisizione dei grafici;
$link = InetRead("http://magmaliveteatro.files.wordpress.com/2007/12/prova-a-chiedermi-un-favore.jpg")
_SetImageBinaryToCtrl($pic_giocatori, $link)
$link = InetRead("http://magmaliveteatro.files.wordpress.com/2007/12/prova-a-chiedermi-un-favore.jpg")
_SetImageBinaryToCtrl($pic_mappe, $link)
$link = InetRead("http://magmaliveteatro.files.wordpress.com/2007/12/prova-a-chiedermi-un-favore.jpg")
_SetImageBinaryToCtrl($pic_classifica, $link)
; fine dell'acquisizione dei grafici;

; GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd





;Authors: Prog@ndy, based on code by Zedna
Func _SetImageBinaryToCtrl($CtrlId, ByRef $Binary)
    Local $picdata = Binary($Binary) ; Fetch the Data
    Local $piclength = BinaryLen($picdata) ; Get Length

    Local $picstruct = DllStructCreate("byte[" & $piclength & "]")
        DllStructSetData($picstruct,1,$picdata)
        Local $picmemory = DllStructGetPtr($picstruct)
        _SetMemoryImageToCtrl($CtrlId, $picmemory, $piclength)
        DllStructSetData($picstruct,1,0)
    $picstruct = ""
EndFunc

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
        ; use GDI+ for converting to bitmap first
    $hData = _MemGlobalAlloc($nSize,2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer,$pData,$nSize)
    _MemGlobalUnlock($hData)
    $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0)
    $pStream = $pStream[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    _SetBitmapToCtrl($CtrlId, $hBitmap)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc

; internal helper function
; Out of resources.au3 :)
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
        ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
        Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

this code doesn't work:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#include <INet.au3>
#include <BinaryImage.au3>

#Region ### START Koda GUI section ### Form=
$form_principale = GUICreate("Monitor your game server (by P3D's tools)", 350, 360)

$file = GUICtrlCreateMenu("File")
$esci = GUICtrlCreateMenuItem("Esci", $file)
$informazioni = GUICtrlCreateMenu("Informazioni")
$verifica_aggiornamenti = GUICtrlCreateMenuItem("Verifica aggiornamenti", $informazioni)
$informazioni_sul_programma = GUICtrlCreateMenuItem("Informazioni sul programma", $informazioni)

$tab = GUICtrlCreateTab(15, 104, 320, 235)
GUICtrlCreateTabItem("Numero di giocatori")
GUICtrlCreateLabel("Grafico che rappresenta il numero dei giocatori durante la giornata di oggi.", 45, 130, 260, 35, $SS_CENTER)
$pic_giocatori = GUICtrlCreatePic("", 45, 160, 260, 170)
GUICtrlCreateTabItem("Mappe preferite")
GUICtrlCreateLabel("Grafico che rappresenta la percentuale con cui ciascuna mappa si presenta sul totale.", 45, 130, 260, 35, $SS_CENTER)
$pic_mappe = GUICtrlCreatePic("", 45, 160, 260, 170)
GUICtrlCreateTabItem("Posizione in classifica")
GUICtrlCreateLabel("Grafico che rappresenta la posizione in classifica attuale del server di gioco.", 45, 130, 260, 35, $SS_CENTER)
$pic_classifica = GUICtrlCreatePic("", 45, 160, 260, 170)

GUISetState(@SW_SHOW)

; acquisizione dei grafici;
$link = InetRead("http://magmaliveteatro.files.wordpress.com/2007/12/prova-a-chiedermi-un-favore.jpg")
_SetImageBinaryToCtrl($pic_giocatori, $link)
$link = InetRead("http://magmaliveteatro.files.wordpress.com/2007/12/prova-a-chiedermi-un-favore.jpg")
_SetImageBinaryToCtrl($pic_mappe, $link)
$link = InetRead("http://magmaliveteatro.files.wordpress.com/2007/12/prova-a-chiedermi-un-favore.jpg")
_SetImageBinaryToCtrl($pic_classifica, $link)
; fine dell'acquisizione dei grafici;

; GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd





;Authors: Prog@ndy, based on code by Zedna
Func _SetImageBinaryToCtrl($CtrlId, ByRef $Binary)
    Local $picdata = Binary($Binary) ; Fetch the Data
    Local $piclength = BinaryLen($picdata) ; Get Length

    Local $picstruct = DllStructCreate("byte[" & $piclength & "]")
        DllStructSetData($picstruct,1,$picdata)
        Local $picmemory = DllStructGetPtr($picstruct)
        _SetMemoryImageToCtrl($CtrlId, $picmemory, $piclength)
        DllStructSetData($picstruct,1,0)
    $picstruct = ""
EndFunc

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
        ; use GDI+ for converting to bitmap first
    $hData = _MemGlobalAlloc($nSize,2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer,$pData,$nSize)
    _MemGlobalUnlock($hData)
    $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0)
    $pStream = $pStream[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    _SetBitmapToCtrl($CtrlId, $hBitmap)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc

; internal helper function
; Out of resources.au3 :)
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
        ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
        Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

ehi ehi ehi, what is your name?

Share this post


Link to post
Share on other sites



From the help file: Don't forget to close your tabitem creation with GUICtrlCreateTabItem(""). Just add this statement before GUISetState().

Share this post


Link to post
Share on other sites

OKay, you are right!

thank you. :)


ehi ehi ehi, what is your name?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0