Tooltips in GUI V1 to V2 convert Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
IWantItAll2
Posts: 8
Joined: 14 Jun 2023, 10:00

Tooltips in GUI V1 to V2 convert

29 Jun 2023, 05:54

I found some code that works fantastically... in V1.x
I'm having some trouble converting it to V2.0. the % %CurrControl%_TT part is getting the best of me. any help converting it would be great!
I'ts also not happy with PrevControl being set after its already used but i think i can get a work around for that.
Thanks

Code: Select all

Gui, Add, Edit, vMyEdit
MyEdit_TT := "This is a tooltip for the control whose variable is MyEdit."
Gui, Add, DropDownList, vMyDDL, Red|Green|Blue
MyDDL_TT := "Choose a color from the drop-down list."
Gui, Add, Checkbox, vMyCheck, This control has no tooltip.
Gui, Show
OnMessage(0x200, "WM_MOUSEMOVE")
return

WM_MOUSEMOVE()
{
    static CurrControl, PrevControl, _TT  ; _TT is kept blank for use by the ToolTip command below.
    CurrControl := A_GuiControl
    If (CurrControl <> PrevControl and not InStr(CurrControl, " "))
    {
        ToolTip  ; Turn off any previous tooltip.
        SetTimer, DisplayToolTip, 1000
        PrevControl := CurrControl
    }
    return

    DisplayToolTip:
    SetTimer, DisplayToolTip, Off
    ToolTip % %CurrControl%_TT  ; The leading percent sign tell it to use an expression.
    SetTimer, RemoveToolTip, 3000
    return

    RemoveToolTip:
    SetTimer, RemoveToolTip, Off
    ToolTip
    return
}


GuiClose:
ExitApp
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Tooltips in GUI V1 to V2 convert

29 Jun 2023, 06:12

Hello,

1. Who wrote the script?
2. What does the script currently do in v1?
3. What is your current draft v2 script?
IWantItAll2
Posts: 8
Joined: 14 Jun 2023, 10:00

Re: Tooltips in GUI V1 to V2 convert

29 Jun 2023, 06:19

The script i got from an old forum post https://www.autohotkey.com/board/topic/81915-solved-gui-control-tooltip-on-hover/
The scrip shows a tool tip the relevant tool tip when hovering the mouse over the respective UI element.

My current script for V2 is below, but it is not working.

Code: Select all

#Requires AutoHotkey v2.0-a ; forces V2
myGUI :=Gui()
myGUI.Add("Edit", "vMyEdit")
MyEdit_TT := "This is a tooltip for the control whose variable is MyEdit."
myGUI.Add("DropDownList", "vMyDDL", "Red|Green|Blue")
MyDDL_TT := "Choose a color from the drop-down list."
myGUI.Add("Checkbox", "vMyCheck", "This control has no tooltip.")
myGUI.Show()
OnMessage(0x200, "WM_MOUSEMOVE")
return

WM_MOUSEMOVE()
{
    static CurrControl, PrevControl, _TT  ; _TT is kept blank for use by the ToolTip command below.
    
	CurrControl := A_GuiControl
    If (CurrControl != PrevControl)
    {
        ToolTip  ; Turn off any previous tooltip.
        SetTimer( , DisplayToolTip, 1000)
        PrevControl := CurrControl
    }
    return

    DisplayToolTip:
		SetTimer( , DisplayToolTip, Off)
		ToolTip (%CurrControl%_TT)  ; The leading percent sign tell it to use an expression.
		SetTimer( , RemoveToolTip, 3000)
		return

    RemoveToolTip:
		SetTimer( , RemoveToolTip, Off)
		ToolTip
		return
}


GuiClose:
ExitApp
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Tooltips in GUI V1 to V2 convert  Topic is solved

29 Jun 2023, 07:11

In case not: you would have to translate your script into v2 syntax. The approach below is a bit roundabout compared to the more advanced script from just me.

Code: Select all

#Requires AutoHotkey v2.0
gui1 := Gui(, 'Colors')
gui1.SetFont     's10'
gui1.AddEdit     'w230 vMyEdit'
gui1.AddDDL      'wp   vMyDDL'  , ['Red', 'Green', 'Blue']
gui1.AddCheckBox 'wp   vMyCheck', 'This control has no tooltip.'
gui1.Show
tip := Map(
   'Edit1'    , 'This is a tooltip for the control whose variable is MyEdit.'
 , 'ComboBox1', 'Choose a color from the drop-down list.'
)
OnMessage 0x200, WM_MOUSEMOVE

WM_MOUSEMOVE(wParam, lParam, msg, hwnd) {
 Static PrevControl := ''
 Global CurrControl
 MouseGetPos ,,, &CurrControl
 If CurrControl != PrevControl {
  ToolTip(), SetTimer(showTip, -800)
  PrevControl := CurrControl
 }
}

showTip() {
 If tip.Has(CurrControl)
  ToolTip(tip[CurrControl]), SetTimer(ToolTip, -3000)
}
cgx5871
Posts: 319
Joined: 26 Jul 2018, 14:02

Re: Tooltips in GUI V1 to V2 convert

20 Feb 2024, 18:35

@mikeyww
I just saw you write like this. You can also delay the display of the tooltip.

Code: Select all

ToolTip("ok"), SetTimer(ToolTip, -3000)
-----------------------------
Why is the official help so complicated?
As a beginner, very confused. Why is the help file written like this?
-----------------------------
#2: Hides a tooltip after a certain amount of time without having to use Sleep (which would stop the current thread).

Code: Select all

ToolTip "Timed ToolTip`nThis will be displayed for 5 seconds."
SetTimer () => ToolTip(), -5000
In addition, can this Map() directly call the v variable defined in the gui?
vMyEdit'
vMyDDL'
vMyCheck'
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Tooltips in GUI V1 to V2 convert

20 Feb 2024, 20:00

I do not understand your questions.

"V" options are accessible when you :arrow: submit the GUI.

Using fat-arrow functions is not required. You can use a function or function object with the more traditional syntax if easier.

Although AHK enables multi-statement lines, the statements can also be put onto separate lines if easier (using braces where relevant).

V1 commands became functions in v2, so these can generally be used in the same ways that other functions can be used. In other words, these native v2 functions are called as functions. Similarly, the native v2 function can be named as a func object when representing the function and providing a way to call it or bind parameters to it.

Using v2 requires a basic level of understanding how expressions and functions work, so that may require more reading and learning in some instances. Expressions and functions are used more in v2 than in v1.

An alternative to your script is below. The "done" function only calls the "ToolTip" function. Thus, this form of script provides some unnecessary steps, because SetTimer can instead just call the ToolTip function object directly-- which is what your script does.

Code: Select all

#Requires AutoHotkey v2.0
sec := 2
ToolTip 'Timed ToolTip`nThis will be displayed for ' sec ' seconds.'
SetTimer done, -1000 * sec

done() {
 ToolTip
}
Simplify further:

Code: Select all

#Requires AutoHotkey v2.0
sec := 2
ToolTip 'Timed ToolTip`nThis will be displayed for ' sec ' seconds.'
SetTimer ToolTip, -1000 * sec
In this script, ToolTip is the function object to call when the timer expires.

I think that part of the answer to your question is that practicing with these constructs will help you to understand them. We can talk all day about how to ride a bicycle, but you will fully learn how to do it when you get on the bicycle.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: AccelAHK, Bing [Bot], Descolada, vmech and 40 guests