Page 1 of 1

ControlGet Line

Posted: 02 Feb 2019, 05:50
by zorg
AutoHotkey version 1.1.30.01

Code: Select all

WinActivate, ahk_class Notepad++
ControlGetFocus, Scintilla, ahk_class Notepad++
ControlGet, count, CurrentLine,, %Scintilla%
Works.

Code: Select all

WinActivate, ahk_class Notepad++
ControlGetFocus, Scintilla, ahk_class Notepad++
ControlGet, count, CurrentCol,, %Scintilla%
Works.

Code: Select all

WinActivate, ahk_class Notepad++
ControlGetFocus, Scintilla, ahk_class Notepad++
ControlGetText, text, %Scintilla%
Works.

Code: Select all

WinActivate, ahk_class Notepad++
ControlGetFocus, Scintilla, ahk_class Notepad++
ControlGet, ln, Line, 10, %Scintilla%
Throws an error (but ErrorLevel = 0).

So, workaround:

Code: Select all

WinActivate, ahk_class Notepad++
ControlGetFocus, Scintilla, ahk_class Notepad++
ControlGetText, text, %Scintilla%
lines := StrSplit(text, "`r`n")
ln := lines[10]

Re: ControlGet Line

Posted: 02 Feb 2019, 06:15
by just me
Where's the bug?
Line

Retrieves the text of line N in an Edit control.

Code: Select all

ControlGet, OutputVar, Line, N , Control, WinTitle, WinText, ExcludeTitle, ExcludeText
Line 1 is the first line. Depending on the nature of the control, OutputVar might end in a carriage return (`r) or a carriage return + linefeed (`r`n). If the specified line number is blank or does not exist, ErrorLevel is set to 1 and OutputVar is made blank.
The Notepad++ main control is not an Edit control.

Re: ControlGet Line

Posted: 02 Feb 2019, 06:45
by zorg

Code: Select all

WinActivate, ahk_class Notepad++
ControlGetFocus, Scintilla, ahk_class Notepad++
Does retrieve an Edit control: ControlGet CurrentLine, ControlGet CurrentCol and ControlGetText work that way.
But not ControlGet Line.

Re: ControlGet Line

Posted: 03 Feb 2019, 03:39
by just me
Every control may respond to (some) common Edit messages, or not.

Re: ControlGet Line

Posted: 03 Feb 2019, 05:40
by zorg
It may be an explanation.
Now I suspect the Notepad++ Scintilla control is a Rich Edit Control, that comes with Unsupported Edit Control Functionalities indeed, but EM_GETLINE is not part of them. So it should be usable by AutoHotkey.

Re: ControlGet Line

Posted: 03 Feb 2019, 07:40
by just me
The Windows version of Scintilla is a Windows Control. As such, its primary programming interface is through Windows messages. Early versions of Scintilla emulated much of the API defined by the standard Windows Edit and RichEdit controls but those APIs are now deprecated in favour of Scintilla's own, more consistent API. In addition to messages performing the actions of a normal Edit control, Scintilla allows control of syntax styling, folding, markers, autocompletion and call tips.

Scintilla Documentation - Introduction

Re: ControlGet Line

Posted: 03 Feb 2019, 08:28
by zorg
That's it. Scintilla is "messages performing the actions of a normal Edit control". Well, maybe not all of them... But it would be surprising if it missed GETLINE.

Re: ControlGet Line

Posted: 03 Feb 2019, 09:14
by nnnik
Well to me it seems that GETLINE is missing.
You might be better off to use the messages for the Scintilla Control directly than using AHK code.

Re: ControlGet Line

Posted: 03 Feb 2019, 10:18
by zorg
Yes it would be great to use the messages for the Scintilla Control directly. But I don't know how to do that in my ahk script :?

Re: ControlGet Line

Posted: 03 Feb 2019, 11:08
by nnnik
There is a wonderful forum thats just about helping people achieve goals like those ->
See: https://www.autohotkey.com/boards/viewforum.php?f=76

Re: ControlGet Line

Posted: 03 Feb 2019, 11:26
by jeeswg
I've added 2 functions, JEE_SciGetTextLine and JEE_SciGetTextSel, here. Cheers.
GUIs via DllCall: text functions (get/set internal/external control text) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40514

Re: ControlGet Line

Posted: 03 Feb 2019, 15:23
by zorg
jeeswg your work is impressive. It is far more advanced than my little workaround of 3 lines.
Thank you guys.