Jump to content
Sign in to follow this  
MyEarth

solved --> Mouse "over"

Recommended Posts

MyEarth

Hello to all,

I have this script:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Flag = False
$Form1 = GUICreate("Form1", 243, 141, 196, 128)
$Button1 = GUICtrlCreateButton("Normal_1", 8, 8, 73, 33)
$Button2 = GUICtrlCreateButton("Normal_2", 7, 51, 73, 33)
$Button3 = GUICtrlCreateButton("Normal_3", 7, 95, 73, 33)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
My_Mouse_Is_Hover($Button1, "1")
;~ My_Mouse_Is_Hover($Button2, "2")
;~ My_Mouse_Is_Hover($Button3, "3")
WEnd

Func My_Mouse_Is_Hover($handle, $data)
$nHover = GUIGetCursorInfo()
If $nHover[4] = $handle Then
If Not $Flag Then
GUICtrlSetData($handle, "I'm cool")
$Flag = 1
EndIf
Else
If $Flag Then
GUICtrlSetData($handle, "Normal_" & $data)
$Flag = 0
EndIf
EndIf
EndFunc ;==>My_Mouse_Is_Hover

Work fine with 1 button, not with 2 or more, maybe is the flag but i don't know how to set it in the func. Thanks for any help

Edited by MyEarth

Share this post


Link to post
Share on other sites
MyEarth

Did you see my commented func? Remove the comment from:

;~ My_Mouse_Is_Hover($Button2, "2")

;~ My_Mouse_Is_Hover($Button3, "3")

and try to put the mouse over the first button, the second and the third start flickering

Share this post


Link to post
Share on other sites
JohnOne

I see.

$Flag is a global variable which is tested and changed with each call to the function.

So if you mouse over button one, flag is set to 1, the next call is for button 2, flag is already 1 without even having been moused over.

You see where this is going?


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
MyEarth

Yes, more or less

And when i move the mouse from Button1 to Button2, Button1 don't change his name (the flag is 1), but Button2 changes

When my mouse is on Button1, Button2 flashes

I need to set up a different flag for each button, but the problem is to set it in the Func, not like a global variable like $flag1 - $flag2

Edited by MyEarth

Share this post


Link to post
Share on other sites
PhoenixXL

Something likewise

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

$Form1 = GUICreate("Form1", 243, 141, 196, 128)
$Button1 = GUICtrlCreateButton("Normal_1", 8, 8, 73, 33)
$Button2 = GUICtrlCreateButton("Normal_2", 7, 51, 73, 33)
$Button3 = GUICtrlCreateButton("Normal_3", 7, 95, 73, 33)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
My_Mouse_Is_Hover($Button1, "1")
My_Mouse_Is_Hover($Button2, "2")
My_Mouse_Is_Hover($Button3, "3")
WEnd

Func My_Mouse_Is_Hover($handle, $data)
Static $iPrevCtl ;For a check of the previous control
$nHover = GUIGetCursorInfo()
If $nHover[4] = $handle Then
If Not ($iPrevCtl = $handle) Then
GUICtrlSetData($handle, "I'm cool")
$iPrevCtl = $handle
EndIf
Else ;For a check for the previous write
If Not (GUICtrlRead( $handle ) = ("Normal_" & $data)) Then GUICtrlSetData($handle, "Normal_" & $data)
EndIf
EndFunc ;==>My_Mouse_Is_Hover

This could even be done using _Winapi_WindowFromPoint and a AdlibRegister

or by registering messages like WM_MOUSEMOVE as suggested by JohnOne

or you can use the existing UDF like one written by MrCreator

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
MyEarth

Maybe is possible to use array to declare ex. 10 flags, then call the number of the flag in the Func. Or isn't possible?

Any other idea will be accepted :D

EDIT: Just see the PhoneixXL script, i'm testing it

Edited by MyEarth

Share this post


Link to post
Share on other sites
MyEarth

I have tested the PhoneixXL script, i have 2 question:

1) If i move the mouse on the button1 the name change, if i remove it the name come back to the previus, but if i put again the mouse on the button nothing change

Now for question N°2 -->

2) If i use your method i can apply only to text, but if i want to ex. color a label on mouse hover?

Everything solved, many thanks PhoneixXL :D

Edited by MyEarth

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
Sign in to follow this  

×