Sign in to follow this  
Followers 0
eJan

$GUI_EVENT_PRIMARYUP for hover Button

10 posts in this topic

#1 ·  Posted (edited)

I'd like to have "real" Hover Button which capture $GUI_EVENT_PRIMARYUP on desired control. GUIGetMsg should work when Button was released inside control - not (only) clicked. Please help.

#include <GUIConstants.au3>

$hGUI = GUICreate("GUI", 226, 88)
$text = GUICtrlCreateLabel("Label", 8, 10, 209, 29, $SS_SUNKEN)
GUICtrlSetColor($text, 0x737373)

$progress = GUICtrlCreateProgress(8, 43, 209, 16, $PBS_SMOOTH)

$btn2 = GUICreateBiStateControl(GUICtrlCreateLabel("", 83, 63, 60, 17), $hGUI, "OnHover", "OnLeave")
$btnW = GUICtrlCreateLabel("", 84, 64, 58, 15, $SS_WHITEFRAME) ; Button (white)
$btnG = GUICtrlCreateLabel("", 83, 63, 60, 17, $SS_GRAYFRAME) ; Button (gray)
GUICtrlCreateLabel("", 2, 4, 221, 81, $SS_GRAYFRAME) ; Group (gray)
$btn1 = GUICtrlCreateLabel("Button", 83, 63, 60, 17, $SS_CENTER)
GUICtrlSetColor($btn1, 0x8C8C8C)
HotKeySet("{ENTER}", "Action")

GUISetState(@SW_SHOW)

Func Close()
    GUISetState(@SW_HIDE)
    Exit
EndFunc

While 1
    CheckBiStateControl($btn2)
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn2[0]
            Action()
        Case $msg = $GUI_EVENT_CLOSE
            Close()
    EndSelect
WEnd

Func Action()
    HotKeySet("{ENTER}")
    MsgBox(0, "", "Clicked")
    For $i = 1 To 100 Step 20
        Sleep(1)
        GUICtrlSetData($progress, $i, $i)
    Next
    GUICtrlSetData($btn1, "Close")
    GUICtrlDelete($progress)
    $text2 = GUICtrlCreateLabel("Complete", 8, 43, 209, 16, $SS_CENTER + $SS_SUNKEN)
    GUICtrlSetColor($text2, 0x737373)
    HotKeySet("{ENTER}", "Close")
    While 1
        CheckBiStateControl($btn2)
        $msg = GUIGetMsg()
        Select
            Case $msg = $btn2[0] Or $msg = $GUI_EVENT_CLOSE
                Close()
        EndSelect
    WEnd
EndFunc

Func OnHover()
    GUICtrlSetColor($btn1, 0x4AAACA)
EndFunc

Func OnLeave()
    GUICtrlSetColor($btn1, 0x8C8C8C)
EndFunc

Func GUICreateBiStateControl($hControl, $hGUI, $hover_func, $leave_func)
    Local $cPos = ControlGetPos($hGUI, "", $hControl)
    Local $hBSControl[8]
    $hBSControl[0] = $hControl
    $hBSControl[1] = $cPos[0]
    $hBSControl[2] = $cPos[1]
    $hBSControl[3] = $cPos[0] + $cPos[2]
    $hBSControl[4] = $cPos[1] + $cPos[3]
    $hBSControl[5] = $hover_func
    $hBSControl[6] = $leave_func
    $hBSControl[7] = 0
    Return $hBSControl
EndFunc

Func CheckBiStateControl(ByRef $hControl)
    Local $info = GUIGetCursorInfo()
    If $info[0] > $hControl[1] And $info[0] < $hControl[3] And _
            $info[1] > $hControl[2] And $info[1] < $hControl[4] Then
        If $hControl[7] Then Return 0
        $vCallData = $hControl[0]
        Call($hControl[5])
        $hControl[7] = 1
    ElseIf $hControl[7] Then
        $vCallData = $hControl[0]
        Call($hControl[6])
        $hControl[7] = 0
    EndIf
EndFunc
Edit: AutoIt 3.1.1.92 Edited by eJan

Share this post


Link to post
Share on other sites



Can't really understand what you're trying to do, but you can create your own ActiveX button with more events like the one seen here. The button in this link can process Primary Up. You could also make labels that do the same thing.

-Livewire

Share this post


Link to post
Share on other sites

Can't really understand what you're trying to do, but you can create your own ActiveX button with more events like the one seen here. The button in this link can process Primary Up. You could also make labels that do the same thing.

