Jump to content
Sign in to follow this  
philw

Text highlighted problem

Recommended Posts

philw

I have a program containing an edit control. When I click on another program from the task bar and then go back to my original one, all the text in the edit control is highlighted. The scroll position is still as it was, but clicking the edit control to remove the highlighting means that the original caret position is lost. Any way to prevent this happening?

Thanks!

Share this post


Link to post
Share on other sites
someone

Have you checked out WinGetCaretPos in the helpfile? Maybe try using it to nab the caret position before you click away from the edit control and restore it after.

Let us know how that works for you


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites
philw

Have you checked out WinGetCaretPos in the helpfile? Maybe try using it to nab the caret position before you click away from the edit control and restore it after.

Let us know how that works for you

WinGetCaretPos() seems to return some bizarre coordinates that I couldn't connect with the caret position on the screen. Which probably means I didn't understand the Help File! However, your suggestion got me thinking, and something along the lines of:

Opt("GUIOnEventMode",1)

Dim $select[2]
Global $winflag=1

While 1
  Sleep(100)
  If WinActive($hWindow)=1 AND $winflag=0 Then  
    _GUICtrlEdit_SetSel($hEdit,$select[0],$select[1])
    $winflag=1
  ElseIf WinActive($hWindow)=0 AND $winflag=1 Then
    $select=_GUICtrlEdit_GetSel($hEdit)
    $winflag=0
  EndIf
WEnd

works. There's a bit of a flicker when the window regains focus, as first all the text is selected and then _GUICtrlEdit_SetSel() kicks in, but I can live with that!

Thanks for your help on this one!

Share this post


Link to post
Share on other sites
philw

philw

This?

Works perfectly. Problem solved. Thanks very much for that, Rasim!

Share this post


Link to post
Share on other sites
philw

A further quick question. I have two tabs, each containing an edit control. If I highlight, let's say the first five characters in tab1, then click on the other tab, the first five characters are highlighted there too.

Could the script you provided above be modified to stop this happening as well?

Edited by philw

Share this post


Link to post
Share on other sites
rasim

A further quick question. I have two tabs, each containing an edit control. If I highlight, let's say the first five characters in tab1, then click on the other tab, the first five characters are highlighted there too.

Could the script you provided above be modified to stop this happening as well?

Don`t see this problem, work fine for me:

#include <GUIConstants.au3>

$hGUI = GUICreate("Test GUI", 300, 200)

$hTab = GUICtrlCreateTab(10, 10, 280, 180, $TCS_FIXEDWIDTH)

$TabItem_1 = GUICtrlCreateTabItem("TabItem 1")

$Edit_1 = GUICtrlCreateEdit("Hello world", 50, 50, 100, 100)

$TabItem_2 = GUICtrlCreateTabItem("TabItem 2")

$Edit_2 = GUICtrlCreateEdit("Hello world", 50, 50, 100, 100)

GUICtrlCreateTabItem("")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites
philw

Don`t see this problem, work fine for me:

#include <GUIConstants.au3>

$hGUI = GUICreate("Test GUI", 300, 200)

$hTab = GUICtrlCreateTab(10, 10, 280, 180, $TCS_FIXEDWIDTH)

$TabItem_1 = GUICtrlCreateTabItem("TabItem 1")

$Edit_1 = GUICtrlCreateEdit("Hello world", 50, 50, 100, 100)

$TabItem_2 = GUICtrlCreateTabItem("TabItem 2")

$Edit_2 = GUICtrlCreateEdit("Hello world", 50, 50, 100, 100)

GUICtrlCreateTabItem("")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

(Apologies for not replying before. Just back from holiday!)

I tried adding everything in my script that seemed as though it might have an effect to yours, and it still worked correctly. Don't know WHAT I'm doing to copy the highlighting from one tab to the other.

The problem script is at http://www.southernwalks.co.uk/hedit.zip. There's a compiled version, so you can see what's happening.

Edited by philw

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×