Sign in to follow this  
Followers 0
philw

Retaining higlighted text in multi-line edit contro when another control is clicked

3 posts in this topic

Hi,

I have three controls in a window, a multi-line edit control, a list and a button. I want to highlight a few lines of text in the edit control, click on an item in the list and then click on the button. When the button is clicked, a function applies the item selected in the list to the highlighted text.

However, as soon as I click on the list, the highlighting in the edit control vanishes, and _GUICtrlEdit_GetSel returns an empty string. Any way of preventing this?

Thanks!

Share this post


Link to post
Share on other sites



philw

Try this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Global $aSelect

$hGUI = GUICreate("Test", 300, 280)

$ctlList = GUICtrlCreateList("MyListBox", 10, 10, 280, 100)

$ctlEdit = GUICtrlCreateEdit("Hello world!", 10, 120, 280, 100)

$button = GUICtrlCreateButton("Test", 11, 245, 75, 23)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState()

Do
Until GUIGetMsg() = -3

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0x0000FFFF)
    Local $iCode = BitShift($wParam, 16)
    
    Switch $iIDFrom
        Case $ctlEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    $aSelect = _GUICtrlEdit_GetSel($iIDFrom)
                Case $EN_SETFOCUS
                    If IsArray($aSelect) Then
                        _GUICtrlEdit_SetSel($iIDFrom, $aSelect[0], $aSelect[1])
                        $aSelect = 0
                    EndIf
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

:mellow:

Share this post


Link to post
Share on other sites

Hi,

I have three controls in a window, a multi-line edit control, a list and a button. I want to highlight a few lines of text in the edit control, click on an item in the list and then click on the button. When the button is clicked, a function applies the item selected in the list to the highlighted text.

However, as soon as I click on the list, the highlighting in the edit control vanishes, and _GUICtrlEdit_GetSel returns an empty string. Any way of preventing this?

Thanks!

ES_NOHIDESEL

When ES_NOHIDESEL is specified for an edit control, selected text remains highlighted when the edit control does not have the focus. Normally, without ES_NOHIDESEL specified, an edit control "hides" the selection when it loses focus. In other words, the selection is not highlighted, but the text still appears as normal.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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  
Followers 0