Zohar Posted February 22, 2015 Share Posted February 22, 2015 (edited) Hi Assume this case: I got a handle to a control, in $hControl, and I now want to use ControlGetPos(), but without supplying it again the Window Name(or class), and the Control ClassNN, but simply supplying $hControl. How can I do it? Thank you Edited February 23, 2015 by Zohar Link to comment Share on other sites More sharing options...
TheDcoder Posted February 22, 2015 Share Posted February 22, 2015 IMO Its not possible EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2015 Moderators Share Posted February 22, 2015 Zohar,Of course it is possible - complicated, but possible: #include <GUIConstantsEx.au3> #include <Array.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30) GUISetState() ; Using ControlGetPos $aControlGetPos = ControlGetPos($hGUI, "", $cButton) _ArrayDisplay($aControlGetPos, "ControlGetPos", Default, 8) ; Get handle $hHandle = GUICtrlGetHandle($cButton) ; But using WinGetPos gives you absolute coords $aWinGetPos = WinGetPos($hHandle) _ArrayDisplay($aWinGetPos, "WinGetPos - Basic", Default, 8) ; So you need to convert them to client coords Local $tPoint = DllStructCreate("int X;int Y") DllStructSetData($tPoint, "X", $aWinGetPos[0]) DllStructSetData($tPoint, "Y", $aWinGetPos[1]) _WinAPI_ScreenToClient($hGUI, $tPoint) $aWinGetPos[0] = DllStructGetData($tPoint, "X") $aWinGetPos[1] = DllStructGetData($tPoint, "Y") _ArrayDisplay($aWinGetPos, "WinGetPos - Converted", Default, 8) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndM23 TheDcoder 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
TheSaint Posted February 22, 2015 Share Posted February 22, 2015 Brings to mind a quote from somewhere. Melba23 making the impossible possible since August 2008! Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
TheDcoder Posted February 22, 2015 Share Posted February 22, 2015 Thanks Melba EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Zohar Posted February 23, 2015 Author Share Posted February 23, 2015 Hi Melba Thank you very much for the example, but I think my question was not completely understood. My appology, allow me to sharpen my explanation abit. The window is not created by me via AutoIt, but is a 3rd party application's window. Also, my question is If the ControlGetPos() function can somehow get the Handle variable as a parameter, and not to use additional code... The reason I ask this, is because I remember some years ago that I read in the Help file, that all functions of some type(I think all functions that work on a Window?) can also get a Handle, instead of the Window Title/Class. Despite the fact that I'm sure that I read it in the help, I am not able to find it now.. Anyone knows where it is written? Thank you Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 23, 2015 Moderators Share Posted February 23, 2015 Zohar,You can use a window's "handle" in place of its "title" - so in ControlGetPos you can identify the parent GUI by either. But when using that function the control must be identified by its "ControlID". So if all we have is a handle, we need to determine the ControlID - which is not very difficult as you can see: #include <GUIConstantsEx.au3> #include <Array.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30) $hHandle = GUICtrlGetHandle($cButton) ; Get control handle GUISetState() ; Using ControlID $aControlGetPos = ControlGetPos($hGUI, "", $cButton) _ArrayDisplay($aControlGetPos, "ControlID", Default, 8) ; Using handle $aControlGetPos = ControlGetPos($hGUI, "", _WinAPI_GetDlgCtrlID($hHandle)) ; Convert handle to ControlID _ArrayDisplay($aControlGetPos, "Handle", Default, 8) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndIs that what you wanted? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Trong Posted February 23, 2015 Share Posted February 23, 2015 Its not possible! without Window Name(or class), and the Control ClassNN Run("calc") WinWaitActive("Calculator") $hc = ControlGetHandle('[ACTIVE]','','Button9') $k = WinGetPos($hc) MouseClick("main",$k[0] + $k[2]/2, $k[1] + $k[3]/2) WinWaitClose("Calculator") Regards, Link to comment Share on other sites More sharing options...
Zohar Posted February 23, 2015 Author Share Posted February 23, 2015 (edited) Melba: Yes I understand now.. Thank you BTW, do you know where in the Help file it is written? (that we can replace the Window Name with the Window Handle) Trong: You didn't read the answers people wrote here if you say it's impossible Edited February 23, 2015 by Zohar Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 23, 2015 Moderators Share Posted February 23, 2015 Zohar, do you know where in the Help file it is written? (that we can replace the Window Name with the Window Handle)At the bottom of the Window Titles and Text (Advanced) page. M23 Zohar 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zohar Posted February 23, 2015 Author Share Posted February 23, 2015 At the bottom of the Window Titles and Text (Advanced) page. Right! Thank you so much Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 23, 2015 Moderators Share Posted February 23, 2015 Maybe I'm missing something? I've always just used the handle straight up. #include <GUIConstantsEx.au3> #include <Array.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30) $hHandle = GUICtrlGetHandle($cButton) ; Get control handle GUISetState() ; Using ControlID $aControlGetPos1 = ControlGetPos($hGUI, "", $cButton) _ArrayDisplay($aControlGetPos1, "ControlID", Default, 8) ; Using handle $aControlGetPos2 = ControlGetPos("", "", $hHandle) _ArrayDisplay($aControlGetPos2, "Handle1", Default, 8) $aControlGetPos3 = ControlGetPos($hHandle, "", "") _ArrayDisplay($aControlGetPos3, "Handle2", Default, 8) $aControlGetPos4 = ControlGetPos($hGUI, "", $hHandle) _ArrayDisplay($aControlGetPos4, "Handle3", Default, 8) . iamtheky 1 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...
Moderators Melba23 Posted February 23, 2015 Moderators Share Posted February 23, 2015 SmOke_N,Well, well, well. We learn something new everyday. M23 TheDcoder 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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