Code : Tout sélectionner
#include <Memory.au3>
#include <GDIPlus.au3>
_GDIPlus_Startup()
Global Const $idInput_toto_Color = 0x002000
Global Const $hBitmap = Load_BMP_From_Mem(Texture(), True)
Global $aR = DllCall("Gdi32.dll", "Handle", "CreatePatternBrush", "Handle", $hBitmap) ;create background image of input box!
Global $hBrush = $aR[0]
GUICreate("MyGUI")
$tbtoto = GUICtrlCreateEdit("", 10, 10, 250, 20)
$hInput_toto = GUICtrlGetHandle($tbtoto)
GUIRegisterMsg(0x0133, "WM_CTLCOLOREDIT") ;$WM_CTLCOLOREDIT = 0x0133
GUISetState()
While 1
If GUIGetMsg() = -3 Then ExitLoop
WEnd
_GDIPlus_Shutdown()
Func Texture()
Local $Texture
$Texture &= 'iVBORw0KGgoAAAANSUhEUgAAABYAAAAWAQMAAAD+ev54AAAABlBMVEX58vL8/vwLi9S/AAAAHUlEQVR4Xo3DQREAAAABwWuifytBzFDBY6m5obwGWsMgvzLU9ywAAAAASUVORK5CYII='
Return Binary(_Base64Decode($Texture))
EndFunc ;==>Texture
Func WM_CTLCOLOREDIT($hGUI, $Msg, $wParam, $lParam)
#forceref $hGUI, $Msg
If $lParam = $hInput_toto Then
DllCall("Gdi32.dll", "uint", "SetTextColor", "handle", $wParam, "uint", $idInput_toto_Color)
DllCall("Gdi32.dll", "int", "SetBkMode", "handle", $wParam, "int", 1)
Return $hBrush
EndIf
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_CTLCOLOREDIT
Func _Base64Decode($input_string)
Local $struct = DllStructCreate("int")
Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
If @error Or Not $a_Call[0] Then Return SetError(1, 0, "")
Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")
$a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
If @error Or Not $a_Call[0] Then Return SetError(2, 0, "")
Return DllStructGetData($a, 1)
EndFunc ;==>_Base64Decode
;======================================================================================
; 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
; Don't forget _GDIPlus_Startup() and _GDIPlus_Shutdown()
;
; Requirement(s): GDIPlus.au3, Memory.au3 and _WinAPI_BitmapCreateDIBFromBitmap() from WinAPIEx.au3
; Return Value(s): Success: handle to bitmap (GDI+ bitmap format) or hbitmap (WinAPI bitmap format),
; 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 and
; Yashied for _WinAPI_BitmapCreateDIBFromBitmap() from WinAPIEx.au3
; Version: v0.98 Build 2012-08-29 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 Return 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 Return 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 = _WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
_GDIPlus_BitmapDispose($hBitmap)
Return $hHBmp
EndIf
Return $hBitmap
EndFunc ;==>Load_BMP_From_Mem
Func _WinAPI_BitmapCreateDIBFromBitmap($hBitmap) ;create 32-bit bitmap v5 (alpha channel supported)
Local $tBIHDR, $aRet, $tData, $pBits, $hResult = 0
$aRet = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
If (@error) Or ($aRet[0]) Then Return 0
$tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aRet[2], $aRet[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
$pBits = DllStructGetData($tData, 'Scan0')
If Not $pBits Then Return 0
$tBIHDR = DllStructCreate( 'dword bV5Size;long bV5Width;long bV5Height;word bV5Planes;word bV5BitCount;dword bV5Compression;' & _ ;http://msdn.microsoft.com/en-us/library/windows/desktop/dd183381(v=vs.85).aspx
'dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;' & _
'dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;' & _
'int bV5Endpoints[3];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;' & _
'dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved')
DllStructSetData($tBIHDR, 'bV5Size', DllStructGetSize($tBIHDR))
DllStructSetData($tBIHDR, 'bV5Width', $aRet[2])
DllStructSetData($tBIHDR, 'bV5Height', $aRet[3])
DllStructSetData($tBIHDR, 'bV5Planes', 1)
DllStructSetData($tBIHDR, 'bV5BitCount', 32)
DllStructSetData($tBIHDR, 'bV5Compression', 0) ; $BI_BITFIELDS = 3, $BI_RGB = 0, $BI_RLE8 = 1, $BI_RLE4 = 2, $RGBA = 0x41424752
DllStructSetData($tBIHDR, 'bV5SizeImage', $aRet[3] * DllStructGetData($tData, 'Stride'))
DllStructSetData($tBIHDR, 'bV5AlphaMask', 0xFF000000)
DllStructSetData($tBIHDR, 'bV5RedMask', 0x00FF0000)
DllStructSetData($tBIHDR, 'bV5GreenMask', 0x0000FF00)
DllStructSetData($tBIHDR, 'bV5BlueMask', 0x000000FF)
DllStructSetData($tBIHDR, 'bV5CSType', 2) ; LCS_WINDOWS_COLOR_SPACE = 2
DllStructSetData($tBIHDR, 'bV5Intent', 4) ; $LCS_GM_IMA
$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', $aRet[2] * $aRet[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
$hResult = $hResult[0]
Else
$hResult = 0
EndIf
_GDIPlus_BitmapUnlockBits($hBitmap, $tData)
$tData = 0
$tBIHDR = 0
Return $hResult
EndFunc ;==>_WinAPI_BitmapCreateDIBFromBitmap