Page 1 of 1
EM_SCROLLCARET
Posted: Mon Jul 20, 2026 7:23 am
by sexy96
How can I read the number of the first visible line in the AkelPad window using a .js script?
How do I determine the cursor's position within the text in terms of X and Y pixels?
Re: EM_SCROLLCARET
Posted: Mon Jul 20, 2026 6:13 pm
by DV
Code: Select all
function Edit_GetFirstVisibleLine(hEd)
{
var nLine = AkelPad.SendMessage(hEd, EM_GETFIRSTVISIBLELINE, 0, 0);
return AkelPad.SendMessage(hEd, AEM_GETUNWRAPLINE, nLine, 0);
}
Code: Select all
var lpPoint = AkelPad.MemAlloc(8 /*sizeof(POINT)*/);
var oSys = AkelPad.SystemFunction();
oSys.Call("User32::GetCaretPos", lpPoint);
oSys.Call("User32::ClientToScreen", hWnd, lpPoint);
var nPosX = AkelPad.MemRead(_PtrAdd(lpPoint, 0), 3 /*DT_DWORD*/);
var nPosY = AkelPad.MemRead(_PtrAdd(lpPoint, 4), 3 /*DT_DWORD*/);
AkelPad.MemFree(lpPoint);
Re: EM_SCROLLCARET
Posted: Tue Jul 21, 2026 11:45 am
by sexy96
How to calculate the (variable) width of the line-number margin in pixels
based on text length: 9 lines, 99, 100, 1000, etc.
Re: EM_SCROLLCARET
Posted: Tue Jul 21, 2026 1:05 pm
by DV
sexy96 wrote: ↑Tue Jul 21, 2026 11:45 amHow to calculate the (variable) width of the line-number margin in pixels
That's not easy to do. You need to work directly with WinAPI.
You may use the approach similar to the function `getRequiredWidthAndHeight` here:
https://github.com/d0vgan/AkelPad-Scrip ... te.js#L606
That function uses the following two parameters:
Code: Select all
var hWndEdit = AkelPad.GetEditWnd();
var hFontEdit = AkelPad.SendMessage(hWndEdit, WM_GETFONT, 0, 0);
Re: EM_SCROLLCARET
Posted: Tue Jul 21, 2026 1:15 pm
by DV
Depending on your actual needs, there may be a much easier solution mentioned in "AkelPad\AkelFiles\Docs\LineBoard-Eng.txt" :
Code: Select all
WScript.Echo(GetBoardWidth(AkelPad.GetEditWnd(), 0));
function GetBoardWidth(hWndEdit, hDocEdit)
{
var lpRect;
var nWidth=0;
if (lpRect=AkelPad.MemAlloc(16 /*sizeof(RECT)*/))
{
AkelPad.CallW("LineBoard::Main", 11, hWndEdit, hDocEdit, lpRect);
nWidth=AkelPad.MemRead(lpRect + 0 /*offsetof(RECT, left)*/, 3 /*DT_DWORD*/);
AkelPad.MemFree(lpRect);
}
return nWidth;
}
Re: EM_SCROLLCARET
Posted: Tue Jul 21, 2026 6:19 pm
by sexy96
Thank you