Laetterman Posted September 26, 2006 Posted September 26, 2006 Using the following script there is always a 'beep', when the mouse is over a little window. This does not change when there is another window (eg the explorer) in the foreground of this win. I'd like to have a 'beep' only when the mouse is over a port of the window, which can be seen by the user. #include <GUIConstants.au3> GUICreate("Win1", 100, 100, 500, 500) GUISetState (@SW_SHOW) While 1 If _IsMouseOverControl("Win1","") Then Beep(440, 10) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend Func _IsMouseOverControl($WinTitle,$WinText) $C = WinGetPos($WinTitle,$WinText) If @error Then SetError(-1) Return 0 Else $C_X = $C[0] $C_Y = $C[1] $C_Width = $C[2] $C_Height = $C[3] $M = MouseGetPos() $M_X = $M[0] $M_Y = $M[1] If (($M_X >= $C_X And $M_X <= $C_X + $C_Width) And ($M_Y >= $C_Y And $M_Y <= $C_Y + $C_Height)) Then Return 1 Else Return 0 EndIf EndIf EndFunc Any Ideas? Laetterman
Moderators SmOke_N Posted September 26, 2006 Moderators Posted September 26, 2006 #include <GUIConstants.au3> $Main = GUICreate("Win1", 100, 100, 500, 500) $Button1 = GUICtrlCreateButton('Button1', 25, 25, 50, 30) $Button2 = GUICtrlCreateButton('Button2', 25, 25, 50, 30) GUICtrlSetState($Button1, $GUI_HIDE) GUISetState (@SW_SHOW) While 1 If _MouseHover($Main, $Button2) Then Beep(440, 10) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend Func _MouseHover($hWnd, $iCID, $iIsVisible = 80) Local $aGGCI = GUIGetCursorInfo(HWnd($hWnd)) If GUICtrlGetState($iCID) = $iIsVisible And _ IsArray($aGGCI) And _ $aGGCI[4] = $iCID Then Return SetError(0, 0, 1) Return SetError(1, 0, 0) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Laetterman Posted September 26, 2006 Author Posted September 26, 2006 Thank you but it's not exactly what I need. It only works if the window with the Button has the focus and is in the foreground. I'm looking for a 'beep' if the mouse hovers a control which can be seen with the eyes, no matter if the window is the active one or not.
Moderators SmOke_N Posted September 26, 2006 Moderators Posted September 26, 2006 Thank you but it's not exactly what I need. It only works if the window with the Button has the focus and is in the foreground. I'm looking for a 'beep' if the mouse hovers a control which can be seen with the eyes, no matter if the window is the active one or not.Here, you can write it...CtrlGetPos() Then Convert to Screen Coords Then use MouseGetPos() Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
martin Posted September 26, 2006 Posted September 26, 2006 (edited) Here, you can write it...CtrlGetPos() Then Convert to Screen Coords Then use MouseGetPos()I don't know how to do this but I think it's a bit more difficult than SmOke_N suggests. The value returned by GUICtrlGetState($iCID) is only related to whether the control is set to visible on the parent window and in the example it will always be 80 even if the button is covered by another application. Finding the mouse coordinates will therefor not help untill you have some way of knowing that the button can actually be seen. Over to someone at a higher level than me. Edited September 26, 2006 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Laetterman Posted September 26, 2006 Author Posted September 26, 2006 Yes, that is what I think too. Any other ideas?
martin Posted September 30, 2006 Posted September 30, 2006 Yes, that is what I think too. Any other ideas?No many. But in Delphi, and probably other languages, it's very easy to do what you want using onmousemove for the button. If you could find the z order of froms on the desktop then in theory you could work out if the button was visible,.. but this sounds very difficult to me.There's probably an easy way to do it and now that I've bumped this maybe someone will tell you. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Valuater Posted September 30, 2006 Posted September 30, 2006 (edited) _ControlHover() UDFis your friendhttp://www.autoitscript.com/forum/index.ph...st&p=240145be sure to use[preferred] - Window handle to save CPU usage and speed of _ControlHover(); - and Avoid array errors for "non-active window"8) Edited September 30, 2006 by Valuater
Moderators SmOke_N Posted September 30, 2006 Moderators Posted September 30, 2006 No many. But in Delphi, and probably other languages, it's very easy to do what you want using onmousemove for the button. If you could find the z order of froms on the desktop then in theory you could work out if the button was visible,.. but this sounds very difficult to me.There's probably an easy way to do it and now that I've bumped this maybe someone will tell you.I mis-understood the question the first time I think. And this question has been asked before.Unfortunately, I have to agree it isn't the easiest thing in the world. Off the top of my head, you would have to get every window not minimized, find their xstarting/ystarting | xending/yending with WinGetPos(), calculate with ControlGetPos() + Conversion to Screen Coords, and verify that none of the windows are overlapping the control entirely.Out of curiousity though, what is such a function necessary for? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Valuater Posted September 30, 2006 Posted September 30, 2006 I am sure _ControlHover will do this for you 8)
martin Posted September 30, 2006 Posted September 30, 2006 (edited) I am sure _ControlHover will do this for you8)Well maybe you are sure but I don't think you have tried it. Unfortunately it tells you when the mouse is over the control whether or not there is another form hiding it. Edited September 30, 2006 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Laetterman Posted October 4, 2006 Author Posted October 4, 2006 yupp, _ControlHover doesn't recognize if there is another window between control and user. So it's like _IsMouseOverControl from the beginning of the topic... what a bummer! but thanx nethertheless!!!
Valuater Posted October 4, 2006 Posted October 4, 2006 prooof... #include <GUIConstants.au3> #include <_ControlHover.au3> $Win = GUICreate("Win1", 120, 100, 500, 500) $control = GUICtrlCreateLabel( " a label / control ", 20, 20, 100, 20) GUISetState (@SW_SHOW) _ControlHover( 2, "", $control) While 1 If _ControlHover(0, $Win ) And @extended = $control Then Beep(440, 10) If _ControlHover(1, $Win ) And @extended = $control Then MsgBox(64,"Test", "You clicked the label / control ", 2) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend 8)
martin Posted October 4, 2006 Posted October 4, 2006 (edited) prooof... What is this proof of? It doesn't do what is wanted, ie beep when the mouse is over the label if a part of the form is covered by another form. But that has already been established a few posts ago. In the case of a button, it will still become highlit when the mouse is over it even if part of the form is covered, so how do you find when the button is highlit? Or is that just asking the original question another way? Edited October 4, 2006 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Valuater Posted October 4, 2006 Posted October 4, 2006 (edited) it covered this portion...Using the following script there is always a 'beep', when the mouse is over a little window. This does not change when there is another window (eg the explorer) in the foreground of this win.and your right... not this ....I'd like to have a 'beep' only when the mouse is over a port of the window, which can be seen by the user.But.... it did answer this....yupp, _ControlHover doesn't recognize if there is another window between control and user. So it's like _IsMouseOverControl from the beginning of the topic... what a bummer! but thanx nethertheless!!! and that is what i responded to... is that ok with you?8) Edited October 4, 2006 by Valuater
martin Posted October 4, 2006 Posted October 4, 2006 it covered this portion...and your right... not this ....But.... it did answer this.... and that is what i responded to... is that ok with you?8)Fine, I only wondered what it is was proof of, very sorry if I upset you. For people like me with very small brains it would be helpful to add a bit more explanation maybe so that the point you are making is clear.I think the tone of my post came out wrong. Humble apologies. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
martin Posted October 5, 2006 Posted October 5, 2006 (edited) This problem can be solved using a post by Larry where he has used WindowFromPoint to give the topmost control at a position.Here is a simple demo expandcollapse popup#include <GUIConstants.au3> #include <_ControlHover.au3> $mygui = GUICreate("Hover - Button") $Button_1 = GUICtrlCreateButton ("Button 1", 50, 30, 100, 20) $lab1 = GUICtrlCreateLabel('x=dsscs',50,130,100,15) GUISetState() $GuiHnd = GUICtrlGetHandle ($Button_1) $dll = dllopen("user32.dll") While 1 $msg1 = GUIGetMsg() If $msg1 = $GUI_EVENT_CLOSE Then ExitLoop EndIf if WindowFromPoint() = $GuiHnd then Beep(500,40) WEnd dllclose($dll) Func WindowFromPoint() Local $point, $cHwnd, $hwnd, $pos, $size $point = MouseGetPos() $hwnd = DLLCall($dll, "hwnd", "WindowFromPoint", "int", $point[0], "int", $point[1]) If $hwnd[0] <> 0 Then $pos = WinGetPos($hwnd[0]) If @error Then Return 0 $size = WinGetClientSize($hwnd[0]) If @error Then Return 0 $pos[0] += (($pos[2] - $size[0]) / 2) $pos[1] += (($pos[3] - $size[1]) - (($pos[2] - $size[0]) / 2)) $cHwnd = DLLCall($dll,"hwnd","RealChildWindowFromPoint","hwnd",$hwnd[0], _ "int",$point[0] - $pos[0],"int",$point[1] - $pos[1]) If $cHwnd[0] <> 0 Then $hwnd[0] = $cHwnd[0] EndIf Return $hwnd[0] EndFunc Edited October 5, 2006 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Laetterman Posted October 9, 2006 Author Posted October 9, 2006 That is what I was looking for, Great! Many thanx to martin
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