Netol Posted July 5 Share Posted July 5 Hi my friend How can I make a form that has an image background with several .png image buttons When you mouse over them they enlarge for a second I need to create a form like the attached image. Each green icon will be a .png transparent button Link to comment Share on other sites More sharing options...
Developers Jos Posted July 5 Developers Share Posted July 5 What exactly is that image from? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Werty Posted July 5 Share Posted July 5 (edited) 56 minutes ago, Jos said: What exactly is that image from? NEOM https://en.wikipedia.org/wiki/Neom So no, not a game. Edited July 5 by Werty Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Netol Posted July 5 Author Share Posted July 5 3 hours ago, Jos said: What exactly is that image from? Is a Tour Virtual of any construction. I need to create an background image and a lot of button like .png images Link to comment Share on other sites More sharing options...
Solution Andreik Posted July 5 Solution Share Posted July 5 (edited) Not really a button but something that might work well in your case. expandcollapse popup#include <GUIConstantsEx.au3> #include <GDIPlus.au3> Global $Info, $ButtonHover = False _GDIPlus_Startup() Local $hMain = GUICreate("Image", 400, 200) Local $cBackground = GUICtrlCreatePic(@ScriptDir & '\background.jpg', 0, 0, 400, 200) ; Background image GUICtrlSetState($cBackground, $GUI_DISABLE) Local $cButton = GUICtrlCreatePic('', 50, 50, 50, 50) ImageToCtrl(@ScriptDir & '\button.png', $cButton) GUISetState(@SW_SHOW, $hMain) While True Switch GUIGetMsg() Case $cButton MsgBox(0, '', 'You clicked me?') Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() Exit EndSwitch $Info = GUIGetCursorInfo($hMain) If Not IsArray($Info) Then ContinueLoop If $Info[4] = $cButton Then If Not $ButtonHover Then $ButtonHover = True ;~ You can upscale control here ImageToCtrl(@ScriptDir & '\hover.png', $cButton) ; Hovered button image EndIf Else If $ButtonHover Then $ButtonHover = False ;~ You can downscale control here ImageToCtrl(@ScriptDir & '\button.png', $cButton) ; Normal button image EndIf EndIf WEnd Func ImageToCtrl($sImage, $cCtrl) Local $hImage = _GDIPlus_ImageLoadFromFile($sImage) Local $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $iHeight = _GDIPlus_ImageGetHeight($hImage) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iWidth, $iHeight) Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_DeleteObject(GUICtrlSendMsg($cCtrl, 0x0172, 0, $hHBITMAP)) _WinAPI_DeleteObject($hHBITMAP) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_ImageDispose($hImage) EndFunc If you want multiple "buttons" you can create a multidimensional array to store the control ID and current hover state for each control. Edited July 5 by Andreik Netol 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Netol Posted July 5 Author Share Posted July 5 1 hour ago, Andreik said: Not really a button but something that might work well in your case. expandcollapse popup#include <GUIConstantsEx.au3> #include <GDIPlus.au3> Global $Info, $ButtonHover = False _GDIPlus_Startup() Local $hMain = GUICreate("Image", 400, 200) Local $cBackground = GUICtrlCreatePic(@ScriptDir & '\background.jpg', 0, 0, 400, 200) ; Background image GUICtrlSetState($cBackground, $GUI_DISABLE) Local $cButton = GUICtrlCreatePic('', 50, 50, 50, 50) ImageToCtrl(@ScriptDir & '\button.png', $cButton) GUISetState(@SW_SHOW, $hMain) While True Switch GUIGetMsg() Case $cButton MsgBox(0, '', 'You clicked me?') Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() Exit EndSwitch $Info = GUIGetCursorInfo($hMain) If Not IsArray($Info) Then ContinueLoop If $Info[4] = $cButton Then If Not $ButtonHover Then $ButtonHover = True ;~ You can upscale control here ImageToCtrl(@ScriptDir & '\hover.png', $cButton) ; Hovered button image EndIf Else If $ButtonHover Then $ButtonHover = False ;~ You can downscale control here ImageToCtrl(@ScriptDir & '\button.png', $cButton) ; Normal button image EndIf EndIf WEnd Func ImageToCtrl($sImage, $cCtrl) Local $hImage = _GDIPlus_ImageLoadFromFile($sImage) Local $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $iHeight = _GDIPlus_ImageGetHeight($hImage) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iWidth, $iHeight) Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_DeleteObject(GUICtrlSendMsg($cCtrl, 0x0172, 0, $hHBITMAP)) _WinAPI_DeleteObject($hHBITMAP) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_ImageDispose($hImage) EndFunc If you want multiple "buttons" you can create a multidimensional array to store the control ID and current hover state for each control. WOW, fantastic and you did it on the first try. Thanks a lot 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