Jump to content

Advice mode from mouse position


Recommended Posts

Yes :

#include <Constants.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <WinAPISysWin.au3>
#include <APISysConstants.au3>

Opt("MustDeclareVars", 1)

HotKeySet("{ESC}", _Exit)

Example()

Func Example()
  Local $hWnd, $tPoint = DllStructCreate($tagPOINT)
  Local $hTarget, $sClass, $sClassList, $iInstance, $hCtrl
  While 1
    $tPoint.X = MouseGetPos(0)
    $tPoint.Y = MouseGetPos(1)
    $hTarget = _WinAPI_WindowFromPoint($tPoint)
    $sClass = _WinAPI_GetClassName($hTarget)
    $hWnd = _WinAPI_GetAncestor($hTarget, $GA_ROOT)
    ConsoleWrite($hWnd & "/" & $hTarget & "/" & $sClass)
    If $hWnd <> $hTarget And $sClass <> "" Then
      $sClassList = WinGetClassList($hWnd)
      StringReplace($sClassList, $sClass, $sClass)
      $iInstance = @extended
      ConsoleWrite("(" & $iInstance & ") ")
      For $i = 1 To $iInstance
        $hCtrl = ControlGetHandle($hWnd, "", $sClass & $i)
        If $hCtrl = $hTarget Then
          ConsoleWrite(" [CLASS:" & $sClass & "; INSTANCE:" & $i & "]")
          ExitLoop
        EndIf
      Next
    EndIf
    ConsoleWrite(@CRLF)
    Sleep(500)
  WEnd
EndFunc   ;==>Example

Func _Exit()
  Exit
EndFunc   ;==>_Exit

 

Link to post
Share on other sites

Let me review my previous post.  After playing with it, I noticed that it was not able to detect disabled controls.  So here a new version :

#include <Constants.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <WinAPISysWin.au3>
#include <APISysConstants.au3>
#include <WinAPIConv.au3>

Opt("MustDeclareVars", 1)

HotKeySet("{ESC}", _Exit)

Example()

Func Example()
  Local $hWnd, $tPoint = DllStructCreate($tagPOINT)
  Local $hTarget, $sClass, $sClassList, $iInstance, $hCtrl
  While 1
    $tPoint.X = MouseGetPos(0)
    $tPoint.Y = MouseGetPos(1)
    $hTarget = _WinAPI_WindowFromPoint($tPoint)
    $hWnd = _WinAPI_GetAncestor($hTarget, $GA_ROOT)
    If $hTarget = $hWnd Then
      _WinAPI_ScreenToClient($hWnd, $tPoint)
      $hTarget = _WinAPI_ChildWindowFromPointEx ($hWnd, $tPOINT)
    EndIf
    $sClass = _WinAPI_GetClassName($hTarget)
    ConsoleWrite ($hWnd & "/" & $hTarget & "/" & $sClass)
    If $hWnd <> $hTarget And $sClass <> "" Then
      $sClassList = WinGetClassList($hWnd)
      StringReplace($sClassList, $sClass, $sClass)
      $iInstance = @extended
      ConsoleWrite ("(" & $iInstance & ") ")
      For $i = 1 To $iInstance
        $hCtrl = ControlGetHandle($hWnd, "", $sClass & $i)
        If $hCtrl = $hTarget Then
          ConsoleWrite (" [CLASS:"  & $sClass & "; INSTANCE:" & $i & "]")
          ExitLoop
        EndIf
      Next
    EndIf
    ConsoleWrite (@CRLF)
    Sleep(500)
  WEnd
EndFunc   ;==>Example

Func _Exit()
  Exit
EndFunc   ;==>_Exit

I could have modified the previous post, but I thought you would prefer a new snippet so you can compare and study the changes made.

Link to post
Share on other sites
Just now, Asaf_Ank said:

Is it possible to do it in C#?

Meh ?  It is an AutoIt forum here not a C# !

But to answer your question : yes.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...