Jump to content
Sign in to follow this  
Valuater

_ControlHover() UDF

Recommended Posts

Hey all, here is my example script:

2.) This one is my example of being able to move the controls around (only the label moves as of now):

UPDATED: The new example lets you move any of the three controls, and right clicking allows you to rename them.

#include<GuiConstants.au3>
#include<ControlHover.au3>
Opt("MouseCoordMode", 2)

$Main_GUI = GuiCreate("DanGui", 400, 250)

$MoveMe = GuiCtrlCreateLabel("Move Me (Test)", 150, 70, 80, 20)
$OK_BUT = GuiCtrlCreateButton("OK", 70, 160, 80, 20)
$CANCEL_BUT = GuiCtrlCreateButton("CANCEL", 220, 160, 90, 20)
$Move_But = GUICtrlCreateButton("Unlock Controls", 150, 220)
$Allow_Move = 0
_ControlHover(2, "", $MoveMe)
_ControlHover(2, "", $OK_BUT)
_ControlHover(2, "", $CANCEL_BUT)

GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $OK_BUT
            If $Allow_Move = 0 Then
                MsgBox(0, "Title", "This button still works!")
            EndIf
        Case $msg = $CANCEL_BUT
            If $Allow_Move = 0 Then
                MsgBox(0, "Title", "This button still works!")
            EndIf
        Case $msg = $Move_But
            If $Allow_Move = 0 Then
                GUICtrlSetData(6, "Lock Controls")
                $Allow_Move = 1
            ElseIf $Allow_Move = 1 Then
                GUICtrlSetData(6, "Unlock Controls")
                $Allow_Move = 0
            EndIf
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    
    ;If moving is enabled
    
    If $Allow_Move = 1 Then
        
        ;Check for a Hover
        
        $Over = _ControlHover(0, $Main_GUI)
        If $Over = 1 Then
            If @extended = $MoveMe Then
                GUICtrlSetBkColor(3, 0xFF0000)
            Else
                GUICtrlSetBkColor(3, 0xECE9D8)
            EndIf
            If @extended = $OK_BUT Then
                GUICtrlSetColor(4, 0xFF0000)
            Else
                GUICtrlSetColor(4, 0xECE9D8)
            EndIf
        EndIf
        
        ;Check for a Click
        
        $Click = _ControlHover(1, $Main_GUI)
        If $Click = 1 Then
            Select
                Case @extended = $MoveMe
                    MoveControl(3)
                Case @extended = $OK_BUT
                    MoveControl(4)
                Case @extended = $CANCEL_BUT
                    MoveControl(5)
            EndSelect
        EndIf
        $Check_Click = GUIGetCursorInfo()
        Select
            Case $Check_Click[4] = 3 And $Check_Click[3] = 1
                Text_Change(3)
            Case $Check_Click[4] = 4 And $Check_Click[3] = 1
                Text_Change(4)
            Case $Check_Click[4] = 5 And $Check_Click[3] = 1
                Text_Change(5)
        EndSelect
    EndIf
WEnd

;Text_Change ==> To rename a control in "Unlocked" mode when it is right-clicked on.

Func Text_Change($IDtoRename)
    $New_Name = InputBox("Label Change", "Input new text for this label:")
    If $New_Name = "" Then
        MsgBox(0, "ERROR!", "The entered text was invalid.  No changes have been made.")
    Else
        GUICtrlSetData($IDtoRename, $New_Name)
    EndIf
EndFunc

;MoveControl ==> When a control is clicked on in "Unlocked" mode.

Func MoveControl($IDtoMove)
    Do
        $Check_Click = GUIGetCursorInfo()
        $mousepos = MouseGetPos()
        GUICtrlSetPos($IDtoMove, $mousepos[0] - 40, $mousepos[1] - 10)
        Sleep(20)
    Until $Check_Click[2] = 0
EndFunc

Enjoy! I hope Val get's a sticky for this :).

