EM_EXLINEFROMCHAR 参数的含义

Meaning of the parameters for EM_EXLINEFROMCHAR

EM_EXLINEFROMCHAREM_LINEFROMCHAR 的参数不同。

虽然我可以找到后者的例子,但前者没有产生任何有用的链接。

我想知道的是 - 如果我像在 EM_LINEFROMCHAR 中那样将 -1 传递给 EM_EXLINEFROMCHAR 插入符号所在的当前行,它是否会正常工作。不幸的是,MSDN 没有解释它。

TIA!!

不幸的是,EM_EXLINEFROMCHAR 的文档仅说明了以下有关输入参数的内容:

wParam
This parameter is not used; it must be zero

lParam
Zero-based index of the character.

没有提到是否允许-1,所以不能保证它是否有效。最好不要冒险。干脆不传-1,传实际的插入符位置,用EM_GETSEL or EM_EXGETSEL很简单,eg:

DWORD pos = 0;
SendMessage(hwnd, EM_GETSEL, (WPARAM)&pos, 0);
int lineIndex = SendMessage(hwnd, EM_EXLINEFROMCHAR, 0, pos);
CHARRANGE rng = {};
SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&rng);
int lineIndex = SendMessage(hwnd, EM_EXLINEFROMCHAR, 0, rng.cpMin);

EM_LINEFROMCHAR 已明确记录,因此合同有义务接受 -1 作为输入:

wParam
The character index of the character contained in the line whose number is to be retrieved. If this parameter is -1, EM_LINEFROMCHAR retrieves either the line number of the current line (the line containing the caret) or, if there is a selection, the line number of the line containing the beginning of the selection.

lParam
This parameter is not used.

int lineIndex = SendMessage(hwnd, EM_LINEFROMCHAR, (WPARAM)-1, 0);