-Livewire

ActiveX - NO, I have already use Labels which simulate Button - all I wanna do is: to use that label and capture mouse event when the mouse is released over Label - not clicked (because in Windows if user click on button and move cursor outside that button - nothing happen. Best explanation is HyperLink control where the action is taken when mouse is released inside HyperLink - not clicked)

Share this post


Link to post
Share on other sites

ActiveX - NO, I have already use Labels which simulate Button - all I wanna do is: to use that label and capture mouse event when the mouse is released over Label - not clicked (because in Windows if user click on button and move cursor outside that button - nothing happen. Best explanation is HyperLink control where the action is taken when mouse is released inside HyperLink - not clicked)

Perhaps something like

Case $msg = $GUI_EVENT_PRIMARYUP
            $pos = GuiGetCursorInfo()
            IF $pos[4] = 3 Then
                MsgBox(0,"Hi","You released your cursor over the label")
            EndIf

Maybe I have misunderstood you as well?

Regards,

Share this post


Link to post
Share on other sites

Thanks syberschmo, very close, unfortunately doesn't work everytime when the mouse is released.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks syberschmo, very close, unfortunately doesn't work everytime when the mouse is released.

I don't know why you need two While..Wend GUIGetMsg loops, although I'm not sure that that's the problem. If all you want is that hover button functionality, this works fine for every primary up release:
#include <GUIConstants.au3>

$hGUI = GUICreate("GUI", 226, 88)
$text = GUICtrlCreateLabel("Label", 8, 10, 209, 29, $SS_SUNKEN)
GUICtrlSetColor($text, 0x737373)

$progress = GUICtrlCreateProgress(8, 43, 209, 16, $PBS_SMOOTH)

$btnW = GUICtrlCreateLabel("", 84, 64, 58, 15, $SS_WHITEFRAME) ; Button (white)
$btnG = GUICtrlCreateLabel("", 83, 63, 60, 17, $SS_GRAYFRAME) ; Button (gray)
GUICtrlCreateLabel("", 2, 4, 221, 81, $SS_GRAYFRAME) ; Group (gray)
$btn1 = GUICtrlCreateLabel("Button", 83, 63, 60, 17, $SS_CENTER)
GUICtrlSetColor($btn1, 0x8C8C8C)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_EVENT_PRIMARYUP
                $pos = GuiGetCursorInfo()
                IF $pos[4] = 3 Then
                    MsgBox(0,"Hi","You released your cursor over the label")
                EndIf
    EndSelect
WEnd
Exit

Why don't you just go from there? Add that hover functionality differently and see, specifically, what's wrong with what you are doing. :D

I would rewrite it myself, but I'm a bit busy at the moment :D

Regards,

Edited by syberschmo

Share this post


Link to post
Share on other sites

Thanks syberschmo, very close, unfortunately doesn't work everytime when the mouse is released.

Could you explain a scenario where it does not work? Provide your code? Works everytime for me, so I'm curious.

#include <GUIConstants.au3>
    ; == GUI generated with Koda ==
    $Form1 = GUICreate("AForm1", 303, 204, 192, 125)
    $lblHoover1 = GUICtrlCreateLabel("ALabel1", 8, 8, 283, 17)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GuiGetMsg(1)
        Switch $msg[0]
            Case 0
                Sleep(250)
            Case -11
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $GUI_EVENT_PRIMARYUP
                ConsoleWrite("$msg[0]:=" & $msg[0] & ", $msg[1]:=" & $msg[1] & ", $msg[2]:=" & $msg[2] & ", $msg[3]:=" & $msg[3] & @LF)
                  $pos = GuiGetCursorInfo()
                    IF $pos[4] = $lblHoover1 Then
                        MsgBox(0,"Hi","You released your cursor over the label",5)
                    EndIf               
            Case Else
                ConsoleWrite("$msg[0]:=" & $msg[0] & ", $msg[1]:=" & $msg[1] & ", $msg[2]:=" & $msg[2] & ", $msg[3]:=" & $msg[3] & @LF)
                ;;;;;;;
        EndSwitch
    WEnd

Share this post


Link to post
Share on other sites

Could you explain a scenario where it does not work? Provide your code? Works everytime for me, so I'm curious.

This code selectively fires...

#include <GUIConstants.au3>

$hGUI = GUICreate("GUI", 226, 88)
$text = GUICtrlCreateLabel("Label", 8, 10, 209, 29, $SS_SUNKEN)
GUICtrlSetColor($text, 0x737373)

