Page 1 of 1

If element is highlighted, show text box

Posted: 24 May 2018, 06:53
by Scr1pter
Hi guys,

I would like to realize the following:
When creating a Gui which contains buttons, I want to add a little icon (picture) next to the buttons.
When a user highlights such a picture with the mouse cursor, an information box with text should appear.
As soon as the mouse cursor gets moved away from the picture, the text box should disappear automatically.

I was thinking about something like this:
Image

I believe I saw such behaviour in programs, but I can't remember in which ones.

Is "tooltip" suitable for my desire?


The code (for this simple text gui is):

Code: Select all

F7::
x := (A_ScreenWidth/2)-(Width/2)
y := (A_ScreenHeight/2)-(Height/2)
Gui, +AlwaysOnTop
Gui, Show, %x% %y% w330 h300
Gui, Add, Button, x0 y0 w100 h100 gOk, Ok
Gui, Add, Button, x0 y150 w100 h100 gCancel, Cancel
Gui, Add, Picture, x100 y0 w20 h20, C:\Users\USER\Documents\Logitech Gaming Software\AutoHotKey-Scripts\pics\Question.png
return

Ok:
Gui, Submit, NoHide
Gui, Destroy
return

Cancel:
Gui, Destroy
return

Esc::
ExitApp
return
Best regards

Re: If element is highlighted, show text box

Posted: 24 May 2018, 09:01
by MaxAstro
You could do this with a tooltip and a background loop, yes. You can have the loop call MouseGetPos, which can return the control under the mouse. If the control under the mouse is the image, display the tooltip, otherwise turn it off.

Re: If element is highlighted, show text box

Posted: 24 May 2018, 09:20
by jmeneses
MaxAstro wrote:You could do this with a tooltip and a background loop, yes. You can have the loop call MouseGetPos, which can return the control under the mouse. If the control under the mouse is the image, display the tooltip, otherwise turn it off.

Code: Select all

F7:: 
x := (A_ScreenWidth/2)-(Width/2)
y := (A_ScreenHeight/2)-(Height/2)
Gui, +AlwaysOnTop
Gui, Show, %x% %y% w330 h300
Gui, Add, Button, x0 y0 w100 h100 gOk, Ok
Gui, Add, Button, x0 y150 w100 h100 gCancel, Cancel
Gui, Add, Picture, x100 y0 w20 h20, C:\Users\USER\Documents\Logitech Gaming Software\AutoHotKey-Scripts\pics\Question.png
OnMessage(0x200,"MouseHover")
OnMessage(0x202,"MouseLeave")
return

Ok:
Gui, Submit, NoHide
Gui, Destroy
return

Cancel:
Gui, Destroy
return

Esc::
ExitApp
return

MouseHover(wParam, lParam, msg, hwnd) {
   MouseGetPos, , , , CurrControl
   If (msg = 0x200) && (Instr(CurrControl,"Static"))
      ToolTip % "Executes operation"
   Else
      ToolTip
   Return
}

Re: If element is highlighted, show text box

Posted: 24 May 2018, 09:40
by MaxAstro
Interesting, I didn't know there was a system message for that. Looking at the list of system messages, though, isn't 0x202 LButton up?

Re: If element is highlighted, show text box

Posted: 24 May 2018, 10:00
by jmeneses
MaxAstro wrote:Interesting, I didn't know there was a system message for that. Looking at the list of system messages, though, isn't 0x202 LButton up?
You're right it's a mistake

Code: Select all

OnMessage(0x202,"MouseLeave")
is LBUTTONUP and is needless in this script :thumbup: