How to use WinAPI windowFromPoint() in script?

English main discussion
Post Reply
  • Author
  • Message
Offline
Posts: 9
Joined: Sat Oct 14, 2017 5:58 am

How to use WinAPI windowFromPoint() in script?

Post by TiderV »

I want to use windowFromPoint to retrieve the handle of window under specified point,
HWND WindowFromPoint(
[in] POINT Point
);
but I tried several methods, all failed to get a correct result.
how to assign the Int64 parameter Point? can you experts help to solver the problem? many many thanks!!!

Code: Select all

function windowFromPoint(nPosX, nPosY){
    //var lpPoint = AkelPad.MemAlloc(8 sizeof(POINT)*/);
    //AkelPad.SendMessage(hWndEdit, 3190 /*AEM_GETCARETPOS*/, lpPoint, 0);
    //oSys.Call("User32::ClientToScreen", hWndEdit, lpPoint);
    //nX = AkelPad.MemRead(_PtrAdd(lpPoint, 0), 3 /*DT_DWORD*/);
    //nY = AkelPad.MemRead(_PtrAdd(lpPoint, 4), 3 /*DT_DWORD);
    //var hwnd = oSys.Call("User32::WindowFromPoint",lpPoint);
    //var hwnd = oSys.Call("User32::WindowFromPoint", 0x000004370000077F); //nPosX=1919 nPosY=1079 
    //var hwnd = oSys.Call("User32::WindowFromPoint",parseInt('0x000004370000077F'))
    var hwnd = oSys.Call("User32::WindowFromPoint", (nPosX&0x00000000FFFFFFFF)|(nPosY << 32));
    var hwnd = oSys.Call("User32::WindowFromPoint", nPosX|(nPosY << 32));
    var hParent = oSys.Call("User32::GetAncestor", hwnd, 2);
    return hParent
}

DV
Offline
Posts: 1294
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: How to use WinAPI windowFromPoint() in script?

Post by DV »

The script "TabSwitch.js" by Instructor contains the following code that uses the POINT structure:

Code: Select all

function GetCursorPos(ptPoint)
{
  var lpPoint;

  ptPoint.x=0;
  ptPoint.y=0;

  if (lpPoint=AkelPad.MemAlloc(8 /*sizeof(POINT)*/))
  {
    if (oSys.Call("user32::GetCursorPos", lpPoint))
    {
      ptPoint.x=AkelPad.MemRead(_PtrAdd(lpPoint, 0) /*offsetof(POINT, x)*/, 3 /*DT_DWORD*/);
      ptPoint.y=AkelPad.MemRead(_PtrAdd(lpPoint, 4) /*offsetof(POINT, y)*/, 3 /*DT_DWORD*/);
    }
    AkelPad.MemFree(lpPoint);
  }
}

DV
Offline
Posts: 1294
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: How to use WinAPI windowFromPoint() in script?

Post by DV »

Additionally, you can download zip-archives with scripts here:
http://akelpad.sourceforge.net/forum/vi ... .php?t=240
and search them for examples of usage of specific Win API structures and methods.

Offline
Posts: 9
Joined: Sat Oct 14, 2017 5:58 am

Post by TiderV »

Hi, DV, thanks for your reply, you guide me found the global index of user defined scripts.
I have tested and found that WindowFromPoint function does not accept a pointer to point as its parameter

Code: Select all

var oSys = AkelPad.SystemFunction();
WScript.Echo(getWinClassName(windowFromPoint(1919, 1079)));
function windowFromPoint(nPosX, nPosY){
	lpPoint=AkelPad.MemAlloc(8 /*sizeof(POINT)*/)
	AkelPad.MemCopy(_PtrAdd( lpPoint, 0) , nPosX, 3/*DT_DWORD*/);
	AkelPad.MemCopy(_PtrAdd( lpPoint, 4) , nPosY, 3/*DT_DWORD*/);
	var hwnd = oSys.Call("User32::WindowFromPoint", lpPoint);
	var hParent = oSys.Call("User32::GetAncestor", hwnd, 2)
    return hParent
}

function getWinClassName(hWnd){
	var lpInfo = AkelPad.MemAlloc(260 * _TSIZE);
	if (oSys.Call("User32::GetClassName" + _TCHAR, hWnd, lpInfo, 260))
		sClass = AkelPad.MemRead(lpInfo, _TSTR);
	else
      sClass = "";
	return sClass;
}
It seems that WindowFromPoint function only accept a unsigned Int64 number as a POINT struct as its parameter
I have test to pass a 8 Byte Hex value but to no avail also

Code: Select all

var hwnd = oSys.Call("User32::WindowFromPoint", 0x000001CA000001CA);	//alwayse got pos(0,0) Win Handle regardless what value assigned
and

Code: Select all

//var hwnd = oSys.Call("User32::WindowFromPoint", 0x000001CA);	//got pos(458,0) Win Handle
seems that AkelPad.SystemFunction() (or javasript Engine) can't successfully interpret a 8 Byte Hex value as UInt64

so the main problem is how to enforce the AkelPad.SystemFunction() to know I passed a UInt64 parameter?

DV
Offline
Posts: 1294
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Post by DV »

Good question. In fact, it is a question of having a 64-bit integer in JScript and passing it from JScript to AkelPad.
I asked Google about 64-bit integers in JScript, and it looks like they are not natively supported by JScript.
I also considered usage of AkelPad's _PtrAdd, but I believe that if 32-bit AkelPad is used then the pointer size is also 32-bit, so it does not help with 64-bit integers...

Offline
Posts: 9
Joined: Sat Oct 14, 2017 5:58 am

Post by TiderV »

DV wrote:Good question. In fact, it is a question of having a 64-bit integer in JScript and passing it from JScript to AkelPad.
I asked Google about 64-bit integers in JScript, and it looks like they are not natively supported by JScript.
I also considered usage of AkelPad's _PtrAdd, but I believe that if 32-bit AkelPad is used then the pointer size is also 32-bit, so it does not help with 64-bit integers...

So this Function can't be used in akelpad? I'm wondering if there is ActiveX or Akelpad built-in conversions available to achieve this...
Post Reply