在记事本++插件中获取当前光标位置
Getting current cursor pos within notepad++ plugin
我正在尝试获取光标所在的行号。但是我没有找到直接的方法就可以获得线路。相反,我正在尝试获取当前位置,然后使用 SCI_LINEFROMPOSITION
将其转换为行。
::SendMessage(nppData._nppHandle,SCI_GETCURRENTPOS,0,(LPARAM)&first);
::SendMessage(nppData._scintillaMainHandle,SCI_GETCURRENTPOS,0,(LPARAM)&second);
::SendMessage(nppData._scintillaSecondHandle,SCI_GETCURRENTPOS,0,(LPARAM)&third);
这些调用中的每一个都不会更改最后一个参数的值。不幸的是,我没有找到SCI_GETCURRENTPOS
的例子.我能够将文本插入到文件中,以便我可以通过这种方式检查值:
std::wstringstream wss;
wss << "First value read" << first << std::endl;
wss << "Second value read" << second << std::endl;
wss << "Third value read" << third << std::endl;
insertTextIntoCurrentFile(wss.str().c_str());
我应该如何获得当前线路?在这种情况下,预期的HWND
是发送SendMessage
?
以下答案是您最初的问题和您自己的答案的组合的澄清版本(这就是导致我找到这个完整解决方案的原因)。
// Position of the cursor in the entire buffer
int cursorPosition = ::SendMessage(nppData._scintillaMainHandle, SCI_GETCURRENTPOS, 0, 0);
// Line position of the cursor in the editor
int currentLine = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTLINE, 0, 0);
// Column position of the cursor in the editor
int currentColumn = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTCOLUMN, 0, 0);
我能够通过搜索记事本加讨论来解决这个问题。答案是从 SendMessage
读取返回值。
获得 Scintilla HWND
:
int currentEdit;
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)¤tEdit);
HWND curScint = (currentEdit == 0 ) ?
nppData._scintillaMainHandle:nppData._scintillaSecondHandle;
获取当前光标位置:
int cursorPosition = ::SendMessage(curScint,SCI_GETCURRENTPOS,0,0);
这是一种无需调用 SendMessage()
的方法,只需使用标准 Scintilla API 中的方法 – 伪代码如下:
currentLineNumber = editor.SCI_LINEFROMPOSITION(editor.SCI_GETCURRENTPOS())
这对于将代码保持在更高级别或用于其他语言(如 N++ Python 脚本插件)的脚本非常有用,在这些语言中,调用记录的 API 很容易,但SendMessage()
方法可能更困难。(经过测试 - 它有效。
相关文章:
- 如何在QML中设置鼠标光标位置
- 当光标位置在编辑控件 MFC 中更改时是否有通知代码?
- 将光标位置存储在类对象中(ncurses c++)
- 在系统设置光标位置之前获取和设置光标位置?
- 在重新居中之前获取游戏中的光标位置
- 尝试在自定义 QT 创建器文本编辑器中创建查找和替换循环.我似乎无法设置光标位置
- 如何在应用程序窗口中设置光标位置?(C )
- 如何在Qwidget上获取当前的鼠标光标位置
- 如何在 c++ 控制台应用程序中控制光标位置
- 如何使用 Gtkmm 获取光标位置
- C++如何获取当前光标位置
- 在Embarcadero Tools API中的光标位置插入文本
- 光标位置 在控制台上需要有关此代码的帮助
- 在记事本++插件中获取当前光标位置
- 在Qt中如何处理相对于光标位置的光标形状
- 在linux终端中获取光标位置和终端大小
- 如何从最后一个光标位置读取文件
- 信号编辑文本已更改为可编辑的QComboBox设置光标位置在设置编辑文本之后的末尾
- 如何为标准输出设置控制台光标位置
- 获取当前光标位置