If element is highlighted, show text box

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Scr1pter
Posts: 1220
Joined: 06 Aug 2017, 08:21
Location: Germany

If element is highlighted, show text box

24 May 2018, 06:53

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
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: G502 FE, Jelly Comb Touchpad - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.32.00
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: If element is highlighted, show text box

24 May 2018, 09:01

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.
User avatar
jmeneses
Posts: 497
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: If element is highlighted, show text box

24 May 2018, 09:20

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
}
Donec Perficiam
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: If element is highlighted, show text box

24 May 2018, 09:40

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?
User avatar
jmeneses
Posts: 497
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: If element is highlighted, show text box

24 May 2018, 10:00

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:
Donec Perficiam

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], hasantr, swrong, try_else_finally, Xeo786 and 34 guests