Floppy Posted January 18, 2009 Share Posted January 18, 2009 (edited) Hello, is there a way to know the control type hovered by mouse? For example, if the mouse is over a button...then, the script return $button...if is over an edit...return $edit Thanks and bye! # Sorry for english # Edited January 18, 2009 by FSoft Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 18, 2009 Moderators Share Posted January 18, 2009 http://www.autoitscript.com/forum/index.ph...st&p=629237http://www.autoitscript.com/forum/index.ph...c=30717&hl= 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. Link to comment Share on other sites More sharing options...
Floppy Posted January 18, 2009 Author Share Posted January 18, 2009 http://www.autoitscript.com/forum/index.ph...st&p=629237 http://www.autoitscript.com/forum/index.ph...c=30717&hl= I'm tried with this script: #include <ControlPos.au3> #include <GuiConstants.au3> $w=GUICreate("Test") $b1=GUICtrlCreateButton("Test",50,10,100,100) $b2=GUICtrlCreateButton("Test",50,150,100,100) GUISetState() while 1 $m=GUIGetMsg() Select Case $m=$gui_event_close ExitLoop Case $m=$b1 MsgBox(0,"",_CtrlGetByPos($w)) EndSelect WEnd But, when I click on the button 1, the message box text is "0". Why? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 18, 2009 Moderators Share Posted January 18, 2009 I'm tried with this script: #include <ControlPos.au3> #include <GuiConstants.au3> $w=GUICreate("Test") $b1=GUICtrlCreateButton("Test",50,10,100,100) $b2=GUICtrlCreateButton("Test",50,150,100,100) GUISetState() while 1 $m=GUIGetMsg() Select Case $m=$gui_event_close ExitLoop Case $m=$b1 MsgBox(0,"",_CtrlGetByPos($w)) EndSelect WEnd But, when I click on the button 1, the message box text is "0". Why?You have to read how to use functions in order to get the right results 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. Link to comment Share on other sites More sharing options...
ProgAndy Posted January 18, 2009 Share Posted January 18, 2009 (edited) I think, you wnat something like this? ( It is the same like the first link from SmOke_N, but with WinAPI.au3)#include <WinAPI.au3> While 1 Sleep(40) $tPoint = _WinAPI_GetMousePos() $hWnd = _WinAPI_WindowFromPoint($tPoint) $ClassName = _WinAPI_GetClassName($hWnd) ToolTip($ClassName,Default,Default,"ClassName: ") WEnd Edited January 18, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 18, 2009 Share Posted January 18, 2009 Try this example, it shows the CLASS Name of hovered windows/controls: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> ; HotKeySet("{Esc}", "Quit") Global $hLast_Hovered_Wnd = 0 GUICreate("Hovered CLASS Name Example", 300, 150, -1, -1, -1, $WS_EX_TOPMOST) GUICtrlCreateButton("Button", 20, 20, 60, 20) GUICtrlCreateCheckbox("Checkbox", 100, 20) GUICtrlCreateEdit("", 20, 50, 150, 60) GUISetState() AdlibEnable("_CheckHoveredClassName_Proc", 300) While 1 $aMsg = GUIGetMsg() Switch $aMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _CheckHoveredClassName_Proc() $hHovered_Wnd = _WinGetHoveredHandle() $hHovered_ParentWnd = _WinAPI_GetAncestor($hHovered_Wnd, 2) ;To get properly CLASSNN with non active windows ;If $hLast_Hovered_Wnd <> $hHovered_Wnd Then ToolTip(StringFormat("hWnd: %s\r\nCLASSNN: %s", _ $hHovered_Wnd, _WinGetClassNameNN($hHovered_Wnd, $hHovered_ParentWnd)), _ Default, Default, "Hovered CLASSNN Info", 1, 5) $hLast_Hovered_Wnd = $hHovered_Wnd ;EndIf EndFunc Func _WinGetHoveredHandle() Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1) Local $Ret = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) Opt("MouseCoordMode", $iOld_Opt_MCM) Return HWnd($Ret[0]) EndFunc Func _WinGetClassNameNN($hCtrlWnd, $hWinWnd="") $hCtrlWnd = ControlGetHandle($hWinWnd, "", $hCtrlWnd) $sClassName = _WinGetClassName($hCtrlWnd) $aClassList = StringSplit(WinGetClassList($hWinWnd), @CRLF) For $i In $aClassList If $i = $sClassName Then For $j = 1 To UBound($aClassList) If ControlGetHandle($hWinWnd, "", $i & $j) = $hCtrlWnd Then Return $i & $j Next EndIf Next Return $sClassName EndFunc Func _WinGetClassName($hWnd) Local $aClassName = DLLCall("user32.dll", "int", "GetClassName", "hWnd", $hWnd, "str", "", "int", 256) If Not @error And $aClassName[0] <> 0 Then Return $aClassName[2] Return @error EndFunc Func Quit() Exit EndFunc  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Floppy Posted January 18, 2009 Author Share Posted January 18, 2009 (edited) You have to read how to use functions in order to get the right results Yes, however now I'm read the script with more attention; and I see that the script description is: Get the Control ID or the ClassNameNN by the X and Y client coordinatesBut I don't want the Control ID...I want a script that tells me only if the control hovered by mouse is a button or an edit or a label, etc...I don't want to know the class, the handle and others... Edited January 18, 2009 by FSoft Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 18, 2009 Moderators Share Posted January 18, 2009 Yes, however now I'm read the script with more attention; and I see that the script description is: Get the Control ID or the ClassNameNN by the X and Y client coordinatesBut I don't want the Control ID...I want a script that tells me only if the control hovered by mouse is a button or an edit or a label, etc...I don't want to know the class, the handle and others...is there a way to know the control type hovered by mouse?Was I supposed to interpret this correctly and magically know exactly what you were talking about?It returns the ClassNameNN as well if you choose, which will in fact give the type of control that it is. What you do with that information is locked away in your own mind somewhere I'm sure. 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. Link to comment Share on other sites More sharing options...
Andreik Posted January 18, 2009 Share Posted January 18, 2009 Yes, however now I'm read the script with more attention; and I see that the script description is: Get the Control ID or the ClassNameNN by the X and Y client coordinates But I don't want the Control ID... I want a script that tells me only if the control hovered by mouse is a button or an edit or a label, etc... I don't want to know the class, the handle and others...MrCreatoR solve your problem, I change very little his script: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> ; HotKeySet("{Esc}", "Quit") Global $hLast_Hovered_Wnd = 0 GUICreate("Hovered CLASS Name Example", 300, 150, -1, -1, -1, $WS_EX_TOPMOST) GUICtrlCreateButton("Button", 20, 20, 60, 20) GUICtrlCreateCheckbox("Checkbox", 100, 20) GUICtrlCreateEdit("", 20, 50, 150, 60) GUISetState() AdlibEnable("_CheckHoveredClassName_Proc", 300) While 1 $aMsg = GUIGetMsg() Switch $aMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _CheckHoveredClassName_Proc() $hHovered_Wnd = _WinGetHoveredHandle() $hHovered_ParentWnd = _WinAPI_GetAncestor($hHovered_Wnd, 2);To get properly CLASSNN with non active windows $WIN_CLASS = _WinGetClassNameNN($hHovered_Wnd, $hHovered_ParentWnd) ToolTip(StringRegExpReplace($WIN_CLASS,"\d",""),Default,Default,"Control Type") $hLast_Hovered_Wnd = $hHovered_Wnd EndFunc Func _WinGetHoveredHandle() Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1) Local $Ret = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) Opt("MouseCoordMode", $iOld_Opt_MCM) Return HWnd($Ret[0]) EndFunc Func _WinGetClassNameNN($hCtrlWnd, $hWinWnd="") $hCtrlWnd = ControlGetHandle($hWinWnd, "", $hCtrlWnd) $sClassName = _WinGetClassName($hCtrlWnd) $aClassList = StringSplit(WinGetClassList($hWinWnd), @CRLF) For $i In $aClassList If $i = $sClassName Then For $j = 1 To UBound($aClassList) If ControlGetHandle($hWinWnd, "", $i & $j) = $hCtrlWnd Then Return $i & $j Next EndIf Next Return $sClassName EndFunc Func _WinGetClassName($hWnd) Local $aClassName = DLLCall("user32.dll", "int", "GetClassName", "hWnd", $hWnd, "str", "", "int", 256) If Not @error And $aClassName[0] <> 0 Then Return $aClassName[2] Return @error EndFunc Func Quit() Exit EndFunc When the words fail... music speaks. Link to comment Share on other sites More sharing options...
ProgAndy Posted January 18, 2009 Share Posted January 18, 2009 (edited) I want a script that tells me only if the control hovered by mouse is a button or an edit or a label, etc...I don't want to know the class, the handle and others...That's exactly what i wrote in Post #5 Edited January 18, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Floppy Posted January 18, 2009 Author Share Posted January 18, 2009 MrCreatoR solve your problem, I change very little his script: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> ; HotKeySet("{Esc}", "Quit") Global $hLast_Hovered_Wnd = 0 GUICreate("Hovered CLASS Name Example", 300, 150, -1, -1, -1, $WS_EX_TOPMOST) GUICtrlCreateButton("Button", 20, 20, 60, 20) GUICtrlCreateCheckbox("Checkbox", 100, 20) GUICtrlCreateEdit("", 20, 50, 150, 60) GUISetState() AdlibEnable("_CheckHoveredClassName_Proc", 300) While 1 $aMsg = GUIGetMsg() Switch $aMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _CheckHoveredClassName_Proc() $hHovered_Wnd = _WinGetHoveredHandle() $hHovered_ParentWnd = _WinAPI_GetAncestor($hHovered_Wnd, 2);To get properly CLASSNN with non active windows $WIN_CLASS = _WinGetClassNameNN($hHovered_Wnd, $hHovered_ParentWnd) ToolTip(StringRegExpReplace($WIN_CLASS,"\d",""),Default,Default,"Control Type") $hLast_Hovered_Wnd = $hHovered_Wnd EndFunc Func _WinGetHoveredHandle() Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1) Local $Ret = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) Opt("MouseCoordMode", $iOld_Opt_MCM) Return HWnd($Ret[0]) EndFunc Func _WinGetClassNameNN($hCtrlWnd, $hWinWnd="") $hCtrlWnd = ControlGetHandle($hWinWnd, "", $hCtrlWnd) $sClassName = _WinGetClassName($hCtrlWnd) $aClassList = StringSplit(WinGetClassList($hWinWnd), @CRLF) For $i In $aClassList If $i = $sClassName Then For $j = 1 To UBound($aClassList) If ControlGetHandle($hWinWnd, "", $i & $j) = $hCtrlWnd Then Return $i & $j Next EndIf Next Return $sClassName EndFunc Func _WinGetClassName($hWnd) Local $aClassName = DLLCall("user32.dll", "int", "GetClassName", "hWnd", $hWnd, "str", "", "int", 256) If Not @error And $aClassName[0] <> 0 Then Return $aClassName[2] Return @error EndFunc Func Quit() Exit EndFunc The script is good...but not correct because the checkbox tooltip is "Button" and not "Checkbox"! Link to comment Share on other sites More sharing options...
Kip Posted January 18, 2009 Share Posted January 18, 2009 And both label and picture are "Static". MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 18, 2009 Moderators Share Posted January 18, 2009 @FSoft (and others if need be). You seem to need to do some homework on MSDN if you are confused on why the results returned are "Static" or "Button" for different types of controls. If you need it to be very specific, then "You" yourself will need to write something that has a base of what the control id is: eg... $a_mycontrol[3][2] = [[1, "Button"], etc...] This way you can use the control ID to tell what the control type is in your script. But for all sakes and aguments ... A label is Static, a image is Static, a Checkbox is a Button, ... Hell, even an Input is an Edit... so get to scripting ... @FSoft, when responding to those helping you, don't be a stupid and put exclamations and italics around things (without an explanation) unless you want them to be considered insulting. You'll lose any future help you could hope to gain here that way. 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. Link to comment Share on other sites More sharing options...
Floppy Posted January 19, 2009 Author Share Posted January 19, 2009 (edited) @FSoft, when responding to those helping you, don't be a stupid and put exclamations and italics around things (without an explanation) unless you want them to be considered insulting. You'll lose any future help you could hope to gain here that way.Sorry, but you live in another country that it isn't ItalyIn Italy there's a proverb: Paese che vai, usanza che trovi! that (more or less) in english means: In each country you go, there are different customs!Regarding the exclamations and italics (and others), we use it in Italy to highlight something and not to insult someone...bye Edited January 19, 2009 by FSoft Link to comment Share on other sites More sharing options...
Kip Posted January 19, 2009 Share Posted January 19, 2009 Regarding the exclamations and italics (and others), we use it in Italy to highlight something and not to insult someone...Welcome to these English forums! MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
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