[SOLVED] [GUI] Picture mouse over

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

[SOLVED] [GUI] Picture mouse over

18 May 2015, 05:29

Hi guys, I need you help because I'm not good with GUI stuff :D

I have a simple GUI showing some pictures and a mouseover code. I would like to apply a transparent layer on top of the pictures so that they will become darker or lighter on mouse over.

There's a simple way to do it?


Thank you :)
Last edited by cyruz on 20 May 2015, 12:03, edited 1 time in total.
ABCza on the old forum.
My GitHub.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: [GUI] Picture mouse over

19 May 2015, 02:50

Not saying that this is simple but its useable

Code: Select all

#NoEnv
#SingleInstance Force
 
OnMessage(0x200, "MouseMove")
 
Gui, Margin, 50, 50
Gui, Add, Picture,  Icon8 vMyPic1 +0x0100, %A_WinDir%\System32\shell32.dll
Gui, Add, Picture,  Icon22 vMyPic2 +0x0100, %A_WinDir%\System32\shell32.dll
Gui, Show,, test
 
Return
 
MouseMove(wParam, lParam, Msg, hWnd)
{
    static shown, Overlay_id

    Gui, %A_Gui%: +HwndhGui
    
    if (hwnd = Overlay_id) ; return if mouse over overlay gui
        return
    
    if ((A_GuiControl = "MyPic1") || (A_GuiControl = "MyPic2")) and (!shown)
        {
            
            shown := true
            GuiControlGet, %A_GuiControl%, Pos
            
            X := %A_GuiControl%x
            Y := %A_GuiControl%y
            w := %A_GuiControl%w
            h := %A_GuiControl%h
            
            VarSetCapacity(POINT, 8, 0)
            NumPut(X, POINT, 0, "Int")
            NumPut(Y, POINT, 4, "Int")
            DllCall("User32.dll\ClientToScreen", "Ptr", hGui, "Ptr", &POINT)
            X := NumGet(POINT, 0, "Int")
            Y := NumGet(POINT, 4, "Int")
            
            DetectHiddenWindows on
            Gui, 2: Color, FFFFFF
            Gui, 2: +hwndOverlay_id +owner%hGui%
            WinSet, Transparent, 100, ahk_id %Overlay_id%
            Gui, 2: -Caption +ToolWindow
            Gui, 2: show, x%x% y%y% h%h% w%w% NA
            DetectHiddenWindows off

        }
        else
        {
            Gui, 2:Destroy
            shown := false
        }
}
Hope it helps
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: [GUI] Picture mouse over

20 May 2015, 02:29

Ahahaha this is awesome :D
Showing a small transparent gui on top of the image... Clever!

Thank you Blackholyman.

PS: it works great. May I ask you what option is +0x0100?
ABCza on the old forum.
My GitHub.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: [GUI] Picture mouse over

20 May 2015, 03:01

Great thanks and np

+0x0100 is SS_NOTIFY

It's needed for static controls like Text, Pic to use OnMessage with WM_MOUSEMOVE, you can also get a similar result by giving the control a (dummy) g-label
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: [GUI] Picture mouse over

20 May 2015, 04:43

Thank you for the info :)

Unfortunately If I put a gLabel on the original picture to catch the click it doesn't work and if I create an empty text in the mouseover gui giving it the gLabel, it works but the over effect flickers a lot... Any idea?
ABCza on the old forum.
My GitHub.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: [GUI] Picture mouse over

20 May 2015, 07:16

Code: Select all

#NoEnv
#SingleInstance Force
 
OnMessage(0x200, "MouseMove")
 
Gui, Margin, 50, 50
Gui, Add, Picture,  Icon8 vMyPic1 +0x0100, %A_WinDir%\System32\shell32.dll
Gui, Add, Picture,  Icon22 vMyPic2 +0x0100, %A_WinDir%\System32\shell32.dll
Gui, Show,, test
 
Return




 
MouseMove(wParam, lParam, Msg, hWnd)
{
    static shown, Overlay_id, Text_id

    Gui, %A_Gui%: +HwndhGui
    
    if (hwnd = Overlay_id) or (hwnd = Text_id) ; return if mouse over overlay gui
        return
    
    if ((A_GuiControl = "MyPic1") || (A_GuiControl = "MyPic2")) and (!shown)
        {
            
            shown := true
            GuiControlGet, %A_GuiControl%, Pos
            
            X := %A_GuiControl%x
            Y := %A_GuiControl%y
            w := %A_GuiControl%w
            h := %A_GuiControl%h
            
            VarSetCapacity(POINT, 8, 0)
            NumPut(X, POINT, 0, "Int")
            NumPut(Y, POINT, 4, "Int")
            DllCall("User32.dll\ClientToScreen", "Ptr", hGui, "Ptr", &POINT)
            X := NumGet(POINT, 0, "Int")
            Y := NumGet(POINT, 4, "Int")
            
            DetectHiddenWindows on
            Gui, 2: Color, FFFFFF
            Gui, 2: +hwndOverlay_id +owner%hGui%
            WinSet, Transparent, 100, ahk_id %Overlay_id%
            Gui, 2: -Caption +ToolWindow
            Gui, 2: Margin, 0, 0
            Gui, 2: add, Text, h%h% w%w% hwndText_id go
            Gui, 2: show, x%x% y%y% h%h% w%w% NA
            DetectHiddenWindows off

        }
        else
        {
            Gui, 2:Destroy
            shown := false
        }
        
    return
    
    
    o:
    msgbox 
    return
}
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: [GUI] Picture mouse over

20 May 2015, 09:30

Yes that's exactly what I did, but the overlay flickers a lot when you move the mouse... I'm trying to do something with a hotkey.
ABCza on the old forum.
My GitHub.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: [GUI] Picture mouse over

20 May 2015, 09:44

Hmm not in my tests did you try my example?
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: [GUI] Picture mouse over

20 May 2015, 10:18

Your example works great but if I use some png, like in my case, the overlay flickers a lot :(

EDIT: Looks like there is something strange, I adapted my gui to your example with 2 fixed images and it is not flickering. In my final code i calculate the size dinamically, depending on the number of images (it's a kind of launcher), but I get a lot of flicker... I have to find what is causing that.

EDIT2: Found the problem, i forgot to declare static the hwnd of the text control... :oops:
ABCza on the old forum.
My GitHub.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 374 guests