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?
EM_SCROLLCARET
- Author
- Message
-
Offline
- Posts: 1348
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: EM_SCROLLCARET
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);-
Offline
- Posts: 294
- Joined: Thu Sep 10, 2015 9:53 am
- Location: Deutschland
Re: EM_SCROLLCARET
How to calculate the (variable) width of the line-number margin in pixels
based on text length: 9 lines, 99, 100, 1000, etc.
based on text length: 9 lines, 99, 100, 1000, etc.
-
Offline
- Posts: 1348
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: EM_SCROLLCARET
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);-
Offline
- Posts: 1348
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: EM_SCROLLCARET
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;
}
-
Offline
- Posts: 294
- Joined: Thu Sep 10, 2015 9:53 am
- Location: Deutschland
Re: EM_SCROLLCARET
Thank you