Page 1 of 1

Ask a question about Gui edit

Posted: 07 Dec 2022, 22:35
by yerjoy
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.]

Re: Ask a question about Gui edit

Posted: 08 Dec 2022, 01:15
by Rohwedder
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

Re: Ask a question about Gui edit

Posted: 08 Dec 2022, 01:35
by AlphaBravo
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
    }

Re: Ask a question about Gui edit

Posted: 08 Dec 2022, 02:36
by yerjoy
Thanks a lot,above two autohotkey programs all function :bravo: :dance:
image.png
image.png (126.21 KiB) Viewed 411 times

Re: Ask a question about Gui edit

Posted: 08 Dec 2022, 02:42
by Rohwedder
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")]
}

Re: Ask a question about Gui edit

Posted: 08 Dec 2022, 02:47
by just me
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

Re: Ask a question about Gui edit

Posted: 08 Dec 2022, 22:34
by yerjoy
Thanks all.Every program is magical and perfectly functional :clap: