Gui Edit and g-label?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Gui Edit and g-label?

29 Oct 2019, 07:01

Hi, is it possible to add a g-label to GUI, Edit ?
I have a table, where many values was inserted into Edit fields, and I want to get those values into Clipboard when the user clicks on the Edit field.

Code: Select all

Gui, Add, Edit, w200 gGuiE ReadOnly, First text
Gui, Add, Edit, w200 gGuiE ReadOnly, Second text
Gui, Add, Edit, w200 gGuiE ReadOnly, Third text
Gui, Show, autosize
return

GuiE:
Msgbox % A_GuiControl
return
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Gui Edit and g-label?

29 Oct 2019, 07:46

Try this it works for me with latest AHK version on Win10

Code: Select all

Gui, Add, Edit, w200 vEdit1 ReadOnly, First text
Gui, Add, Edit, w200 vEdit2 ReadOnly, Second text
Gui, Add, Edit, w200 vEdit3 ReadOnly, Third text

OnMessage(0x201, "OnWM_LBUTTONDOWN")

Gui, Show, autosize
return

OnWM_LBUTTONDOWN(wParam, lParam, msg, hWnd) {
	
	MouseGetPos,,,,clickedControl
	if (clickedControl = "Edit1") {
		GuiControlGet, Edit1
		Clipboard := Edit1
	}
	else if (clickedControl = "Edit2") {
		GuiControlGet, Edit2
		Clipboard := Edit2
	}
	else if (clickedControl = "Edit3") {
		GuiControlGet, Edit3
		Clipboard := Edit3
	}
	else
		return 0
}
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Gui Edit and g-label?

29 Oct 2019, 08:37

i was about to suggest using v2 since it has on click event handlers, but apparently not for edits. weird. i see no reason why they shouldnt be supported
anyway, heres more v1 code

Code: Select all

ClickableEdits := [GuiAdd("Edit", "w200 ReadOnly", "First text")
				, GuiAdd("Edit", "w200 ReadOnly", "Second text")
				, GuiAdd("Edit", "w200 ReadOnly", "Third text")]
Gui, Show, autosize

WM_LBUTTONDOWN := 0x201
OnMessage(WM_LBUTTONDOWN, Func("ClickableEditHandler").Bind(ClickableEdits))
ClickableEditHandler(Edits, wParam, lParam, msg, hwnd) {
	for each, hwndEdit in Edits
		if (hwnd = hwndEdit)
		{
			GuiControlGet text, , % hwnd
			Clipboard := text
			return
		}
}

GuiAdd(ControlType, Options := "", Text := "", GuiName := "") {
	Gui % (GuiName ? GuiName ":Add" : "Add"), % ControlType, % Options " hwndCtrlHwnd", % Text
	return CtrlHwnd
}
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Gui Edit and g-label?

29 Oct 2019, 08:40

Adding onto DRocks (which also worked for me) I shortened it down.

Code: Select all

Gui, Add, Edit, w200 vEdit1 ReadOnly, First text
Gui, Add, Edit, w200 vEdit2 ReadOnly, Second text
Gui, Add, Edit, w200 vEdit3 ReadOnly, Third text
Gui, Add, Text, w200 , Testing Text

OnMessage(0x201, "OnWM_LBUTTONDOWN")

Gui, Show, autosize
return

OnWM_LBUTTONDOWN(wParam, lParam, msg, hWnd) {
	MouseGetPos,,,,clickedControl
	If (InStr(clickedControl, "Edit")) {
		GuiControlGet, %clickedControl%
		Clipboard := %clickedControl%
	}
}
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Gui Edit and g-label?

29 Oct 2019, 08:53

@MannyKSoSo Smart move thanks for updating
@swagfag dude I never saw this kind of syntax. Are you basically showing that with a function binding and passing a object, you don't need to declare each Gui variables ?? The object automatically keeps a hwnd of a Gui, Add command ?? EDIT: ohh wow ok I missed that you wrapped the GuiAdd in a custom function before building the object... ok nice one :D thanks
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Gui Edit and g-label?

29 Oct 2019, 21:09

swagfag wrote:
29 Oct 2019, 08:37
i was about to suggest using v2 since it has on click event handlers, but apparently not for edits. weird. i see no reason why they shouldnt be supported
AHK v2 is still Alpha. Recommending it for use is problematic, because it can cause users a lot of other problems and headaches, especially if they need to rely on the software. If they want to experiment with AHK v2 that's all good, but it should be clear what they are getting into. AHK v1 is still the official stable release.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Gui Edit and g-label?

30 Oct 2019, 00:23

@DRocks yeah and u can also subscribe/unsubscribe edits by simply adding/removing HWNDs to/from the array, even at a later point in time
@SOTE :crazy: whatever
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Gui Edit and g-label?

30 Oct 2019, 04:25

If your edits have associated variables A_GuiControl will tell you which edit has been clicked:

Code: Select all

#NoEnv
Gui, Input:New
Gui, Add, Edit, w200 vInput1 ReadOnly, First text
Gui, Add, Edit, w200 vInput2 ReadOnly, Second text
Gui, Add, Edit, w200 vInput3 ReadOnly, Third text
Gui, Add, Text, w200 , Testing Text
Gui, Show, AutoSize, Input
OnMessage(0x0201, "On_WM_LBUTTONDOWN")
Return

InputGuiClose:
ExitApp

On_WM_LBUTTONDOWN(wParam, lParam, msg, hWnd) {
   If (A_Gui = "Input") && (SubStr(A_GuiControl, 1, 5) = "Input")
   {
      GuiControlGet, Text, , %A_GuiControl%
      ToolTip, A_GuiControl: %A_GuiControl%`nText: %Text%
      Return
   }
   Else
      ToolTip
}
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Gui Edit and g-label?

31 Oct 2019, 04:17

swagfag wrote:
29 Oct 2019, 08:37
i was about to suggest using v2 since it has on click event handlers, but apparently not for edits.
v2 raises events for notifications sent by the control to the GUI. Edit controls do not send notifications for clicking; they just handle mouse input internally.

You are able to intercept it with OnMessage because WM_LBUTTONDOWN messages are posted (not sent) to the control, which means they go into the message queue which AutoHotkey itself processes.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Gui Edit and g-label?

31 Oct 2019, 09:03

its a shame that it consumes the events
anyways, thanks for the explanation
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Gui Edit and g-label?

31 Oct 2019, 11:25

its a shame that it consumes the events
There is no event to 'consume'. Control 'events' are common control notifications and the edit control does not notify its parent about mouse clicks. Only if the mouse click sets the focus to the control it creates an EN_SETFOCUS 'event'.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], dra3th, Google [Bot], Spawnova and 228 guests