Ask a question about Gui edit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
yerjoy
Posts: 8
Joined: 20 Dec 2021, 20:08

Ask a question about Gui edit

Post by yerjoy » 07 Dec 2022, 22:35

Hello friends:
I ask a question about Gui edit. I want to write a autohotkey program to show the characters that I selected. For example I want to show 12345 string that I selected,but when I press show key on the menu the blue selected background will disappear,and the program can not catch the characters.
I dont know how to solve this problem.who can help me to solve it,so the program can msgbox show 12345 that I selected when I press the [see] button.

thanks a lot
Johnson Yan

Code: Select all

Gui, winprogram: New
gui winprogram:+alwaysontop
gui winprogram:add,Edit,x5 y5 w150 r6  vwinproeditstr, 
gui winprogram:add,button,x5 y125 gshowdo,[see]
Gui, winprogram:Show,w300 h150
return

Showdo:
gui,submit,nohide
;---?----
;---?----
;---?----
;---?----
;---?----
;---?----
MsgBox,the words that you select is {12345}
return

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
Attachments
tupian1.jpg
tupian1.jpg (9.52 KiB) Viewed 452 times

Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Ask a question about Gui edit

Post by Rohwedder » 08 Dec 2022, 01:15

Hallo,
try:

Code: Select all

Gui, winprogram: New
gui winprogram:+alwaysontop
gui winprogram:add,Edit,x5 y5 w150 r6  vwinproeditstr, 
gui winprogram:add,button,x5 y125 gshowdo,[see]
Gui, winprogram:Show,w300 h150
return

Showdo:
gui,submit,nohide
ClipBoard =
ControlFocus, Edit1, ahk_class AutoHotkeyGUI 
Send, ^c
ClipWait, 0
;---?----
;---?----
;---?----
;---?----
;---?----
;---?----
MsgBox, text is %winproeditstr%`nthe words that you select is %ClipBoard%
return

User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Ask a question about Gui edit

Post by AlphaBravo » 08 Dec 2022, 01:35

Function from Edit Library

Code: Select all

Gui, winprogram: New
gui winprogram:+alwaysontop
gui winprogram:add,Edit,x5 y5 w150 r6  vwinproeditstr HwndhEdit
gui winprogram:add,button,x5 y125 gshowdo,[see]
Gui, winprogram:Show,w300 h150 y0
return

Showdo:
gui,submit,nohide
Edit_GetSel(hEdit,r_StartSelPos,r_EndSelPos)
MsgBox, % "the words that you select is:" SubStr(winproeditstr, r_StartSelPos-1, r_EndSelPos - r_StartSelPos)
return

Edit_GetSel(hEdit,ByRef r_StartSelPos="",ByRef r_EndSelPos="")
    {
    Static Dummy3304
          ,s_StartSelPos
          ,s_EndSelPos
          ,Dummy1:=VarSetCapacity(s_StartSelPos,4,0)
          ,Dummy2:=VarSetCapacity(s_EndSelPos,4,0)

          ;-- Message
          ,EM_GETSEL:=0xB0

    ;-- Get the select positions
    SendMessage EM_GETSEL,&s_StartSelPos,&s_EndSelPos,,ahk_id %hEdit%
    r_StartSelPos:=NumGet(s_StartSelPos,0,"UInt")
    r_EndSelPos  :=NumGet(s_EndSelPos,0,"UInt")
    Return r_StartSelPos
    }

yerjoy
Posts: 8
Joined: 20 Dec 2021, 20:08

Re: Ask a question about Gui edit

Post by yerjoy » 08 Dec 2022, 02:36

Thanks a lot,above two autohotkey programs all function :bravo: :dance:
image.png
image.png (126.21 KiB) Viewed 385 times

Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Ask a question about Gui edit

Post by Rohwedder » 08 Dec 2022, 02:42

This version works here:

Code: Select all

Gui, winprogram: New
gui winprogram:+alwaysontop
gui winprogram:add,Edit,x5 y5 w150 r6  vwinproeditstr HwndhEdit, 1234567890
gui winprogram:add,button,x5 y125 gshowdo,[see]
Gui, winprogram:Show,w300 h150 y0
return
Showdo:
gui,submit,nohide
Pos := Edit_GetSel(hEdit)
MsgBox, % "the words that you select is: " SubStr(winproeditstr, Pos.1, Pos.2-Pos.1+1)
return
Edit_GetSel(hEdit)
{
	Static EM_GETSEL:=0xB0, Pos1, Pos2
	,Dummy1:=VarSetCapacity(Pos1,4,0)
	,Dummy2:=VarSetCapacity(Pos2,4,0)
	;-- Get the select positions
	SendMessage EM_GETSEL, &Pos1, &Pos2,, ahk_id %hEdit%
	Return, [NumGet(Pos1,0,"UInt")+1, NumGet(Pos2,0,"UInt")]
}

just me
Posts: 9459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Ask a question about Gui edit

Post by just me » 08 Dec 2022, 02:47

Another option:

Code: Select all

Gui, winprogram: New
gui winprogram:+alwaysontop
gui winprogram:add,Edit,x5 y5 w150 r6  vwinproeditstr HwndhEdit
gui winprogram:add,button,x5 y125 gshowdo,[see]
Gui, winprogram:Show,w300 h150 y0
return

Showdo:
GuiControl, Focus, winproeditstr
ControlGet, Sel, Selected, , , ahk_id %hEdit%
MsgBox, the words that you select is: %Sel%
return

winprogramGuiClose:
ExitApp

yerjoy
Posts: 8
Joined: 20 Dec 2021, 20:08

Re: Ask a question about Gui edit

Post by yerjoy » 08 Dec 2022, 22:34

Thanks all.Every program is magical and perfectly functional :clap:
Attachments
lu.jpg
lu.jpg (24.2 KiB) Viewed 285 times

Post Reply

Return to “Ask for Help (v1)”