I love your script! ;):lmao::evil::mad::o:D:nuke:

Share this post


Link to post
Share on other sites

Has anyone gotten this to work with GUIONEventMode where an event fires when someone hovers, etc...?

I'll post if I can figure it out :P

Share this post


Link to post
Share on other sites

Has anyone gotten this to work with GUIONEventMode where an event fires when someone hovers, etc...?

I'll post if I can figure it out :D

I think it must first be integrated in the au3 EXE file to use it, I tryed quiet all possibilities with GUIOnEventMode with no result lol.

IMO you should better try to use it with the MessageLoop Mode since it doesn't work with GUIOnEventMode :P .

Share this post


Link to post
Share on other sites

Yeah, I finally just converted my code to a msg loop.... oh well :P

But now I've got another issue... When I have a program run on a "isReleased" event, the button does not go back to it's normal state! It's like ControlHover just stops responding for that button until I do something with another button?!?

If I remove the program from running, then everything works fine... but of course, that kind of defeats the purpose :D

Anyway, i've attached the code with my buttons that i've worked so hard to create... anyone want to take a stab at getting this to work? See any obvious errors? I've used a ton of different configurations from the different demo's posted, but they all seem to have the same issue, so i'm guessing it is something inherent to _ControlHover.

thanks!

Share this post


Link to post
Share on other sites

Very nice....

you just have one small issue with the wrong letter in the command

replace

Func _ButtonReleased($ControlID)

_ParseRun($ControlID, "H")

with

Func _ButtonReleased($ControlID)

_ParseRun($ControlID, "N")

The "N" worked for me

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Very nice....

you just have one small issue with the wrong letter in the command

replace

Func _ButtonReleased($ControlID)

_ParseRun($ControlID, "H")

with

Func _ButtonReleased($ControlID)

_ParseRun($ControlID, "N")

The "N" worked for me

8)

Thanks for the quick reply! That does seem to "reset" it for me... but it looks like it is exhibiting some odd behavior still. Upon clicking the "Show Desktop" button, none of the buttons respond to my mouse movement (aka Hover events) until I click something new with the mouse. Perhaps I can force some sort of reset in the GUI to get it responding again?

Does it do that to you too when you test?

Share this post


Link to post
Share on other sites

Yes...

_ControlHover only works if it is the active window, and was deigned that way...

The reason is, if it is not active and you click on another window but your gui is underneath, the click would be activated and cause problems...

to simply fix your problem, just place this code

Case $_ShowDesktop

ShowDesktop()

WinActivate($_GUI)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Yes...

_ControlHover only works if it is the active window, and was deigned that way...

The reason is, if it is not active and you click on another window but your gui is underneath, the click would be activated and cause problems...

to simply fix your problem, just place this code

Case $_ShowDesktop

ShowDesktop()

WinActivate($_GUI)

8)

That's it!!! Geez, go figure it was an easy fix :P

Thanks Valuater, I'll be sure to link to this topic once I post the final script I'm making. ControlHover aught to get added as an official UDF.

Share this post


Link to post
Share on other sites

Hey Val, I'm just curious, do you think using Larry's "WindowFromPoint" stuff would make your _ControlHover any faster... or even make it possible for Hover to be detected if the GUI is NOT the active window?

I've been playing around with it in a few scripts and it seems pretty quick, but I'm still working on understanding his example.

Share this post


Link to post
Share on other sites

Hey Val, I'm just curious, do you think using Larry's "WindowFromPoint" stuff would make your _ControlHover any faster... or even make it possible for Hover to be detected if the GUI is NOT the active window?

I've been playing around with it in a few scripts and it seems pretty quick, but I'm still working on understanding his example.

let me know what you find... so far, i don't see any advantage to implementing this to _ControlHover()

for sure i am having problems with the script from Larry recognizing a control on a tab

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I like the UDF Valuater. I have created one that gets the Control Info under the mouse here http://www.autoitscript.com/forum/index.php?showtopic=93527.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...