Gui Edit text flickering issue

Report problems with documented functionality
autoexec
Posts: 23
Joined: 20 Feb 2023, 22:38

Gui Edit text flickering issue

Post by autoexec » 10 Mar 2024, 08:34

This problem occurs when using the FileSelect with the OwnDialogs.

Testing code:

Code: Select all

MyGui := Gui()
MyGui.AddEdit("w200 h100", "Sample Text 1`nSample Text 1")
MyGui.AddEdit("wp hp", "Sample Text 2`nSample Text 2")
MyGui.AddButton("w100", "FileSelect").OnEvent("Click", (*) => (MyGui.Opt("+OwnDialogs"), FileSelect()))
MyGui.AddButton("wp", "DirSelect").OnEvent("Click", (*) => (MyGui.Opt("+OwnDialogs"), DirSelect())) ; No problem
MyGui.AddButton("wp", "MsgBox").OnEvent("Click", (*) => (MyGui.Opt("+OwnDialogs"), MsgBox())) ; No problem
MyGui.AddButton("wp", "InputBox").OnEvent("Click", (*) => (MyGui.Opt("+OwnDialogs"), InputBox())) ; No problem
MyGui.OnEvent("Close", (*) => ExitApp())
MyGui.Show("x200 y200")
Click the "FileSelect" button, then click the Cancel button (or press Esc key).
You can see that the text in the 1st Edit control is quickly selected and deselected.
Other dialogs (DirSelect, MsgBox and InputBox) do not have this behavior.

Marium0505
Posts: 40
Joined: 11 May 2020, 20:45

Re: Gui Edit text flickering issue

Post by Marium0505 » 10 Mar 2024, 09:00

I solved this by either adding the -Tabstop option to the edit control(s) or by adding a new invisible edit control first (with optons w0 h0 to hide it).
It's likely because the edit control gets focus.

The downside with the -Tabstop option is that it, as it''s supposed to, will prevent the user from navigating to it with the tab key, in that case you can add use the other alternative (add a hidden edit control which will get focus instead):

Code: Select all

MyGui.AddEdit("0 h0", "")
I personally don't think this is a bug, but how things are supposed to work.

autoexec
Posts: 23
Joined: 20 Feb 2023, 22:38

Re: Gui Edit text flickering issue

Post by autoexec » 12 Mar 2024, 21:20

Thanks for the tip. but I don't think that adding "-Tabstop" or an invisible control is the right solution for that.
Maybe we can find a better way.

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Gui Edit text flickering issue

Post by lexikos » 14 Mar 2024, 03:58

You can see that the text in the 1st Edit control is quickly selected and deselected.
No, I can't. Spy++ indicates that the Edit control is gaining and losing focus, but on my system it happens instantly and has no visible effect.

FileSelect does nothing with focus or activation except activate the dialog when it is first shown.

AutoHotkey is not responsible for reactivating the GUI when the dialog closes or restoring focus to the Button control; both parts are handled by the system.

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

Re: Gui Edit text flickering issue

Post by just me » 14 Mar 2024, 05:39

I can clearly see it. It only happens in combination with (MyGui.Opt("+OwnDialogs").

neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: Gui Edit text flickering issue

Post by neogna2 » 14 Mar 2024, 15:40

I see it too. But it goes away if we also set MyGui.Opt("+E0x02000000") ; WS_EX_COMPOSITED

autoexec
Posts: 23
Joined: 20 Feb 2023, 22:38

Re: Gui Edit text flickering issue

Post by autoexec » 14 Mar 2024, 22:11

MyGui.Opt("+E0x02000000") ; WS_EX_COMPOSITED
Thank you for good tip. It works well when I press the button to open the FileSelect.
Also, I found another strange thing when opening the FileSelect with a hot key.

Here's test code:

Code: Select all

MyGui := Gui("+E0x02000000") ; WS_EX_COMPOSITED
Edit1 := MyGui.AddEdit("w200 h100", "Sample Text 1`nSample Text 1")
MyGui.AddEdit("wp hp", "Sample Text 2`nSample Text 2")
MyGui.AddText(, "Press F1 to FileSelect")
MyGui.OnEvent("Close", (*) => ExitApp())
MyGui.Show("x200 y200")
SendMessage 0x00B1, -2, -1, Edit1 ; Deselects the text

F1::
{
	MyGui.Opt("+OwnDialogs")
	FileSelect
}
If I open the FileSelect by pressing the "F1" key and then close it, while the 1st edit control is focused and its text is not selected, the text in the 1st edit control is automatically selected.
no such problem happens in the 2nd edit control.
I think this is a minor issue but it's weird.

neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: Gui Edit text flickering issue

Post by neogna2 » 15 Mar 2024, 07:17

autoexec wrote:
14 Mar 2024, 22:11
If I open the FileSelect by pressing the "F1" key and then close it, while the 1st edit control is focused and its text is not selected, the text in the 1st edit control is automatically selected.
no such problem happens in the 2nd edit control.
I think this is a minor issue but it's weird.
Puzzling. On my PC with AutoHotkey 2.0.11 and Windows 10 the effect is different. If I focus the first edit control, press F1 and then close the "select file" window then the text in the first edit becomes selected. So on my system it for some reason makes a difference if FileSelect is called from a F1 hotkey compared to from a Gui Button control's OnEvent("Click").

autoexec
Posts: 23
Joined: 20 Feb 2023, 22:38

Re: Gui Edit text flickering issue

Post by autoexec » 15 Mar 2024, 10:29

neogna2 wrote:
I meant that the first edit control text becomes unintentionally selected when the FileSelect window is opened and closed. It seems like that you have seen the same thing.

neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: Gui Edit text flickering issue

Post by neogna2 » 17 Mar 2024, 03:54

autoexec wrote:
15 Mar 2024, 10:29
neogna2 wrote:
I meant that the first edit control text becomes unintentionally selected when the FileSelect window is opened and closed. It seems like that you have seen the same thing.
Yeah I see now, apologies I misread earlier. I wonder what explains that with WS_EX_COMPOSITED the text selection happens when we close a FileSelect window that was created from a F1 hotkey but not one created from a control's OnEvent("Click").

One workaround you could try is to create a hidden dummy before the first edit control
MyGui.AddEdit("w0 h0 +ReadOnly")

neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: Gui Edit text flickering issue

Post by neogna2 » 17 Mar 2024, 05:51

One more observation. With this code

Code: Select all

MyGui := Gui("+E0x02000000") ; WS_EX_COMPOSITED
Edit1 := MyGui.AddEdit("w200 h100", "Sample Text 1`nSample Text 1")
MyGui.AddEdit("wp hp", "Sample Text 2`nSample Text 2")
MyGui.AddText(, "Press F1 to FileSelect")
MyGui.OnEvent("Close", (*) => ExitApp())
MyGui.AddButton("w100", "FileSelect").OnEvent("Click", (*) => (MyGui.Opt("+OwnDialogs"), FileSelect()))
MyGui.Show("x200 y200")
SendMessage 0x00B1, -2, -1, Edit1 ; Deselects the text

F1:: MyGui.Opt("+OwnDialogs") FileSelect()
if we first press F1 and close the popup Edit1's text is selected.
If we instead first press the button, close the popup, then press F1 and close the popup again then Edit1's text is *not* selected.
Edit: Nope, I was wrong, sorry. When we press the button focus shifts from Edit1 to the button. That's why a subsequent F1 doesn't select the text when the popup closes. But if we press the button, close the popup, then click to focus Edit1 again, then press F1 and finally close the popup the result is the same as before: the text in Edit1 gets selected.

Post Reply

Return to “Bug Reports”