Jump to content

Mouse movement and button colors


3lbuniverse
 Share

Recommended Posts

Thats the thing, when I move the mouse over the button, it just turns blue by itself. I didn't do anything and can't find any code to control the change at all. And when I color the button with a GUICtrlSetBkColor($btn,0xffe4b5), then it doesn't change color at all.

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <GuiButton.au3>

GUICreate("Buttons", 510, 400)

$btn = GUICtrlCreateButton("Button", 10, 10, 90, 50)

GUISetState(@SW_SHOW)

While 1

$msg= GUIGetMsg()

Select

Case $msg=$GUI_EVENT_CLOSE

ExitLoop

EndSelect

WEnd

Link to comment
Share on other sites

So, its a windows thing, not an autoit thing? I figured I might be dealing with some internal function that I couldn't bend to my will. I'm not sure what you mean by Custom drawing the control but I'm interested in learning more, especially if it's an alternative to the _ButtonHover. Any other approaches to controling the color of a button when the mouse is over it? Thanks!

Link to comment
Share on other sites

I got it! First I was making it too simple by hoping I could control what Mat pointed out was a windows vista theme, then I was was making it too complex trying to use new UDFs, though those buttons do look pretty cool picea892. I thought it had to be possible using simple GUIGetCursorInfo but I kept getting this flickering, so combing through this forum, Melba23 provided a perfect soultion with a flag to prevent the flickering. Works great, thank you all!

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <GuiButton.au3>

$Green=0x00FF00

$Red=0xFF0000

GUICreate("Buttons", 510, 400)

$btn = GUICtrlCreateButton("Button", 10, 10, 90, 50)

GUICtrlSetBkColor($btn, $Red)

$fLabel = "Red"

GUISetState(@SW_SHOW)

While 1

$msg= GUIGetMsg()

$a = GUIGetCursorInfo()

Select

Case $msg=$GUI_EVENT_CLOSE

ExitLoop

EndSelect

If $a[4] = $btn And $fLabel = "Red" Then

GUICtrlSetBkColor($btn, $Green)

$fLabel = "Green"

ElseIf $a[4] <> $btn And $fLabel = "Green" Then

GUICtrlSetBkColor($btn, $Red)

$fLabel = "Red"

EndIf

WEnd

Link to comment
Share on other sites

  • Moderators

3lbuniverse,

Delighted I could help without actually being there - so to speak! :

A couple of points:

1. When you colour your buttons they trap "Enter" - i.e. whenever you press the "Enter" key, it is as though you pressed the button. It is a known bug and too deeply embedded in AutoIt for it to be changed. There is no reason not to colour buttons - but you need to be aware of this behaviour or it can get a bit confusing when the script apparently happens to fire off events on its own! Here is your code with a small addition - try pressing "Enter" and see what happens :huggles: :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>

$Green = 0x00FF00
$Red = 0xFF0000

GUICreate("Buttons", 510, 400)

$btn = GUICtrlCreateButton("Button", 10, 10, 90, 50)
GUICtrlSetBkColor($btn, $Red)

$fLabel = "Red"

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    $a = GUIGetCursorInfo()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $btn
            MsgBox(0, "Button", "Did you click the button" & @CRLF & "Or press Enter?")
    EndSelect

    If $a[4] = $btn And $fLabel = "Red" Then
        GUICtrlSetBkColor($btn, $Green)
        $fLabel = "Green"
    ElseIf $a[4] <> $btn And $fLabel = "Green" Then
        GUICtrlSetBkColor($btn, $Red)
        $fLabel = "Red"
    EndIf

WEnd

2. When you post code, it makes it much easier to read if you use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...