Jump to content
Sign in to follow this  
Onylove

Hover a picture when mouse over

Recommended Posts

Onylove

I don't know how to do it. When I move mouse over a picture on a GUI, the picture'll change to another picture.

Could some one help me? Thanks so much :)


Forever (freeze_love)Blog at: http://freeze_love.summerhost.info/

Share this post


Link to post
Share on other sites
Yashied

Share this post


Link to post
Share on other sites
Malkey

Another example.

And for those who quenched their thirst on Yashied's link, I added the _Iif one-liner to make the script look a little bit more complicated.

;
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <Misc.au3>

Local $Msg, $GUI, $Pic1, $Pic2

$GUI = GUICreate("My GUI picture", 350, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU)
GUISetBkColor(0xE0FFFF)

$Pic1 = GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 50, 50, 169, 68)
GUICtrlSetState($Pic1, $GUI_SHOW)

$Pic2 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\logo4.gif", 50, 50, 169, 68)
GUICtrlSetState($Pic2, $GUI_SHOW)

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_MOUSEMOVE
            $aCursor = GUIGetCursorInfo()

            GUICtrlSetState($Pic2, _Iif(($aCursor[4] = $Pic2) And BitAND(GUICtrlGetState($Pic2), 16), $GUI_HIDE, _Iif($aCursor[4] <> $Pic1 And BitAND(GUICtrlGetState($Pic2), 32), $GUI_SHOW, 0)))
            ; The above one liner is the same (has same logic structure and does the same) as the below, commented out If - ElseIf - EndIf lines.

            #cs
            If ($aCursor[4] = $Pic2) And BitAND(GUICtrlGetState($Pic2), 16) Then
                GUICtrlSetState($Pic2, $GUI_HIDE)
            ElseIf $aCursor[4] <> $Pic1 And BitAND(GUICtrlGetState($Pic2), 32) Then
                GUICtrlSetState($Pic2, $GUI_SHOW)
            EndIf
            #ce

        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
;

Share this post


Link to post
Share on other sites
picea892

That is a neat trick Malkey. For me it really adds to the complexity of the script and I probably would defer to a function call instead. Certainly nice to know about in case I one day am at your skill level.

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  

×