topten

Prevent buttons from flashing

7 posts in this topic

#1 ·  Posted (edited)

I create buttons, which I can move in GUI. When I drag drop them they are flashing and sometimes the button has the label of the other button. What can I do to make their behavior looking more professional, prevent them from flashing?

 

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

; Mouse coords relative to GUI client area
Opt("MouseCoordMode", 2)

; Set target coords
Global $iTgt_Left = 10, $iTgt_Right = 210, $iTgt_Top = 10, $iTgt_Bot = 110

; Create GUI
$hGUI = GUICreate("Test", 300, 200)


$cLabel = GUICtrlCreateButton("Move me", 10, 170, 80, 23)
$cLabel1 = GUICtrlCreateButton("Move me", 10, 130, 80, 23)
;GUICtrlSetBkColor(-1, 0x00FF00)

$cButton = GUICtrlCreateButton("Me too", 10, 150, 80, 23)

GUISetState()


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            ; If the mouse button is pressed - get info about where
            $cInfo = GUIGetCursorInfo($hGUI)
            ; Is it over a control
            $iControl = $cInfo[4]
            Switch $iControl
                ; If it is a control we want to move
            ;   for $z = 1 to 4
                Case $cLabel, $cButton, $cLabel1
                    ; Work out offset of mouse on control
                    $aPos = ControlGetPos($hGUI, "", $iControl)
                    $iSubtractX = $cInfo[0] - $aPos[0]
                    $iSubtractY = $cInfo[1] - $aPos[1]
                    ; And then move the control until the mouse button is released
                    Do
                        $cInfo = GUIGetCursorInfo($hGUI)
                        ControlMove($hGUI, "", $iControl, 10, $cInfo[1] - $iSubtractY)
                    Until Not $cInfo[2]
                    ; See if the mouse was released over the target
                    $aMPos = MouseGetPos()



            EndSwitch
    EndSwitch
WEnd

Great thanx in advance! I enclose a picture first picture what I get, the second picture is when I move the mouse over the gui

 

example.png

Edited by topten

Share this post


Link to post
Share on other sites



:)

Share this post


Link to post
Share on other sites

topten,

Adding the $WS_CLIPSIBLINGS style to the GUI seems to solve the problem for me.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

So, I am trying this code with clipsiblings And now I dont even see my gui at all. It starts hiding, I can see it only when I move my mouse of the script icon on the process bar

 

 

example2.thumb.png.08663e11ba6f3bc210643

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

; Mouse coords relative to GUI client area
Opt("MouseCoordMode", 2)

; Set target coords
Global $iTgt_Left = 10, $iTgt_Right = 210, $iTgt_Top = 10, $iTgt_Bot = 110

; Create GUI
$hGUI = GUICreate("Test", 300, 200, $WS_CLIPSIBLINGS)


$cLabel = GUICtrlCreateButton("Move me", 10, 170, 80, 23)
$cLabel1 = GUICtrlCreateButton("Move me", 10, 130, 80, 23)
;GUICtrlSetBkColor(-1, 0x00FF00)

$cButton = GUICtrlCreateButton("Me too", 10, 150, 80, 23)

GUISetState(@SW_SHOW)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            ; If the mouse button is pressed - get info about where
            $cInfo = GUIGetCursorInfo($hGUI)
            ; Is it over a control
            $iControl = $cInfo[4]
            Switch $iControl
                ; If it is a control we want to move
            ;   for $z = 1 to 4
                Case $cLabel, $cButton, $cLabel1
                    ; Work out offset of mouse on control
                    $aPos = ControlGetPos($hGUI, "", $iControl)
                    $iSubtractX = $cInfo[0] - $aPos[0]
                    $iSubtractY = $cInfo[1] - $aPos[1]
                    ; And then move the control until the mouse button is released
                    Do
                        $cInfo = GUIGetCursorInfo($hGUI)
                        ControlMove($hGUI, "", $iControl, 10, $cInfo[1] - $iSubtractY)
                    Until Not $cInfo[2]
                    ; See if the mouse was released over the target
                    $aMPos = MouseGetPos()



            EndSwitch
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites

also with $WS_CLIPSIBLINGS it seems that the issue doesn't go away,
the problem arises when the mousepointer is hovering on the other buttons while dragging the picked button.

The underlying buttons "react" to the mouse move causing the visual issue.
I've seen that adding GUICtrlSetState(-1, $GUI_DISABLE ) after each GUICtrlCreateButton (disabling indeed to buttons), you will be still allowed to drag the buttons but without the visual issue.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

topten,

I said "ADD", not "REPLACE" - so you would need to use this:

$hGUI = GUICreate("Test", 300, 200, Default, Default, BitOr($GUI_SS_DEFAULT_GUI, $WS_CLIPSIBLINGS))

What you did was replace all the existing styles - the Setting Styles tutorial in the Wiki explains why you need to do this.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

May I add, better use $GUI_EVENT_SECONDARYDOWN to do this move so you don't execute a 'click button' when the mouse button is released

Edit
GuiCtrlSendMsg seems better for me than $WS_CLIPSIBLINGS

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>

; Mouse coords relative to GUI client area
Opt("MouseCoordMode", 2)

; Set target coords
Global $iTgt_Left = 10, $iTgt_Right = 210, $iTgt_Top = 10, $iTgt_Bot = 110

; Create GUI
$hGUI = GUICreate("Test", 300, 200)

$cLabel = GUICtrlCreateButton("Move me", 10, 170, 80, 23)
$cLabel1 = GUICtrlCreateButton("Move me", 10, 130, 80, 23)
$cButton = GUICtrlCreateButton("Me too", 10, 150, 80, 23)

GUISetState(@SW_SHOW)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_SECONDARYDOWN
            ; If the mouse button is pressed - get info about where
            $cInfo = GUIGetCursorInfo($hGUI)
            ; Is it over a control
            $iControl = $cInfo[4]
            Switch $iControl
                ; If it is a control we want to move
                Case $cLabel, $cButton, $cLabel1
                    GuiCtrlSendMsg($iControl, $BM_SETSTATE, 1, 0)
                    ; Work out offset of mouse on control
                    $aPos = ControlGetPos($hGUI, "", $iControl)
                    $iSubtractX = $cInfo[0] - $aPos[0]
                    $iSubtractY = $cInfo[1] - $aPos[1]
                    ; And then move the control until the mouse button is released
                    Do
                        $cInfo = GUIGetCursorInfo($hGUI)
                        ControlMove($hGUI, "", $iControl, 10, $cInfo[1] - $iSubtractY)
                    Until Not $cInfo[3]
                    ; See if the mouse was released over the target
                    $aMPos = MouseGetPos()
                    GuiCtrlSendMsg($iControl, $BM_SETSTATE, 0, 0)
            EndSwitch

        Case $cLabel, $cButton, $cLabel1
            msgbox(0,"", "test")

    EndSwitch
WEnd

 

Edited by mikell

Share this post


Link to post
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