bub Posted March 19, 2011 Share Posted March 19, 2011 I need buttons dynamic with two images PNG that change with the arrival of the mouse. I did, this is my code. but I have a problem. expandcollapse popup#include <GDIPlus.au3> Dim $STM_SETIMAGE = 0x0172 Dim $Image_OneButton = @ScriptDir&"\Button1.png" Dim $Image_TwoButton = @ScriptDir&"\Button2.png" _GDIPlus_Startup() ;~ insert Image 1 $hImage_One = _GDIPlus_ImageLoadFromFile($Image_OneButton) $iW_One = _GDIPlus_ImageGetWidth($hImage_One) $iH_One = _GDIPlus_ImageGetHeight($hImage_One) $hBitmap_One = _GDIPlus_BitmapCloneArea($hImage_One, 0, 0, $iW_One, $iH_One, $GDIP_PXF32ARGB) $hBmp_One = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_One) _GDIPlus_BitmapDispose($hBitmap_One) _GDIPlus_ImageDispose($hImage_One) ;~ insert image 2 $hImage_Two = _GDIPlus_ImageLoadFromFile($Image_TwoButton) $iW_Two = _GDIPlus_ImageGetWidth($hImage_Two) $iH_Two = _GDIPlus_ImageGetHeight($hImage_Two) $hBitmap_Two = _GDIPlus_BitmapCloneArea($hImage_Two, 0, 0, $iW_Two, $iH_Two, $GDIP_PXF32ARGB) $hBmp_Two = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Two) _GDIPlus_BitmapDispose($hBitmap_Two) _GDIPlus_ImageDispose($hImage_Two) _GDIPlus_Shutdown() GUICreate("My button") ;Create Gui GUISetBkColor(0xFFFFFF) ;Gui color white $Button = GUICtrlCreatePic("" ,0 , 0, $iW_One, $iH_One) ;Create the Pic GUICtrlSendMsg($Button, $STM_SETIMAGE, 0, $hBmp_One) ; Insert PNG GUISetState() Dim $GO = False while 1 $ReadMouse = GUIGetCursorInfo() ; Pos mouse If IsArray($ReadMouse) = 1 Then Select case $ReadMouse[4] = $Button and $GO = False GUICtrlSendMsg($Button, $STM_SETIMAGE, 0, "") ;Restart image GUICtrlSendMsg($Button, $STM_SETIMAGE, 0, $hBmp_Two) ;replace image $GO = True case $ReadMouse[4] <> $Button and $GO = True GUICtrlSendMsg($Button, $STM_SETIMAGE, 0, "") ;Restart image GUICtrlSendMsg($Button, $STM_SETIMAGE, 0, $hBmp_One) ;replace image $GO = False EndSelect EndIf Switch GUIGetMsg() case -3 ; $GUI_EVENT_CLOSE exit EndSwitch WEnd If I replace PNGs images with the function GUICtrlSendMsg, I use two functions and to send a blank picture to restart, otherwise the images overlap. it works! But in the interval between functions the image does not change immediately and leaves a bad flash. This does not happen with guictrlsetimage! but the function guictrlsetimage does not support PNG!! You can implement the PNG format in the guictrlsetimage function? excuse my English, I'm Italian Link to comment Share on other sites More sharing options...
ChrisL Posted March 19, 2011 Share Posted March 19, 2011 (edited) Not sure who wrote the SetBitmap() function so I can't credit them but it wasn't me. Edit: Sorry I missunderstood, you wanted an onHover type event. Code edited. expandcollapse popup#include <GDIPlus.au3> #include <GuiConstantsex.au3> #include <WindowsConstants.au3> Dim $Image_OneButton = @ScriptDir&"\Button1.png" Dim $Image_TwoButton = @ScriptDir&"\Button2.png" _GDIPlus_Startup() $hWNDMain = GUICreate("My button") ;Create Gui GUISetBkColor(0xFFFFFF) ;Gui color white GUISetState(@SW_SHOW,$hWNDMain) $Button = _GuiCtrlCreatePNG($Image_OneButton,0 , 0, $hWNDMain) $CurrentImage = $Image_OneButton Dim $GO = False while 1 Switch GUIGetMsg() Case $Button[1] Msgbox(0,"","Button Clicked") case -3 ; $GUI_EVENT_CLOSE exit _GDIPlus_Shutdown() Case Else $aMouse = GUIGetCursorInfo() If NOT IsArray($aMouse) then ContinueCase If $aMouse[4] = $Button[1] and $CurrentImage <> $Image_TwoButton then $CurrentImage = _SetGraphicToControl($Button[0],$Image_TwoButton) ElseIf $aMouse[4] <> $Button[1] and $CurrentImage <> $Image_OneButton Then $CurrentImage = _SetGraphicToControl($Button[0],$Image_OneButton) EndIf EndSwitch WEnd Func _SetGraphicToControl($hControl,$sImage) Local $hImage If NOT FileExists($sImage) then Return 0 $hImage = _GDIPlus_ImageLoadFromFile($sImage) SetBitmap($hControl,$hImage) _GDIPlus_ImageDispose($hImage) Return $sImage EndFunc Func _GuiCtrlCreatePNG($sImage,$iPosX, $iPosY, $hMainGUI) Local $hImage, $iw,$iH, $ret[2] $hImage = _GDIPlus_ImageLoadFromFile($sImage) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) $Ret[0] = GUICreate("", $iW,$iH, $iPosX, $iPosY,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$hMainGUI) $Ret[1] = GUICtrlCreateLabel("",0,0,$iW,$iH) SetBitmap($Ret[0],$hImage) GUISetState(@SW_SHOW,$Ret[0]) _GDIPlus_ImageDispose($hImage) Return $Ret EndFunc Func SetBitmap($hGUI, $hImage, $iOpacity = 255) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage)) DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage)) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>SetBitmap Edited March 19, 2011 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
AutoBert Posted March 19, 2011 Share Posted March 19, 2011 Hi bub,@Grossvater has a UDF named GuiCtrlPic.au3 on AutoIt.de. After download you can test this little Demo: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include "GUICtrlPic.au3" $bFirst = True $Pic1 = @ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png" $Form1 = GUICreate("Form1", 400, 300) GUICtrlCreatePic(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png", 0, 0, 400, 300) GuiCtrlSetState(-1,$GUI_DISABLE) $a8 = _GUICtrlPic_Create($Pic1 , 30, 30, 72, 72, BitOR($SS_CENTERIMAGE,$SS_SUNKEN, $SS_NOTIFY), Default) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() if $nMsg <> 0 Then ConsoleWrite($nMsg & @crlf) switch $nMsg case $GUI_EVENT_CLOSE Exit Case $a8 if $bFirst Then _GUICtrlPic_SetImage($a8, @ProgramFilesDir & "\AutoIt3\Examples\GUI\Merlin.gif", 1) Else _GUICtrlPic_SetImage($a8, @ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png", 1) EndIf $bFirst = not $bFirst EndSwitch WEndmfg autoBert Link to comment Share on other sites More sharing options...
bub Posted March 22, 2011 Author Share Posted March 22, 2011 Thanks much! Thanks much! Thanks much! Thanks much! Thanks much! @ChrisL: Use the GUI to create the buttons was a crazy idea! xD but very interesting xD I've done a lot of experience! thank you! @AutoBert: Thank you! you gave me what I was looking for, this UDF supersedes images quickly without leaving a bad flash!! This my final script: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include "GUICtrlPic.au3" $bFirst = True $Pic1 = @ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png" $Form1 = GUICreate("Form1", 400, 300) GUICtrlCreatePic(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png", 0, 0, 400, 300) GuiCtrlSetState(-1,$GUI_DISABLE) $a8 = _GUICtrlPic_Create($Pic1 , 30, 30, 72, 72) GUISetState(@SW_SHOW) Dim $GO = False while 1 $ReadMouse = GUIGetCursorInfo() ; Pos mouse If IsArray($ReadMouse) = 1 Then Select case $ReadMouse[4] = $a8 and $GO = False _GUICtrlPic_SetImage($a8, @ProgramFilesDir & "\AutoIt3\Examples\GUI\Merlin.gif", 0) $GO = True case $ReadMouse[4] <> $a8 and $GO = True _GUICtrlPic_SetImage($a8, @ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png", 0) $GO = False EndSelect EndIf Switch GUIGetMsg() case -3 ; $GUI_EVENT_CLOSE exit case $a8 _GUICtrlPic_SetImage($a8, @ProgramFilesDir & "\AutoIt3\Examples\GUI\msoobe.jpg", 0) MsgBox(0,"","Pressed") _GUICtrlPic_SetImage($a8, @ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png", 0) EndSwitch WEnd Link to comment Share on other sites More sharing options...
Djordhan Posted April 8, 2011 Share Posted April 8, 2011 (edited) In fact I`m noticing a flash sometimes when changing image (I set my images to switch on mouse over). It may be due to the fact that the function reloads the image each time, before displaying it. I`ll add an arg to the _GUICtrlPic_SetImage function to accept a list of already loaded image. I`ll post it here afterwhile if it solves my flickering problem. EDIT: Well, it doesn`t... Edited April 8, 2011 by Djordhan Link to comment Share on other sites More sharing options...
4Eyes Posted April 26, 2011 Share Posted April 26, 2011 I used Google Translate to render the original GuiCtrlPic() more readable. Here 'tis: expandcollapse popup; Original from here: http://www.autoit.de/index.php?page=Thread&threadID=24514 ; Description text etc translated to English via GoogleTranslate (better than nothing!) by 4Eyes - 26/Apr/2011 ; #INDEX# ======================================================================================================================= ; Title .........: GUICtrlPic ; AutoIt Version : 3.3.6.1 ; Description ...: Ergänzende Funktionen für Pic-Controls (Additional functions for Pic-Controls) ; Author(s) .....: Großvater ; Dll ...........: GDI32.dll, GDIPlus.dll ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _GUICtrlPic_Create ; _GUICtrlPic_SetImage ; _GUICtrlPic_LoadImage ; _GUICtrlPic_ScaleBitmap ; _GUICtrlPic_GradientFill ; _GUICtrlPic_Invert ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlPic_Create ; Description ...: Pic-Control für alle von GDIPlus unterstützten Formate ggf. mit Transparenz erstellen. ; Syntax.........: _GUICtrlPic_Create($sPicPath, $iLeft, $iTop[, $iWidth = 0[, $iHeight = 0[, $uStyles = -1[, $uExStyles = -1[, $bKeepAspectRatio = False]]]]]) ; Parameters ....: Die Parameter entsprechen bis auf den letzten der AU3-Funktion GUICtrlCreatePic() ; $bKeepAspectRatio - Seitenverhältnis bei der Größenanpassung beachten: ; |True - ja ; |False - nein ; |Default - nein ; Return values .: Im Erfolgsfall: ControlID aus GUICtrlCreatePic() ; Im Fehlerfall: False, @error und @extended enthalten ergänzende fehlerbeschreibende Werte. ; Name...........: _GUICtrlPic_Create ; Description.....: Pic-control necessary for all supported formats GDIPlus create transparency. ; Syntax .........: _GUICtrlPic_Create ($ sPicPath, $ iLeft, $ iTop [, $ iWidth = 0 [, $ iHeight = 0 [, $ Ustyle = -1 [, $ uExStyles = -1 [, $ bKeepAspectRatio = False ]]]]]) ; Parameters .....: The parameters correspond to the last of the AU3 GUICtrlCreatePic function () ; $bKeepAspectRatio - note the aspect ratio sizing: ; | True - yes ; | False - no ; | Default - No ; Return values...: If successful: ControlID from GUICtrlCreatePic (). ; an error occurs: False, @ @ error and extended contain additional descriptive error values??. ; Author ........: Großvater (www.autoit.de) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GUICtrlPic_Create($sPicPath, $iLeft, $iTop, $iWidth = 0, $iHeight = 0, $uStyles = -1, $uExStyles = -1, $bKeepAspectRatio = False) Local Const $IMAGE_BITMAP = 0x0000 Local Const $STM_SETIMAGE = 0x0172 Local $aResult, $hBitmap, $hImage, $Height, $Width, $CtrlID Local $aBitmap = _GUICtrlPic_LoadImage($sPicPath) If @error Then Return SetError(@error, @extended, False) $hBitmap = $aBitmap[0] $Width = $aBitmap[1] $Height = $aBitmap[2] If $iWidth = 0 And $iHeight = 0 Then $iWidth = $Width $iHeight = $Height Else $hBitmap = _GUICtrlPic_ScaleBitmap($hBitmap, $iWidth, $iHeight, $Width, $Height, $bKeepAspectRatio) If @error Then Return SetError(@error, @extended, False) EndIf $CtrlID = GUICtrlCreatePic("", $iLeft, $iTop, $iWidth, $iHeight, $uStyles, $uExStyles) GUICtrlSendMsg($CtrlID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) DllCall("Gdi32.dll", "BOOL", "DeleteObject", "Handle", $hBitmap) Return $CtrlID EndFunc ;==>_GUICtrlPic_Create ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlPic_SetImage ; Description ...: Neues Bild in Pic-Control erstellen. - New image in Pic-Control Create ; Syntax.........: _GUICtrlPic_SetImage($idPic, $sPicPath[, $bKeepAspectRatio = False]) ; Parameters ....: $idPic - ID des PIC-Controls ; $sPicPath - vollständiger Pfad der Bilddatei ; $bKeepAspectRatio - Seitenverhältnis bei der Größenanpassung beachten: (Aspect ratio in mind when sizing) ; |True - ja ; |False - nein ; |Default - nein ; Return values .: Im Erfolgsfall: True (If successful) ; Im Fehlerfall: False, @error und @extended enthalten ggf. ergänzende fehlerbeschreibende Werte ; Name ...........: _GUICtrlPic_SetImage ; Description ...: Create new image in Pic-Control. - New image in Pic-Control Create ; Syntax .........: _GUICtrlPic_SetImage ($ idPic, $ sPicPath [, $ bKeepAspectRatio = False]) ; Parameters ....: $ idPic - ID of the PIC Controls ; $ sPicPath - full path to the image file ; $ bKeepAspectRatio - aspect ratio in mind when sizing (aspect ratio in mind when sizing) ; | True - yes ; | False - no ; | Default - No ; Return values: If successful: True (If successful). ; an error occurs: False, @error and @extended may contain additional descriptive error values ; Author ........: Großvater (www.autoit.de) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GUICtrlPic_SetImage($idPic, $sPicPath, $bKeepAspectRatio = False) Local Const $IMAGE_BITMAP = 0x0000 Local Const $STM_SETIMAGE = 0x0172 Local Const $STM_GETIMAGE = 0x0173 Local $aSize, $hBM, $hBitmap, $Height, $Width Local $aBitmap = _GUICtrlPic_LoadImage($sPicPath) If @error Or $aBitmap[0] = 0 Then Return SetError(@error, @extended, False) $hBitmap = $aBitmap[0] $Width = $aBitmap[1] $Height = $aBitmap[2] $aSize = WinGetClientSize(GUICtrlGetHandle($idPic)) $hBitmap = _GUICtrlPic_ScaleBitmap($hBitmap, $aSize[0], $aSize[1], $Width, $Height, $bKeepAspectRatio) $hBM = GUICtrlSendMsg($idPic, $STM_GETIMAGE, $IMAGE_BITMAP, 0) If $hBM Then DllCall("Gdi32.dll", "BOOL", "DeleteObject", "Handle", $hBM) GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) DllCall("Gdi32.dll", "BOOL", "DeleteObject", "Handle", $hBitmap) GUICtrlSetState($idPic, $GUI_SHOW) Return True EndFunc ;==>_GUICtrlPic_SetImage ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlPic_LoadImage ; Description ...: Bilddatei laden und HBITMAP erzeugen ; Syntax.........: _GUICtrlPic_LoadImage($sPicPath) ; Parameters ....: $sPicPath - vollständiger Pfad der Bilddatei ; Return values .: Im Erfolgsfall: Array mit drei Einträgen, Array[0] enthält ein HBITMAP-Handle, ; Array[1] die Breite und Array[2] die Höhe der Bitmap ; Im Fehlerfall: False, @error und @extended enthalten ggf. ergänzende fehlerbeschreibende Werte ; Author ........: Großvater (www.autoit.de) ; Modified.......: ; Remarks .......: Die Funktion kann auch einzeln genutzt werden, um eine Bitmap zu laden und dann per ; GUICtrlSendMsg($idPIC, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) einem Pic-Control zuzuweisen. ; Name...........: _GUICtrlPic_LoadImage ; Description: Image file upload and create HBITMAP ; Syntax ........: _GUICtrlPic_LoadImage ($ sPicPath) ; Parameters ....: $ sPicPath - full path to the image file ; Return values..: If successful: array with three entries, array [0] contains an HBITMAP handle. ; Array [1] the width and array [2], the height of the bitmap ; an error occurs: False, @error and @extended may contain additional descriptive error values ; Author ........: grandfather (www.autoit.de) ; Modified .......: ; Remarks .......: This function can be used separately to load a bitmap and then by ; GUICtrlSendMsg assign ($ idPIC, $ STM_SETIMAGE, $ IMAGE_BITMAP, $ hBitmap) a Pic-Control. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GUICtrlPic_LoadImage($sPicPath) Local $aResult, $hBitmap, $hImage, $Height, $Width Local $aBitmap[3] = [0, 0, 0] Local $hGDIPDll = DllOpen("GDIPlus.dll") If $hGDIPDll = -1 Then Return SetError(1, 2, $aBitmap) Local $tInput = DllStructCreate("UINT Version;ptr Callback;BOOL NoThread;BOOL NoCodecs") Local $pInput = DllStructGetPtr($tInput) Local $tToken = DllStructCreate("ULONG_PTR Data") Local $pToken = DllStructGetPtr($tToken) DllStructSetData($tInput, "Version", 1) $aResult = DllCall($hGDIPDll, "INT", "GdiplusStartup", "Ptr", $pToken, "Ptr", $pInput, "Ptr", 0) If @error Then Return SetError(@error, @extended, $aBitmap) $aResult = DllCall($hGDIPDll, "INT", "GdipLoadImageFromFile", "WStr", $sPicPath, "Ptr*", 0) If @error Or $aResult[2] = 0 Then Local $Error = @error, $Extended = @extended DllCall($hGDIPDll, "None", "GdiplusShutdown", "Ptr", DllStructGetData($tToken, "Data")) DllClose($hGDIPDll) Return SetError($Error, $Extended, $aBitmap) EndIf $hImage = $aResult[2] $aResult = DllCall($hGDIPDll, "INT", "GdipGetImageWidth", "Handle", $hImage, "UINT*", 0) $Width = $aResult[2] $aResult = DllCall($hGDIPDll, "INT", "GdipGetImageHeight", "Handle", $hImage, "UINT*", 0) $Height = $aResult[2] $aResult = DllCall($hGDIPDll, "INT", "GdipCreateHBITMAPFromBitmap", "Handle", $hImage, "Ptr*", 0, "DWORD", 0xFF000000) $hBitmap = $aResult[2] DllCall($hGDIPDll, "INT", "GdipDisposeImage", "Handle", $hImage) DllCall($hGDIPDll, "None", "GdiplusShutdown", "Ptr", DllStructGetData($tToken, "Data")) DllClose($hGDIPDll) $aBitmap[0] = $hBitmap $aBitmap[1] = $Width $aBitmap[2] = $Height Return $aBitmap EndFunc ;==>_GUICtrlPic_LoadImage ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlPic_ScaleBitmap ; Description ...: Geladene Bitmap skalieren. ; Syntax.........: _GUICtrlPic_ScaleBitmap($hBitmap, $iNewW, $iNewH[, $iBitmapW[, $iBitmapH[, $bKeepAspectRatio = False]]]) ; Parameters ....: $hBitmap - HBITMAP-Handle ; $iNewW - gewünschte Breite in Pixeln ; $iNewH - gewünschte Höhe in Pixeln ; $iBitmapW - aktuelle Breite der Bitmap (wird nur für das Skalieren im Seitenverhältnis benötigt ; $iBitmapH - aktuelle Höhe der Bitmap (wird nur für das Skalieren im Seitenverhältnis benötigt ; $bKeepAspectRatio - Seitenverhältnis bei der Größenanpassung beachten: ; |True - ja ; |False - nein ; |Default - nein ; Return values .: Im Erfolgsfall: HBITMAP-Handle für die skalierte Bitmap ; Im Fehlerfall: False, @error und @extended enthalten ggf. ergänzende fehlerbeschreibende Werte ; Author ........: Großvater (www.autoit.de) ; Modified.......: ; Remarks .......: Die Funktion kann auch einzeln genutzt werden, um eine Bitmap zu skalieren und dann per ; GUICtrlSendMsg($idPIC, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) einem Pic-Control zuzuweisen. ; Name...........: _GUICtrlPic_ScaleBitmap ; Description....: Loaded scale bitmap. ; Syntax ........: _GUICtrlPic_ScaleBitmap ($ hBitmap, $ iNewW, $ iNewH [, $ iBitmapW [, $ iBitmapH [, $ bKeepAspectRatio = False]]]) ; Parameters ....: $ hBitmap - Handle HBITMAP ; $iNewW - desired width in pixels ; $iNewH - desired height in pixels ; $iBitmapW - current width of the bitmap (only needed for scaling the aspect ratio ; $iBitmapH - current height of the bitmap (only needed for scaling the aspect ratio ; $bKeepAspectRatio - note the aspect ratio sizing: ; | True - yes ; | False - no ; | Default - No ; Return values..: If successful: HBITMAP handle for the scaled bitmap. ; an error occurs: False, @error and @extended may contain additional descriptive error values ; Author ........: grandfather (www.autoit.de) ; Modified .......: ; Remarks .......: This function can be used separately to scale a bitmap and then by ; GUICtrlSendMsg assign ($ idPIC, $ STM_SETIMAGE, $ IMAGE_BITMAP, $ hBitmap) a Pic-Control. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GUICtrlPic_ScaleBitmap($hBitmap, $iNewW, $iNewH, $iBitmapW, $iBitmapH, $bKeepAspectRatio = False) Local Const $IMAGE_BITMAP = 0x0000 If $bKeepAspectRatio Then If $iBitmapW >= $iBitmapH Then $iBitmapH *= $iNewW / $iBitmapW $iBitmapW = $iNewW If $iBitmapH > $iNewH Then $iBitmapW *= $iNewH / $iBitmapH $iBitmapH = $iNewH EndIf Else $iBitmapW *= $iNewH / $iBitmapH $iBitmapH = $iNewH If $iBitmapW > $iNewW Then $iBitmapH *= $iNewW / $iBitmapW $iBitmapW = $iNewW EndIf EndIf Else $iBitmapW = $iNewW $iBitmapH = $iNewH EndIf Local $aResult = DllCall("User32.dll", "Handle", "CopyImage", _ "Handle", $hBitmap, "UINT", $IMAGE_BITMAP, "INT", $iBitmapW, "INT", $iBitmapH, "UINT", 0x4 + 0x8) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc ;==>_GUICtrlPic_ScaleBitmap ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlPic_GradientFill ; Description ...: Füllt ein Pic-Control mit einem zweifarbigen linearen Farbverlauf. ; Syntax.........: _GUICtrlPic_GradientFill($idCTRL, $C1, $C2[, $D = 1[, $3D = 3[, $GC = 0[, $BW = 0[, $BH = 0]]]]]) ; Parameters ....: $idCTRL - ID des Pic-Controls aus GUIStrlCreatePic() ; $C1 - Startfarbe als 6-stelliger RGB-Hexstring ("RRGGBB") ; $C2 - Zielfarbe als 6-stelliger RGB-Hexstring ("RRGGBB") ; $D - Verlaufsrichtung: ; |0 - horizontal ; |1 - vertikal ; |2 - diagonal (links oben -> rechts unten) ; |3 - diagonal (rechts oben -> links unten) ; |Default - 0 ; $3D - Verlaufsart: ; |1 - flacher Verlauf (Startfarbe -> Zielfarbe) ; |2 - "3D"-Verlauf (Startfarbe -> Zielfarbe -> Startfarbe) ; |3 - erhaben (wie 2, die Startfarbe bleibt aber im Randbereich) ; |Default - 1 ; $GC - Gammakorrektur: ; |0 - ohne ; |1 - mit ; |Default - 0 ; $BW - Breite des Verlaufs in Pixeln ; |Default - 0 (Breite des Controls) ; $BH - Höhe des Verlaufs in Pixeln ; |Default - 0 (Höhe des Controls) ; Return values .: Bei erfolgreicher Ausführung: Handle der erzeugten Bitmap (HBITMAP) ; Im Fehlerfall: False, @error wird auf 1 gesetzt ; Author ........: Großvater (www.autoit.de) ; Modified.......: ; Remarks .......: Das Control muss mit GUICtrlCreatePic() erzeugt worden sein, sonst geschieht nichts. ; Die Parameter $BW und $BH laden zum Experimentieren ein. ; Name...........: _GUICtrlPic_GradientFill ; Description....: Fills a Pic-linear control with a two-color gradient. ; Syntax ........: _GUICtrlPic_GradientFill ($ idCTRL, $ C1, $ C2 [, $ D = 1 [, $ 3D = 3 [, $ GC = 0 [, $ BW = 0 [, $ BH = 0 ]]]]]) ; Parameters ....: $idCTRL - ID of the Pic-Controls from GUIStrlCreatePic () ; $C1 - starting color as a 6-digit RGB hex strings ("RRGGBB) ; $C2 - target color as a 6-digit RGB hex strings ("RRGGBB) ; $D - the direction: ; |0 - horizontal ; |1 - vertical ; |2 - diagonal (top left -> right) ; |3 - diagonal (top right -> left) ; |Default - 0 ; $3D - Gradient: ; |1 - flat course (Start Color -> target color) ; |2 - "3D" profile (Start Color -> Target Color -> Colour Start) ; |3 - sublime (such as 2, the starting color remains in the border area) ; |Default - 1 ; $GC - Gamma correction: ; |0 - without ; |1 - with ; |Default - 0 ; $BW - width in pixels of the course ; |Default - 0 (width of the control) ; $BH - Height in pixels of the course ; |Default - 0 (height of the control) ; Return values..: On success: Handle of the created bitmap (HBITMAP). ; an error occurs: False, @error is set to 1 ; Author ........: grandfather (www.autoit.de) ; Modified .......: ; Remarks .......: The control must GUICtrlCreatePic () have been produced, otherwise nothing happens. ; The parameters $ and $ BW BH invite you to experiment. ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GUICtrlPic_GradientFill($idCTRL, $C1, $C2, $D = 1, $3D = 3, $GC = 0, $BW = 0, $BH = 0) Local Static $STM_SETIMAGE = 0x172 Local Static $IMAGE_BITMAP = 0x0 Local Static $BITSPIXEL = 0xC Local $hWnd If IsHWnd($idCTRL) Then $hWnd = $idCTRL Else $hWnd = GUICtrlGetHandle($idCTRL) EndIf Local $aResult = DllCall("User32.dll", "Int", "GetClassName", "Hwnd", $hWnd, _ "Str", "", "Int", 256) If $aResult[2] <> "Static" Then Return False EndIf Local $GDIPDll = DllOpen("GDIPlus.dll") If $GDIPDll = -1 Then Return SetError(1, 0, False) EndIf Local $SI = DllStructCreate("UInt Version;Ptr Callback;Bool NoThread;Bool NoCodecs") Local $Token = DllStructCreate("ulong_ptr Data") DllStructSetData($SI, "Version", 1) $aResult = DllCall($GDIPDll, "Int", "GdiplusStartup", _ "Ptr", DllStructGetPtr($Token), "Ptr", DllStructGetPtr($SI), "Ptr", 0) If @error Then DllClose($GDIPDll) Return SetError(1, 0, False) EndIf Local $GDIPToken = DllStructGetData($Token, "Data") Local $RECT = DllStructCreate("Long; Long; Long Right;Long Bottom") DllCall("User32.dll", "Bool", "GetClientRect", "Hwnd", $hWnd, _ "Ptr", DllStructGetPtr($RECT)) Local $W = DllStructGetData($RECT, "Right") Local $H = DllStructGetData($RECT, "Bottom") Switch $D Case 0, 1, 2, 3 Case Else $D = 0 EndSwitch Switch $3D Case 1, 2, 3 Case Else $3D = 1 EndSwitch Switch $GC Case 0, 1 Case Else $GC = 0 EndSwitch If $BW = 0 Then $BW = $W If $BH = 0 Then $BH = $H Local $pBITMAP = DllStructCreate("Ptr") DllCall($GDIPDll, "Int", "GdipCreateBitmapFromScan0", _ "Int", $W, "Int", $H, "Int", 0, "Int", 0x26200A, "Ptr", 0, _ "Ptr", DllStructGetPtr($pBITMAP)) $pBITMAP = DllStructGetData($pBITMAP, 1) Local $pGRAPHICS = DllStructCreate("Ptr") DllCall($GDIPDll, "Int", "GdipGetImageGraphicsContext", _ "Ptr", $pBITMAP, "Ptr", DllStructGetPtr($pGRAPHICS)) $pGRAPHICS = DllStructGetData($pGRAPHICS, 1) DllCall($GDIPDll, "Int", "GdipSetSmoothingMode", "Ptr", $pGRAPHICS, "Int", 0) Local $RECTF = DllStructCreate("Float L;Float T;Float R;Float B") DllStructSetData($RECTF, "R", $BW) DllStructSetData($RECTF, "B", $BH) Local $Color1 = "0xFF" & $C1 Local $Color2 = "0xFF" & $C2 Local $pBRUSH = DllStructCreate("Ptr") DllCall($GDIPDll, "Int", "GdipCreateLineBrushFromRect", _ "Ptr", DllStructGetPtr($RECTF), "Int", $Color1, "Int", $Color2, _ "Int", $D, "Int", 0, "Ptr", DllStructGetPtr($pBRUSH)) $pBRUSH = DllStructGetData($pBRUSH, 1) DllCall($GDIPDll, "Int", "GdipSetLineGammaCorrection", "Ptr", $pBRUSH, _ "Int", $GC) Local $RELINT = DllStructCreate("Float[5]") Switch $3D Case 1 DllStructSetData($RELINT, 1, 0.00, 1) DllStructSetData($RELINT, 1, 0.25, 2) DllStructSetData($RELINT, 1, 0.50, 3) DllStructSetData($RELINT, 1, 0.75, 4) DllStructSetData($RELINT, 1, 1.00, 5) Case 2 DllStructSetData($RELINT, 1, 0.0, 1) DllStructSetData($RELINT, 1, 0.5, 2) DllStructSetData($RELINT, 1, 1.0, 3) DllStructSetData($RELINT, 1, 0.5, 4) DllStructSetData($RELINT, 1, 0.0, 5) Case Else DllStructSetData($RELINT, 1, 0.0, 1) DllStructSetData($RELINT, 1, 1.0, 2) DllStructSetData($RELINT, 1, 1.0, 3) DllStructSetData($RELINT, 1, 1.0, 4) DllStructSetData($RELINT, 1, 0.0, 5) EndSwitch Local $RELPOS = DllStructCreate("Float[5]") DllStructSetData($RELPOS, 1, 0.0, 1) If $3D <> 3 Then DllStructSetData($RELPOS, 1, 0.25, 2) Else DllStructSetData($RELPOS, 1, 0.15, 2) EndIf DllStructSetData($RELPOS, 1, 0.5, 3) If $3D <> 3 Then DllStructSetData($RELPOS, 1, 0.75, 4) Else DllStructSetData($RELPOS, 1, 0.85, 4) EndIf DllStructSetData($RELPOS, 1, 1.0, 5) DllCall($GDIPDll, "Int", "GdipSetLineBlend", _ "Ptr", $pBRUSH, "Ptr", DllStructGetPtr($RELINT), _ "Ptr", DllStructGetPtr($RELPOS), "Int", 5) DllCall($GDIPDll, "Int", "GdipFillRectangle", "Ptr", $pGRAPHICS, _ "Ptr", $pBRUSH, "Float", 0, "Float", 0, "Float", $W, "Float", $H) Local $hBitmap = DllStructCreate("Ptr") DllCall($GDIPDll, "Int", "GdipCreateHBITMAPFromBitmap", _ "Ptr", $pBITMAP, "Ptr", DllStructGetPtr($hBitmap), "Int", 0XFFFFFFFF) $hBitmap = DllStructGetData($hBitmap, 1) DllCall($GDIPDll, "Int", "GdipDeleteBrush", "Ptr", $pBRUSH) DllCall($GDIPDll, "Int", "GdipDisposeImage", "Ptr", $pBITMAP) DllCall($GDIPDll, "Int", "GdipDeleteGraphics", "Ptr", $pGRAPHICS) DllCall($GDIPDll, "None", "GdiplusShutdown", "Ptr", $GDIPToken) DllClose($GDIPDll) GUICtrlSendMsg($idCTRL, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) Return $hBitmap EndFunc ;==>_GUICtrlPic_GradientFill ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlPic_Invert ; Description ...: Farben eines Pic-Controls invertieren. (Colors of a Pic-Invert Controls.) ; Syntax.........: _GUICtrlPic_LoadImage($sPicPath) ; Parameters ....: $idPic - ControlID aus GUICtrlCreatePic() ; Return values .: Keine (no) ; Author ........: Großvater (www.autoit.de) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _GUICtrlPic_Invert($idPic) Local Const $IMAGE_BITMAP = 0x0000, $STM_SETIMAGE = 0x0172, $STM_GETIMAGE = 0x0173, $DSTINVERT = 0x00550009 Local $aResult Local $hBitmap = GUICtrlSendMsg($idPic, $STM_GETIMAGE, $IMAGE_BITMAP, 0) Local $aSize = WinGetClientSize(GUICtrlGetHandle($idPic)) Local $iWidth = $aSize[0], $iHeight = $aSize[1] Local $hGDI32 = DllOpen("Gdi32.dll") $aResult = DllCall($hGDI32, "Handle", "CreateCompatibleDC", "Handle", 0) Local $hDC = $aResult[0] $aResult = DllCall($hGDI32, "Handle", "SelectObject", "Handle", $hDC, "Handle", $hBitmap) $aResult = DllCall($hGDI32, "BOOL", "BitBlt", "Handle", $hDC, "INT", 0, "INT", 0, "INT", $iWidth, "INT", $iHeight, _ "Handle", $hDC, "INT", 0, "INT", 0, "DWORD", $DSTINVERT) $aResult = DllCall($hGDI32, "BOOL", "DeleteDC", "Handle", $hDC) DllClose($hGDI32) GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) EndFunc ;==>_GUICtrlPic_Invert ; =============================================================================================================================== Link to comment Share on other sites More sharing options...
odaylton Posted December 4, 2017 Share Posted December 4, 2017 Link alemão https://autoit.de/index.php?thread/84310-gui-mit-fernbedienung-steuern/&postID=674432&highlight=GuiCtrlPic.au3#post674432 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now