GUI: Right-click button to display Tooltip?

Get help with using AutoHotkey and its commands and hotkeys
Bernd
Posts: 12
Joined: 03 Sep 2016, 13:56

GUI: Right-click button to display Tooltip?

21 Apr 2019, 12:16

Hi, one question:
In my Gui, I use buttons with g-labels to execute certain functions (left-click).
Now I want to display a Tooltip if the button is right-clicked.
Somebody knows how?
Odlanir
Posts: 515
Joined: 20 Oct 2016, 08:20

Re: GUI: Right-click button to display Tooltip?

21 Apr 2019, 13:04

Code: Select all

OnMessage(0x204, "WM_RBUTTONDOWN")
gui,add, button, w100,Button1
gui,add, button, wp,Button2
gui,show
return

WM_RBUTTONDOWN() {
    If (A_Gui) {		
        MouseGetPos, , , , control
        if control ~= "Button"
            tooltip, % "Right click on " control
        else 
            tooltip
	}
}

esc::
    ExitApp
return
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
swagfag
Posts: 2908
Joined: 11 Jan 2017, 17:59

Re: GUI: Right-click button to display Tooltip?

21 Apr 2019, 13:12

Code: Select all

Gui New, +hwndhGui
Gui Add, Button, hwndhBtn, rmb click here
Gui Show

Tips := {(hBtn): "tool msg"}

#If WinActive("ahk_id" hGui)
RButton::
	MouseGetPos, , , , hwnd, 2
	if Tips.HasKey(hwnd)
		ToolTip % Tips[hwnd]
return
Bernd
Posts: 12
Joined: 03 Sep 2016, 13:56

Re: GUI: Right-click button to display Tooltip?

29 Apr 2019, 13:23

Thank you both!
Can you explain how it works?
For example, my usual button looks like this:

Code: Select all

Gui, Add, Button, x+10 y40 w80 h80 gAE, AE#`nÆ
Where does the "hwndhBtn, rmb click here" go?
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: GUI: Right-click button to display Tooltip?

30 Apr 2019, 02:34

Hi Bernd,

For example, using Swagfag's code:

Code: Select all

Gui New, +hwndhGui
Gui, Add, Button, x+10 y40 w80 h80 gAE hwndhAE, AE#`nÆ
Gui, Add, Button, x+10 y40 w80 h80 gOE hwndhOE, OE#`nŒ
Gui Show
Tips := {(hAE): "msg for AE", (hOE): "msg for Œ"}
return

AE:
OE:
MsgBox % A_ThisLabel
return

#If WinActive("ahk_id" hGui)
RButton::
	MouseGetPos, , , , hwnd, 2 ; stores in 'hwnd' the control's HWND of the control the mouse is hovering over
	if Tips.HasKey(hwnd)
		ToolTip % Tips[hwnd]
return
see also: Controls: Uncommon Styles and Options.

Hope this helps.
just me
Posts: 6486
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUI: Right-click button to display Tooltip?

30 Apr 2019, 03:24

Hi Bernd,

a simple solution is to use the GuiContextMenu: label:

Code: Select all

#NoEnv
Gui, Add, Button, x+10 y40 w80 h80 gAE vBtnAE, AE#`nÆ
BtnAETT := "ToolTip for AE"
Gui, Add, Button, x+10 y40 w80 h80 gOE vBtnOE, OE#`nŒ
BtnOETT := "ToolTip for OE"
Gui, Show, , ContextMenu
Return

GuiClose:
ExitApp

GuiContextMenu:
If A_GuiControl In BtnAE,BtnOE
{
   TT := %A_GuiControl%TT
   ToolTip, %TT%
   SetTimer, RemoveTT, 1000
}
Return

RemoveTT:
ToolTip
Return

AE:
OE:
MsgBox % A_ThisLabel
Return
Bernd
Posts: 12
Joined: 03 Sep 2016, 13:56

Re: GUI: Right-click button to display Tooltip?

30 Apr 2019, 18:35

Hey just me, your simple solution works! :) Thank you!
(Except I had to delete "OE:" for some reason.)
Bernd
Posts: 12
Joined: 03 Sep 2016, 13:56

Re: GUI: Right-click button to display Tooltip?

03 May 2019, 17:42

Question to just me:
What does

Code: Select all

AE:
MsgBox % A_ThisLabel
Return
exactly? I accidentally tried it without and the code still works...
just me
Posts: 6486
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUI: Right-click button to display Tooltip?

04 May 2019, 04:39

Hi Bernd,

Code: Select all

AE:
MsgBox % A_ThisLabel
Return
is just the g-label for the AE button:

Code: Select all

Gui, Add, Button, x+10 y40 w80 h80 gAE vBtnAE, AE#`nÆ ; <<<<< gAE
The MsgBox shall only show, that the label has been called.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot] and 230 guests