Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
_GDIPlus_Startup()
$gpsind0 = _GDIPlus_ImageLoadFromFile("file.png")
$hHBMP0 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($gpsind0)
$hHBMP1 = _hBitmap_Resize($hHBMP0, 90, 60)
$Form1 = GUICreate("A problem to solve", 150, 150)
$btn0 = GUICtrlCreateButton('Button', 10, 10, 90, 60, 0x0080) ; $BS_BITMAP = 0x0080
$btn1 = GUICtrlCreateButton('Button', 10, 80, 90, 60, 0x0080) ; $BS_BITMAP = 0x0080
GUISetState(@SW_SHOW)
_WinAPI_DeleteObject(GUICtrlSendMsg($btn0, 0xF7, 0x00, $hHBMP0)) ; $BM_SETIMAGE = 0xF7 ; $IMAGE_BITMAP = 0x00
_WinAPI_DeleteObject(GUICtrlSendMsg($btn1, 0xF7, 0x00, $hHBMP1)) ; $BM_SETIMAGE = 0xF7 ; $IMAGE_BITMAP = 0x00
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($hHBMP1)
_WinAPI_DeleteObject($hHBMP0)
_GDIPlus_ImageDispose($gpsind0)
_GDIPlus_Shutdown()
GUIDelete()
Exit
Case $btn0
MsgBox(64, '', 'you clicked a button 0')
Case $btn1
MsgBox(64, '', 'you clicked a button 1')
EndSwitch
WEnd
Func _hBitmap_GetSize($hBitmap)
Local $tObj = DllStructCreate('long Type;long Width;long Height;long WidthBytes;ushort Planes;ushort BitsPixel;ptr Bits')
Local $Ret = DllCall('gdi32.dll', 'int', 'GetObject', 'int', $hBitmap, 'int', DllStructGetSize($tObj), 'ptr', DllStructGetPtr($tObj))
If (@error) Or ($Ret[0] = 0) Then
Return 0
EndIf
Local $Size[2] = [DllStructGetData($tObj, 'Width'), DllStructGetData($tObj, 'Height')]
If ($Size[0] = 0) Or ($Size[1] = 0) Then
Return 0
EndIf
Return $Size
EndFunc ;==>_Icons_Bitmap_GetSize
Func _hBitmap_Resize($hBitmap, $iWidth, $iHeight)
Local $Size = _hBitmap_GetSize($hBitmap)
If $Size = 0 Then
Return 0
EndIf
Local $Ret, $hDC, $hDestDC, $SrcDC, $hBmp
$hDC = _WinAPI_GetDC(0)
$hDestDC = _WinAPI_CreateCompatibleDC($hDC)
$hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
_WinAPI_SelectObject($hDestDC, $hBmp)
$hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
_WinAPI_SelectObject($hSrcDC, $hBitmap)
_WinAPI_ReleaseDC(0, $hDC)
DllCall('gdi32.dll', 'int', 'SetStretchBltMode', 'hwnd', $hDestDC, 'int', 4)
$Ret = DllCall('gdi32.dll', 'int', 'StretchBlt', 'hwnd', $hDestDC, 'int', 0, 'int', 0, 'int', $iWidth, 'int', $iHeight, 'hwnd', $hSrcDC, 'int', 0, 'int', 0, 'int', $Size[0], 'int', $Size[1], 'dword', $SRCCOPY)
If (@error) Or ($Ret[0] = 0) Then
_WinAPI_DeleteObject($hBmp)
$hBmp = 0
EndIf
_WinAPI_DeleteDC($hDestDC)
_WinAPI_DeleteDC($hSrcDC)
Return $hBmp
EndFunc ;==>_Icons_Bitmap_Resize