Jump to content

Edit control showing line number


Mingre
 Share

Recommended Posts

Yes _GUICtrlRichEdit would do that you could also colour specific words using richedit give a look on the help file for further informtion.

for more help feel free to ask :)

No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Link to comment
Share on other sites

#include <GuiRichEdit.au3>
_GUICtrlRichEdit_Create ( $hWnd, $sText, $iLeft, $iTop [, $iWidth = 150 [, $iHeight = 150 [, $iStyle = -1 [, $iExStyle = -1]]]] )

 

Examplein the help file:

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGui, $hRichEdit, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is more text")
    GUISetState(@SW_SHOW)

    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

may i know what exactly you want.Are you trying to make an editor like scite

No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Link to comment
Share on other sites

so you want to embedd  a number list to an edit control?

 

Try creating a new gui over the first one which has the number controls.

Edited by Surya

No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Link to comment
Share on other sites

  • Moderators

mingre,

This is how I did it some years ago:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Include <GuiEdit.au3>

;Global $bEditMode = True

Global $iLineCount = 0 ; Keep a global count so we can check if it has changed

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

$cEdit_Num = GUICtrlCreateEdit("", 10, 13, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)

$cEdit_Main = GUICtrlCreateEdit("", 36, 10, 96, 175)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 10, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)

GUISetState(@SW_SHOW)

AdlibRegister("_LineNum", 100)

$sStuff = ""
For $i = 1 To 20
    GUICtrlSetData($cEdit_Main, "Blah " & $i & @CRLF, 1)
    Sleep(250)
Next

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch



WEnd



Func _LineNum() ; line numbering
    Local $iCount = _GUICtrlEdit_GetLineCount ($cEdit_Main)

    ;Check if the number of lines has changed in $cEdit_Main
    ;since this function was last called
    If $iCount <> $iLineCount Then
        ;save the new count to the global variable
        $iLineCount = $iCount

        Local $iNumCount = _GUICtrlEdit_GetLineCount ($cEdit_Num)
        If $iLineCount > $iNumCount Then
            For $i = $iNumCount + 1 To $iLineCount

                _GUICtrlEdit_AppendText ($cEdit_Num, @CRLF & $i)
            Next
        ElseIf $iLineCount < $iNumCount Then
            $text = GUICtrlRead($cEdit_Num)
            For $i = $iNumCount To $iLineCount + 1 Step -1
                $text = StringReplace($text,@CRLF & $i,"")
            Next
            GUICtrlSetData($cEdit_Num, $text)
        EndIf

    EndIf

    Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine ($cEdit_Main)
    Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine ($cEdit_Num)
    If $iFirstVisMain <> $iFirstVisNum Then
        _GUICtrlEdit_LineScroll($cEdit_Num, 0, $iFirstVisMain - $iFirstVisNum)
    EndIf
EndFunc

I will look at how I might update the code to use a message handler rather than Adlib.

M23

Edit: And here it is:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Include <GuiEdit.au3>

; Create flag
$bEditChanged = False

Global $iLineCount = 0 ; Keep a global count so we can check if it has changed

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

$cEdit_Num = GUICtrlCreateEdit("", 10, 13, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)

$cEdit_Main = GUICtrlCreateEdit("", 36, 10, 96, 175)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 10, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

; Example code only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$iNewLine = 1
$nBegin = TimerInit()
; End of example code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; If flag set
    If $bEditChanged Then
        ; Adjust numbering if required
        _LineNum()
        ; Clear flag
        $bEditChanged = False
    EndIf

; Example code only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ; Add 20 lines - once every 250 msecs
    If TimerDiff($nBegin) > 250 And $iNewLine < 20 Then
        ; Add a line to show it working
        GUICtrlSetData($cEdit_Main, "Blah " & $iNewLine & @CRLF, 1)
        ; Increase count
        $iNewLine += 1
        ; Reset timer
        $nBegin = TimerInit()
    EndIf
; End of example code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

WEnd

Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam)

    ; If it was an update message from the edit
    If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $cEdit_Main Then
        ; Set the label to the new data
        $bEditChanged = True
    EndIf

EndFunc   ;==>_WM_COMMAND

Func _LineNum() ; line numbering
    Local $iCount = _GUICtrlEdit_GetLineCount ($cEdit_Main)

    ;Check if the number of lines has changed in $cEdit_Main
    ;since this function was last called
    If $iCount <> $iLineCount Then
        ;save the new count to the global variable
        $iLineCount = $iCount
        Local $iNumCount = _GUICtrlEdit_GetLineCount ($cEdit_Num)
        If $iLineCount > $iNumCount Then
            For $i = $iNumCount + 1 To $iLineCount
                _GUICtrlEdit_AppendText ($cEdit_Num, @CRLF & $i)
            Next
        ElseIf $iLineCount < $iNumCount Then
            $text = GUICtrlRead($cEdit_Num)
            For $i = $iNumCount To $iLineCount + 1 Step -1
                $text = StringReplace($text,@CRLF & $i,"")
            Next
            GUICtrlSetData($cEdit_Num, $text)
        EndIf
    EndIf
    Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine ($cEdit_Main)
    Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine ($cEdit_Num)
    If $iFirstVisMain <> $iFirstVisNum Then
        _GUICtrlEdit_LineScroll($cEdit_Num, 0, $iFirstVisMain - $iFirstVisNum)
    EndIf
EndFunc

 

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...