开发者

How to get text indent (tabs) from some text input?

开发者 https://www.devze.com 2022-12-09 15:00 出处:网络
For example, suppose I\'m editing following text (\\t is for tabs, it\'s not text) \'\\t\\t\\tSome text...\'

For example, suppose I'm editing following text (\t is for tabs, it's not text) '\t\t\tSome text...' and my input keyboard position is right before 'S' (there is no selected text) and I want to get number of tabs before 'S' (in this case it's 3)

So how to get that number of tabs using Win32 API?

p.s. Maybe some function to get whole current line (and then parse that text)?

edit: So I want my program (that is running in background and does开发者_如何学C not have a GUI) to determine number of tabs from current active line in any text editor that is currently active (that I'm editing in).


For some applications such as the standard Windows Notepad, it may be possible to do this from another application. Notepad itself is little more than big Win32 "Edit" control inside a resizeable window, so all the regular Win32 Edit control messages can be used to get the actual text and the caret position and so on.

However, in the general case of any Windows text editor, there is no requirement for applications to use a Win32 Edit control for their text editing needs (and in fact, to do so would be just reinventing Notepad). There is no standard Win32 API method to find out where the caret is pointing, because the application is free to draw text on the screen in any way it sees fit (and will store that text internally inside the application with no corresponding API for you to call).


Best Java coding practice is to make your code operating system platform independent as far as possible. If you are trying to implement a utility that is intrinsically Windows specific (e.g. heavily dependent on Win32 APIs), it would be better to use C++ or C# rather than Java.

0

精彩评论

暂无评论...
验证码 换一张
取 消