Window name under cursor?

Started by rw_baker, February 05, 2016, 06:01:57 AM

Previous topic - Next topic

rw_baker

I have been looking for a general way to find the name of the window which is under the cursor.
I thought of MouseInfo(0), however when the cursor is over a button, then it returns the button name.
I suspect that this is obvious, but I can't see how.

Thanks,

RW Baker

td

Assuming you mean that you want the name of the top level window under the mouse cursor instead of the child window, use MouseInfo(1).   You can find more information in the function's documentation in the Consolidated WIL Help file.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

rw_baker

If I run a script as follows:

message("test","test")
exit

With the cursor over any part of the message window other than the button "OK", I get what I want, i.e., "test".
With the cursor over "OK", MouseInfo(0) reports "OK", and MouseInfo(1) reports the full path of the script that created the message.

When I place the cursor anywhere over the above window I would like to get "test".

Thanks,
RW Baker

td

So you want both top-level and popup windows.  That is a bit trickier.  Here is one approach:

Code (winbatch) Select
AddExtender("wwctl44i.dll", 0, "wwctl64i.dll")       
WS_POPUP = -2147483648
hUser32 = DllLoad("user32.dll")
BoxOpen("Window Under Mouse Pointer","")
hParent  = 0

;; Loop until user quits.
while 1
   lInfo = MouseInfo(3)
   nScreenX = ItemExtract(1, lInfo,  " ")
   nScreenY = ItemExtract( 2, lInfo," ")

   ; Use Win32 API to obtain a window handle for the window under the cursor.
   hTemp = DllCall(hUser32,long:"WindowFromPoint", long:nScreenX, long:nScreenY )
   while hTemp
      hParent = hTemp

      ;  Check for a popup window
      if  cWndInfo(hTemp, 20) & WS_POPUP then break  ; Found a popup windows. 

      ; Get the  parent.
      hTemp = cWndInfo(hTemp, 3)
    endwhile

    ; Get the window name, if we found something.
    if hParent then strName = cWndInfo(hParent, 0)
    else strName = "<None>"
   
    BoxText("Window name: ":strName)
   TimeDelay(0.1)

    If IsKeyDown(@shift) then break
endwhile 

DllFree(hUser32)   
exit
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

rw_baker

I tested the code that you sent on many windows and the only one that failed is the one I mentioned initially, i.e.,
message("test","message")
exit

Testing the code that you sent:
When I place the cursor over the "message" window, the code responds with: "Window Under Mouse Pointer" - not "test".

MouseInfo(1) test:
MouseInfo(1) over anywhere in the "message" window responds with the full path to the creating script.

MouseInfo(0) test:
MouseInfo(0 responds with "test" unless the cursor is over the button, then it responds with "OK".

RW Baker

rw_baker

Correction:  it works for everything I was looking at.  Interest that it still responds with "Window under Mouse Pointer" when I place the cursor
over the box in the code you wrote...probably because the box has no title!

Thanks a lot for your help,

RW Baker

td

"Window under Mouse Pointer"  is the title of the Window in the above script.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade