buymeapc Posted August 10, 2015 Share Posted August 10, 2015 Hi all,So, I found a great post that helped lead me in the right direction to generate line numbers for an edit control. It works great, but I want the edit control to be read-only. As soon as I add the $ES_READONLY style to the edit control, the numbers are no longer generated. Is there a way to use this code from the post to have the line numbers generate as well as having the edit control set as read only? Ultimately, I'm looking to be able to set read only on/off with a hotkey which is CTRL+E (in the replicator). expandcollapse popup#include <GUIConstants.au3> #Include <GUIEdit.au3> $sStuff = "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF $bEditMode = False GUIRegisterMsg($WM_CTLCOLOREDIT, 'WM_CTLCOLOREDIT') $Form1 = GUICreate("Form1", 123, 196, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS)) $cDummy = GUICtrlCreateDummy() $Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetData(-1, "1") GUICtrlSetBkColor(-1, 0xC0DCC0) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUICtrlCreateLabel("CTRL+E to to toggle read only", 0, 180, 123, 16) $Edit_Main = GUICtrlCreateEdit($sStuff, 26, 0, 96, 175, BitOr($GUI_SS_DEFAULT_EDIT, $WS_VSCROLL), 0); This works great!! (but it's not read only) ;~ $Edit_Main = GUICtrlCreateEdit($sStuff, 26, 0, 96, 175, BitOr($GUI_SS_DEFAULT_EDIT, $WS_VSCROLL, $ES_READONLY), 0); This is what I want to work, but read only prevents the numbers from working GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) $Edit_Blank = GUICtrlCreateLabel("", 0, 164, 25, 11) GUICtrlSetBkColor(-1, 0xC0DCC0) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) GUISetState(@SW_SHOW) Local $aAccelKeys[1][2] = [["^e", $cDummy]] GUISetAccelerators($aAccelKeys, $Form1) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cDummy $bEditMode = Not $bEditMode If $bEditMode Then GUICtrlSetStyle($Edit_Main, BitOr($GUI_SS_DEFAULT_EDIT, $WS_VSCROLL)) Else GUICtrlSetStyle($Edit_Main, BitOr($GUI_SS_DEFAULT_EDIT, $WS_VSCROLL, $ES_READONLY)) EndIf EndSwitch WEnd Func WM_CTLCOLOREDIT($hWnd, $iMsg, $iWParam, $iLParam) If $iLParam = GUICtrlGetHandle($Edit_Main) Then Local $iCount = _GUICtrlEdit_GetLineCount ($Edit_Main) Local $iNumCount = _GUICtrlEdit_GetLineCount ($Edit_Num) - 2 If $iCount <> $iNumCount Then Local $sNumContent = '' For $i = 1 To $iCount $sNumContent &= $i & @CRLF Next GUICtrlSetData($Edit_Num, $sNumContent & @CRLF) EndIf Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main) Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num) If $iFirstVisMain <> $iFirstVisNum Then _GUICtrlEdit_LineScroll($Edit_Num, 0, $iFirstVisMain - $iFirstVisNum) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 10, 2015 Moderators Share Posted August 10, 2015 (edited) buymeapc,From MSDN:An edit control that is not read-only or disabled sends the WM_CTLCOLOREDIT message to its parent window when the control is about to be drawnso it looks as if you cannot use this method when the edit is read-only.M23Edit: I found this in my Snippets folder - any use?expandcollapse popup#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, 10, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetData(-1, "1") GUICtrlSetBkColor(-1, 0xC0DCC0) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) $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) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) $cDummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) AdlibRegister("_LineNum", 100) Local $aAccelKeys[1][2] = [["^e", $cDummy]] GUISetAccelerators($aAccelKeys, $hGUI) $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 Case $cDummy $bEditMode = Not $bEditMode If $bEditMode Then ConsoleWrite("Edit mode" & @CRLF) GUICtrlSetStyle($cEdit_Main, $GUI_SS_DEFAULT_EDIT) Else ConsoleWrite("ReadOnly mode" & @CRLF) GUICtrlSetStyle($cEdit_Main, BitOr($GUI_SS_DEFAULT_EDIT, $ES_READONLY)) EndIf 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 Edited August 10, 2015 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
buymeapc Posted August 10, 2015 Author Share Posted August 10, 2015 Well, that certainly stinks, but thank you for confirming my suspicions...Is there a way around this? I've tried creating a transparent label that's the same size of the edit control (minus the width of the scroll bars) to overlay it, but it always ends up behind the edit control instead of on top even though I've stipulated the $GUI_ONTOP style. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 10, 2015 Moderators Share Posted August 10, 2015 buymeapc,Did you see the code I added in the edit above?M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
buymeapc Posted August 10, 2015 Author Share Posted August 10, 2015 Ah, just saw your edit now. Thank you for finding that.I checked it out and it is useful, however it doesn't have the ability to make the line numbers scroll along with the edit scrolling unfortunately - that's why I loved the WM_CTLCOLOREDIT function.I really hate to be that "have my cake and eat it, too" kind of guy, but there has to be a way around this......no? Link to comment Share on other sites More sharing options...
buymeapc Posted August 10, 2015 Author Share Posted August 10, 2015 (edited) Thanks to you finding that MSDN quote, I stumbled across a way to eat that yummy cake If I replicate the WM_CTLCOLOREDIT function with the name of WM_CTLCOLORSTATIC, that takes care of the read only scrolling as this new function will scroll the read only control. I'm not too fond of using the same code in two different areas, but heck, it gets the job done.Thank you so much for the help!!expandcollapse popup#include <GUIConstants.au3> #Include <GUIEdit.au3> $sStuff = "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF & _ "Blah" & @CRLF $bEditMode = False GUIRegisterMsg($WM_CTLCOLOREDIT, 'WM_CTLCOLOREDIT') GUIRegisterMsg($WM_CTLCOLORSTATIC, 'WM_CTLCOLORSTATIC') $Form1 = GUICreate("Form1", 123, 196, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS)) $cDummy = GUICtrlCreateDummy() $Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetData(-1, "1") GUICtrlSetBkColor(-1, 0xC0DCC0) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUICtrlCreateLabel("CTRL+E to toggle read only", 0, 180, 123, 16) $Edit_Main = GUICtrlCreateEdit($sStuff, 26, 0, 96, 175, BitOr($GUI_SS_DEFAULT_EDIT, $WS_VSCROLL), 0); This works great!! (but it's not read only) ;~ $Edit_Main = GUICtrlCreateEdit($sStuff, 26, 0, 96, 175, BitOr($GUI_SS_DEFAULT_EDIT, $WS_VSCROLL, $ES_READONLY), 0); This is what I want to work, but read only prevents the numbers from working GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) $Edit_Blank = GUICtrlCreateLabel("", 0, 164, 25, 11) GUICtrlSetBkColor(-1, 0xC0DCC0) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKSIZE) GUISetState(@SW_SHOW) Local $aAccelKeys[1][2] = [["^e", $cDummy]] GUISetAccelerators($aAccelKeys, $Form1) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cDummy $bEditMode = Not $bEditMode If $bEditMode Then GUICtrlSetStyle($Edit_Main, BitOr($GUI_SS_DEFAULT_EDIT, $WS_VSCROLL)) Else GUICtrlSetStyle($Edit_Main, BitOr($GUI_SS_DEFAULT_EDIT, $WS_VSCROLL, $ES_READONLY)) EndIf EndSwitch WEnd Func GUICtrlEdit_Scroll($hWnd, $hWnd_Num) Local $iCount = _GUICtrlEdit_GetLineCount($hWnd) Local $iNumCount = _GUICtrlEdit_GetLineCount($hWnd_Num) - 2 If $iCount <> $iNumCount Then Local $sNumContent = '' For $i = 1 To $iCount $sNumContent &= $i & @CRLF Next GUICtrlSetData($hWnd_Num, $sNumContent & @CRLF) EndIf Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine($hWnd) Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine($hWnd_Num) If $iFirstVisMain <> $iFirstVisNum Then _GUICtrlEdit_LineScroll($hWnd_Num, 0, $iFirstVisMain - $iFirstVisNum) EndIf EndFunc Func WM_CTLCOLOREDIT($hWnd, $iMsg, $iWParam, $iLParam) If $iLParam = GUICtrlGetHandle($Edit_Main) Then GUICtrlEdit_Scroll($Edit_Main, $Edit_Num) EndIf Return $GUI_RUNDEFMSG EndFunc Func WM_CTLCOLORSTATIC($hWnd, $iMsg, $iWParam, $iLParam) If $iLParam = GUICtrlGetHandle($Edit_Main) Then GUICtrlEdit_Scroll($Edit_Main, $Edit_Num) EndIf Return $GUI_RUNDEFMSG EndFunc Edited August 10, 2015 by buymeapc Better function usage in code Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 10, 2015 Moderators Share Posted August 10, 2015 buymeapc,No need for 2 handlers - just register both messages to the same function.M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
buymeapc Posted August 10, 2015 Author Share Posted August 10, 2015 ....Wow, I never would have thought of that...brilliant! Thanks again! 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