Hiding the caret in a Gui text control.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Hiding the caret in a Gui text control.

15 Apr 2021, 22:13

Is there a n easy way to hide and unhide the caret for a Gui text control? I didn't find anything in help. I want to be able to display an edit control on a TV monitor and don't want the caret to be seen. Thanks.
User avatar
boiler
Posts: 16974
Joined: 21 Dec 2014, 02:44

Re: Hiding the caret in a Gui text control.

15 Apr 2021, 22:58

How about putting the focus on a control that is outside of the visible GUI window like this:

Code: Select all

Gui, Add, Edit, w300 r8
Gui, Add, Edit, x400 vDummy
Gui, Show, w320 h130
GuiControl, Focus, Dummy
return

GuiClose:
ExitApp
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Hiding the caret in a Gui text control.

15 Apr 2021, 23:07

I use a similar method as the one suggested by @boiler, with the exception that you don't have to use a edit control. As far as I can tell (Haven't come across a control you couldn't force focus on) you can use any control as the target of focus. So a invisible text control for example.

*Edit*
Never tried, but it may actually be possible to set focus to the window itself???

*Edit 2
You may be asking something different than what I was thinking. My impression was that you were trying to make the caret vanish between uses. If the intention is to NEVER see a caret then there is no need to show the a edit at all, you can have a hidden edit like boiler said and just have a text control as your display.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Hiding the caret in a Gui text control.

15 Apr 2021, 23:52

Have tested, can't set the focus to the window (at least not using GuiControl and the guis hwnd).

Ignore edit2, I was right the first time.

Here is a little example that works like a normal edit, but if you click somewhere in the last 10px of the control it will set the focus away from the edit control.

Code: Select all

#SingleInstance,Force

Gui, 1:+AlwaysOnTop -Caption hwndGuiHwnd
Gui, 1:Margin, 0, 0

Gui, 1:Add, Text, x190 ym w10 h0 BackgroundTrans hwndTexthwnd gSetFocus
Gui, 1:Add,Edit, xm ym w200 r1 hwndEdit1Hwnd ,

GuiControlGet, pos, 1:Pos, % Edit1Hwnd 
GuiControl, 1:MoveDraw, % TextHwnd, % "h" PosH

gosub, SetFocus

Gui, 1:Show, x10 y10 , Gui 1

return
*Esc::ExitApp

SetFocus:
	GuiControl, 1:Focus, % Texthwnd 
	return

teadrinker
Posts: 4333
Joined: 29 Mar 2015, 09:41
Contact:

Re: Hiding the caret in a Gui text control.

16 Apr 2021, 00:33

Another way:

Code: Select all

Gui, Add, Edit, w300 h200 hwndhEdit
Gui, Show
Return

$F1:: DllCall(((t := !t) ? "Hide" : "Show") . "Caret", "Ptr", hEdit)
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Hiding the caret in a Gui text control.

16 Apr 2021, 00:59

To hide I‘ve been using:

Code: Select all

DllCall("HideCaret","Int", hEdit)
There’s maybe a DllCall like „UnhideCaret“.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Hiding the caret in a Gui text control.

16 Apr 2021, 01:00

teadrinker wrote:
16 Apr 2021, 00:33
Another way:
Thank you.

Code: Select all

Gui, Add, Edit, HwndEditHwnd
DllCall( "HideCaret" , "Ptr" , EditHwnd )
DllCall( "ShowCaret" , "Ptr" , EditHwnd )
;*For later use
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Hiding the caret in a Gui text control.

18 Apr 2021, 20:34

Thanks for all the replies. I decided to go with hiding the edit control, keeping the focus on the edit control and passing the results to a text control . It worked in my tests.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Bing [Bot], DataLife, ShatterCoder and 224 guests