$progress = GUICtrlCreateProgress(8, 43, 209, 16, $PBS_SMOOTH)

$btn2 = GUICreateBiStateControl(GUICtrlCreateLabel("", 83, 63, 60, 17), $hGUI, "OnHover", "OnLeave")
$btnW = GUICtrlCreateLabel("", 84, 64, 58, 15, $SS_WHITEFRAME) ; Button (white)
$btnG = GUICtrlCreateLabel("", 83, 63, 60, 17, $SS_GRAYFRAME) ; Button (gray)
GUICtrlCreateLabel("", 2, 4, 221, 81, $SS_GRAYFRAME) ; Group (gray)
$btn1 = GUICtrlCreateLabel("Button", 83, 63, 60, 17, $SS_CENTER)
GUICtrlSetColor($btn1, 0x8C8C8C)
HotKeySet("{ENTER}", "Action")

GUISetState(@SW_SHOW)

Func Close()
    GUISetState(@SW_HIDE)
    Exit
EndFunc

While 1
    CheckBiStateControl($btn2)
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn2[0]
            Action()
        Case $msg = $GUI_EVENT_CLOSE
            Close()
Case $msg = $GUI_EVENT_PRIMARYUP
            $pos = GuiGetCursorInfo()
            IF $pos[4] = 3 Then
                MsgBox(0,"Hi","You released your cursor over the label")
            EndIf
    EndSelect
WEnd

Func Action()
    HotKeySet("{ENTER}")
    MsgBox(0, "", "Clicked")
    For $i = 1 To 100 Step 20
        Sleep(1)
        GUICtrlSetData($progress, $i, $i)
    Next
    GUICtrlSetData($btn1, "Close")
    GUICtrlDelete($progress)
    $text2 = GUICtrlCreateLabel("Complete", 8, 43, 209, 16, $SS_CENTER + $SS_SUNKEN)
    GUICtrlSetColor($text2, 0x737373)
    HotKeySet("{ENTER}", "Close")
    While 1
        CheckBiStateControl($btn2)
        $msg = GUIGetMsg()
        Select
            Case $msg = $btn2[0] Or $msg = $GUI_EVENT_CLOSE
                Close()
           Case $msg = $GUI_EVENT_PRIMARYUP
            $pos = GuiGetCursorInfo()
            IF $pos[4] = 3 Then
                MsgBox(0,"Hi","You released your cursor over the label")
            EndIf
        EndSelect
    WEnd
EndFunc

Func OnHover()
    GUICtrlSetColor($btn1, 0x4AAACA)
EndFunc

Func OnLeave()
    GUICtrlSetColor($btn1, 0x8C8C8C)
EndFunc

Func GUICreateBiStateControl($hControl, $hGUI, $hover_func, $leave_func)
    Local $cPos = ControlGetPos($hGUI, "", $hControl)
    Local $hBSControl[8]
    $hBSControl[0] = $hControl
    $hBSControl[1] = $cPos[0]
    $hBSControl[2] = $cPos[1]
    $hBSControl[3] = $cPos[0] + $cPos[2]
    $hBSControl[4] = $cPos[1] + $cPos[3]
    $hBSControl[5] = $hover_func
    $hBSControl[6] = $leave_func
    $hBSControl[7] = 0
    Return $hBSControl
EndFunc

Func CheckBiStateControl(ByRef $hControl)
    Local $info = GUIGetCursorInfo()
    If $info[0] > $hControl[1] And $info[0] < $hControl[3] And _
            $info[1] > $hControl[2] And $info[1] < $hControl[4] Then
        If $hControl[7] Then Return 0
        $vCallData = $hControl[0]
        Call($hControl[5])
        $hControl[7] = 1
    ElseIf $hControl[7] Then
        $vCallData = $hControl[0]
        Call($hControl[6])
        $hControl[7] = 0
    EndIf
EndFunc

Seems to fire over the text/caption part of the label.

Share this post


Link to post
Share on other sites

I'm sorry!

I didnt't explain what and where to do.

Case $msg = $btn2[0]
            Action()
I would like this one to replace with $GUI_EVENT_PRIMARYUP, where $btn2[0] is HoverButton (Label). Maybe it's little complicated because there is GUICreateBiStateControl() function which maybe doesn't allow to capture event?

Share this post


Link to post
Share on other sites

Take a look at the post in my sig :D


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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  
Followers 0