timmy2 Posted November 26, 2018 Posted November 26, 2018 I'm using a graphic button in a form and I want to change it to another image when the cursor is hovered over the button. I've got that working but the button flickers constantly. Here's my script: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; create borderless, chromeless form into which image will be placed $Form1 = GUICreate("Welcome", 500, 500, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP), 0) ; place image file in form $Pic1 = GUICtrlCreatePic("Welcometest.bmp", 0, 0, 500, 500) ; needed for some reason GuiCtrlSetState(-1,$GUI_DISABLE) ; display "Click to Continue" button $C2CBtn = GUICtrlCreatePic("C2C_off.bmp", 300, 300) ; display all of the above as a unit GUISetState(@SW_SHOW) While 1 $ggci = GUIGetCursorInfo($Form1) If $ggci[4] = $C2CBtn Then GUICtrlSetImage($C2CBtn,"C2C_on.bmp") Else GUICtrlSetImage($C2CBtn,"C2C_off.bmp") EndIf $nMsg = GuiGetMsg() Switch $nMsg Case $C2CBtn Exit EndSwitch Sleep(100) WEnd Resulting GUI Hovering the cursor over the button changes it as desired. Clicking on the button exits the demo (also desired). But it flickers constantly. Not desired! ;-) The attached button images and background image are all 24b bmp files. The actual image used in place of the white box consists of high quality text and graphics so I can't use JPG format. Welcometest.bmp C2C_off.bmp C2C_on.bmp
Developers Jos Posted November 26, 2018 Developers Posted November 26, 2018 Couple of pointers: Only set the control image when it needs changing, not 10 times per second! Never use a Sleep() in a GUI message loop! as that could lead to slowness in response or missed actions. Jos timmy2 1 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.
Zedna Posted November 26, 2018 Posted November 26, 2018 This is what Jos meant: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $b_on_off = 0 ; state of button: 0-off 1-on ; create borderless, chromeless form into which image will be placed $Form1 = GUICreate("Welcome", 500, 500, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP), 0) ; place image file in form $Pic1 = GUICtrlCreatePic("Welcometest.bmp", 0, 0, 500, 500) ; needed for some reason GuiCtrlSetState(-1,$GUI_DISABLE) ; display "Click to Continue" button $C2CBtn = GUICtrlCreatePic("C2C_off.bmp", 300, 300) ; display all of the above as a unit GUISetState(@SW_SHOW) While 1 $ggci = GUIGetCursorInfo($Form1) If $ggci[4] = $C2CBtn Then If $b_on_off = 0 Then GUICtrlSetImage($C2CBtn,"C2C_on.bmp") $b_on_off = 1 EndIf Else If $b_on_off = 1 Then GUICtrlSetImage($C2CBtn,"C2C_off.bmp") $b_on_off = 0 EndIf EndIf $nMsg = GuiGetMsg() Switch $nMsg Case $C2CBtn Exit EndSwitch ;~ Sleep(100) WEnd timmy2 1 Resources UDF ResourcesEx UDF AutoIt Forum Search
timmy2 Posted November 26, 2018 Author Posted November 26, 2018 8 hours ago, Jos said: Couple of pointers: Only set the control image when it needs changing, not 10 times per second! Never use a Sleep() in a GUI message loop! as that could lead to slowness in response or missed actions. Jos Thank you, @Jos and @Zedna! Jos's reply inspired me to go down the path you so graciously completed for me. Despite the changes shown below I was still wrestling with flickering during hovering when notification of your post appeared. If coding were whittling I would be knee deep in a pile of discards. I appreciate your help immensely. If $ggci[4] = $C2CBtn And $iC2CBtnState = 0 Then GUICtrlSetImage($C2CBtn,"C2C_on.bmp") $iC2CBtnState = 1 Else if $iC2CBtnState = 1 then GUICtrlSetImage($C2CBtn,"C2C_off.bmp") $iC2CBtnState = 0 EndIf
timmy2 Posted November 28, 2018 Author Posted November 28, 2018 Just FYI, I created and tested the above script in AutoIt 3.3.14.2. After upgrading to 3.3.14.5 the internal graphic is resized, I presume because GUICtrlCreatePic is now more strictly obeying the description for width and height: (default is the previously used width). so the following line of code in my original post should now include the dimensions of the click-to-continue button: ; display "Click to Continue" button $C2CBtn = GUICtrlCreatePic("C2C_off.bmp", 300, 300, 144, 144)
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