Jump to content

Mouse Over with 2 Pictures?


Slash
 Share

Recommended Posts

Hi Gyus,

I wanted to ask how does it work when you mouse over the

button is a different picture?

here is my code:

$Button1 = GUICtrlCreateButton("", 475, 460, 150, 35,$BS_BITMAP)

GUICtrlSetImage (-1, "play.bmp",0)

ProgressSet(23)

ps: sorry bad english^^

Link to comment
Share on other sites

Hi, since I don't have the play.bmp and a second image I did the example using 2 icons from shell32.dll.

#include <GUIConstants.au3>

$Gui = GUICreate(":)", 110, 60)
$Button = GUICtrlCreateButton("", 5, 5, 40, 40, $BS_ICON)
GUICtrlSetImage(-1, "shell32.dll", -110)
GUISetState()

$Last = $Button

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            MsgBox(0, "Button Clicked", "Button Clicked", 1)
        Case Else
            Local $GGCI = GUIGetCursorInfo($Gui)
            If $GGCI[4] = $Button And $Last <> $Button Then
                GUICtrlSetImage($Button, "shell32.dll", -110)
                $Last = $Button
            ElseIf $GGCI[4] <> $Button And $Last = $Button Then
                GUICtrlSetImage($Button, "shell32.dll", -138)
                $Last = $GGCI[4]
            EndIf
    EndSwitch
WEnd

Cheers

Link to comment
Share on other sites

smashly,

Very nice work!

I have been playing with your script, attempting to get it to toggle back in forth from one image to another per each mouse over.

What I mean is, one image is displayed on execution. On a mouse over, another image is displayed and stays latched on, or the new image is maintained, even after the cursor is removed. However, on the next mouse over the new image is toggled and the original image is restored.

I have spent a couple of hours in the available documentation and probably a couple more trying out different combinations of things that did not work.

If you have already developed something like this, would you mind posting it here? Thanks in advance!

Link to comment
Share on other sites

smashly,

Very nice work!

I have been playing with your script, attempting to get it to toggle back in forth from one image to another per each mouse over.

What I mean is, one image is displayed on execution. On a mouse over, another image is displayed and stays latched on, or the new image is maintained, even after the cursor is removed. However, on the next mouse over the new image is toggled and the original image is restored.

I have spent a couple of hours in the available documentation and probably a couple more trying out different combinations of things that did not work.

If you have already developed something like this, would you mind posting it here? Thanks in advance!

Do you mean something like this?
#include <GUIConstants.au3>

Global $Bn[6][3], $bX = 5
;$Bn[n][0] = Button Control ID
;$Bn[n][1] = Button Image State (either 1 of 2 states: 0 or 1)
;$Bn[n][2] = Last Control ID the Mouse was over

$Gui = GUICreate(":)", 250, 50)
For $i = 1 To 5
    $Bn[$i][0] = GUICtrlCreateButton("", $bX, 5, 40, 40, $BS_ICON)
    GUICtrlSetImage(-1, "shell32.dll", Idx($Bn[$i][0]))
    $bX += 50
Next
GUISetState(@SW_SHOW, $Gui)

AdlibEnable("Hover", 10)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            For $h = 1 To 5
                If $msg = $Bn[$h][0] Then MsgBox(0, "Button " & $h, "Button " & $h & " Clicked")
            Next
    EndSwitch
WEnd

Func Hover()
    Local $CI = GUIGetCursorInfo($Gui)
    For $i = 1 To 5
        If $CI[4] = $Bn[$i][0] And $Bn[$i][2] <> $CI[4] Then GUICtrlSetImage($Bn[$i][0], "shell32.dll", Idx($Bn[$i][0]))
        $Bn[$i][2] = $CI[4]
    Next
EndFunc         

Func Idx($bID)
    Local $SSI = StringSplit("-59,-60|-74,-75|-98,-99|-110,-138|-187,-188", "|")
    For $j = 1 To 5
        Local $SST = StringSplit($SSI[$j], ",")
        If $Bn[$j][0] = $bID Then 
            If $Bn[$j][1] = 0 Then
                $Bn[$j][1] = 1
                Return $SST[1]
            Else
                $Bn[$j][1] = 0
                Return $SST[2]
            EndIf
        EndIf   
    Next    
EndFunc

Cheers

Link to comment
Share on other sites

Did you have this code lying around or did you just knock it out?

Either way, very nice work and thank you for the example. I had tried a different route and came up with something about as functional as a third nostril. It would toggle, but if the cursor remained over the icon, it would continue to toggle back and forth.

Link to comment
Share on other sites

Hi

Your welcome

Knocked the code out in my morning tea break at work :)

but if the cursor remained over the icon, it would continue to toggle back and forth.

To resolve that you need to set a condition to be met before the image is changed. eg: If the last control the mouse was over is different to the current control the mouse is over then set the new image.

Cheers

Edited by smashly
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...