antonioj84 Posted February 23, 2015 Posted February 23, 2015 (edited) I am trying to run that code that was posted previously , I made little modification no luck so far http://www.autoitscript.com/forum/index.php?showtopic=88082&st=0&p=632463&#entry632463 Basically open calculator if button "=" is clicked then I just need a message box to popup expandcollapse popup#include <Misc.au3> #include <WinAPI.au3> ; Global $hUser32_Dll = DllOpen("User32.dll") HotKeySet("^e", "_Quit") While 1 If _IsPressed("01", $hUser32_Dll) Then ;Waiting untill the button is released While _IsPressed("01", $hUser32_Dll) Sleep(10) WEnd $hWindow = _WinGetHoveredHandle() $iCtrlID = _ControlGetHoveredID() $sWinClass = _WinAPI_GetClassName($hWindow) $sCtrlData = ControlGetText($hWindow, "", $iCtrlID) If $sWinClass = "CalcFrame" And $iCtrlID = 121 And $sCtrlData = "=" Then $sResult = Number(ControlGetText($hWindow, "", "Edit1")) ToolTip("The result has been calculated: " & $sResult, Default, Default, "Calc Info", 1, 5) Else ToolTip("") EndIf EndIf Sleep(10) WEnd Func _ControlGetHoveredID() Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1) Local $hRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) $hRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hRet[0]) If $hRet[0] < 0 Then $hRet[0] = 0 Opt("MouseCoordMode", $iOld_Opt_MCM) Return $hRet[0] EndFunc Func _WinGetHoveredHandle() Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1) Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) Opt("MouseCoordMode", $iOld_Opt_MCM) $aRet = DllCall("User32.dll", "hwnd", "GetAncestor", "hwnd", $aRet[0], "uint", 2) ;$GA_ROOT Return HWnd($aRet[0]) EndFunc Func _Quit() DllClose($hUser32_Dll) Exit EndFunc Edited February 24, 2015 by antonioj84
johnmcloud Posted February 24, 2015 Posted February 24, 2015 Happy now? expandcollapse popup; Originally made by MrCreatoR - Updated by Johnmcloud 2015 #include <WinAPI.au3> #include <Misc.au3> HotKeySet("{ESC}","_Exit") Global $hWindow, $iCtrlID, $sWinClass, $sResult, $fToolTip = False Global $hUser32_Dll = DllOpen("user32.dll") Run("calc.exe") WinWait("[CLASS:CalcFrame]") While 1 If _IsPressed("0D", $hUser32_Dll) Then While _IsPressed("0D", $hUser32_Dll) ;Waiting until the button is released Sleep(10) WEnd If WinActive("[CLASS:CalcFrame]") And Not $fToolTip Then $sResult = WinGetText($hWindow) ToolTip("The result has been calculated: " & $sResult, Default, Default, "Calc Info", 1, 5) $fToolTip = True ElseIf $fToolTip Then ToolTip("") $fToolTip = False EndIf EndIf If _IsPressed("01", $hUser32_Dll) Then While _IsPressed("01", $hUser32_Dll) ;Waiting until the button is released Sleep(10) WEnd $hWindow = _WinGetHoveredHandle() $iCtrlID = _ControlGetHoveredID() $sWinClass = _WinAPI_GetClassName($hWindow) If $sWinClass = "CalcFrame" And $iCtrlID = 121 And Not $fToolTip Then $sResult = WinGetText($hWindow) ToolTip("The result has been calculated: " & $sResult, Default, Default, "Calc Info", 1, 5) $fToolTip = True ElseIf $fToolTip Then ToolTip("") $fToolTip = False EndIf EndIf Sleep(10) WEnd Func _ControlGetHoveredID() Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1) Local $hRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) $hRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hRet[0]) If $hRet[0] < 0 Then $hRet[0] = 0 Opt("MouseCoordMode", $iOld_Opt_MCM) Return $hRet[0] EndFunc Func _WinGetHoveredHandle() Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1) Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) Opt("MouseCoordMode", $iOld_Opt_MCM) $aRet = DllCall("User32.dll", "hwnd", "GetAncestor", "hwnd", $aRet[0], "uint", 2) ;$GA_ROOT Return HWnd($aRet[0]) EndFunc Func _Exit() DllClose($hUser32_Dll) Exit EndFunc Edit your post and use the CODE tags, that cool button with the symbol of Autoit, under the Smiley antonioj84 1
Solution antonioj84 Posted February 24, 2015 Author Solution Posted February 24, 2015 Johnmcloud , works like a charm, you are a life saver thanks
mattschinkel Posted March 7, 2015 Posted March 7, 2015 Thanks antonioj84 for bringing up my old tread which resulted in an answer to my 6 year old question!
Champak Posted November 26, 2016 Posted November 26, 2016 I'm trying to use a variation of this. My issue is my external app is an autoit window and the class is useless because of that...unless there is a way to set the window class that I haven't found. How can I get the return to be the actual window title instead of the window class? Thanks.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now