philw Posted May 1, 2008 Share Posted May 1, 2008 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! Link to comment Share on other sites More sharing options...
someone Posted May 1, 2008 Share Posted May 1, 2008 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 Link to comment Share on other sites More sharing options...
philw Posted May 2, 2008 Author Share Posted May 2, 2008 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! Link to comment Share on other sites More sharing options...
rasim Posted May 2, 2008 Share Posted May 2, 2008 philwThis? Link to comment Share on other sites More sharing options...
philw Posted May 3, 2008 Author Share Posted May 3, 2008 philwThis?Works perfectly. Problem solved. Thanks very much for that, Rasim! Link to comment Share on other sites More sharing options...
philw Posted May 9, 2008 Author Share Posted May 9, 2008 (edited) 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 May 9, 2008 by philw Link to comment Share on other sites More sharing options...
rasim Posted May 10, 2008 Share Posted May 10, 2008 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 Link to comment Share on other sites More sharing options...
philw Posted May 13, 2008 Author Share Posted May 13, 2008 (edited) 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 May 13, 2008 by philw Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now