Jump to content
Bilgus

GUIGetCursorInfo help entry wrong or at best ambiguously worded

Recommended Posts

Bilgus

I was messing with a double window gui  and found GUIGetCursorInfo() not to work as expected

winhandle [optional] The handle of the window to use. If omitted the "current" window will be used.

so what does "current" window mean its surely not the active window?

In this case its the last created window

I think the documentation should at least be:

winhandle [optional] Windows handle as returned by GUICreate() (default is the previously used window).

https://www.autoitscript.com/autoit3/docs/functions/GUIGetCursorInfo.htm

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)
Global $g_idX1 = 0, $g_idY1 = 0, $g_idX2 = 0, $g_idY2 = 0
Global $g_idB1, $g_idB2
Global $hWnd1, $hWnd2

Example()

Func Example()

    $hWnd1 = GUICreate("#1 Click to Get Pos", 400, 400, 100, 100)
    $g_idX1 = GUICtrlCreateLabel("0", 10, 10, 50)
    $g_idY1 = GUICtrlCreateLabel("0", 40, 10, 50)
    $g_idB1 = GUICtrlCreateButton("Window1", 10, 30)
    GUISetOnEvent($GUI_EVENT_CLOSE, _Exit, $hWnd1)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, GetPos, $hWnd1)
    GUISetState(@SW_SHOW)

    $hWnd2 = GUICreate("#2 Click to Get Pos", 400, 400, 200, 200)
    $g_idX2 = GUICtrlCreateLabel("0", 10, 10, 50)
    $g_idY2 = GUICtrlCreateLabel("0", 40, 10, 50)
    $g_idB2 = GUICtrlCreateButton("Window2", 10, 30)
    GUISetOnEvent($GUI_EVENT_CLOSE, _Exit, $hWnd2)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, GetPos, $hWnd2)
    GUISetState(@SW_SHOW)

    ; Loop Forever
    While 1
        Sleep(100000)
    WEnd


EndFunc   ;==>Example

Func GetPos()
    Local $hWndActive = WinActive("")
    Local $sWindow, $a
    $a = GUIGetCursorInfo()
    ;$a = GUIGetCursorInfo(WinActive(""));Works

    If @error Or Not IsArray($a) Then Local $a[5] = [-1, -1, -1, -1, -1]

    If $hWndActive = $hWnd1 Then
        $sWindow = "#1"
        GUICtrlSetData($g_idX1, $a[0])
        GUICtrlSetData($g_idY1, $a[1])
    ElseIf $hWndActive = $hWnd2 Then
        $sWindow = "#2"
        GUICtrlSetData($g_idX2, $a[0])
        GUICtrlSetData($g_idY2, $a[1])
    Else
        $sWindow = "N/A"
    EndIf
    ConsoleWrite("Window " & $sWindow & " is active" & @CRLF)
    If IsArray($a) Then ConsoleWrite("Control Id = " & $a[4] & @CRLF)

EndFunc   ;==>GetPos

Func _Exit()
    GUIDelete()
    Exit
EndFunc   ;==>_Exit

It goes on further to state

Quote

If the "winhandle" parameter is used then the specified window becomes the new "current" window.

Even thats not true, if so this should fail for window #2 instead you'd need to call GUISwitch ($hWnd1)

Func GetPos()
    Local $hWndActive = WinActive("")
    Local $sWindow, $a
    ;$a = GUIGetCursorInfo()
    $a = GUIGetCursorInfo($hWnd1)
    ;$a = GUIGetCursorInfo(WinActive(""));Works

    If @error Or Not IsArray($a) Then Local $a[5] = [-1, -1, -1, -1, -1]

    If $hWndActive = $hWnd1 Then
        $sWindow = "#1"
        GUICtrlSetData($g_idX1, $a[0])
        GUICtrlSetData($g_idY1, $a[1])
    ElseIf $hWndActive = $hWnd2 Then
        $a = GUIGetCursorInfo()
        $sWindow = "#2"
        GUICtrlSetData($g_idX2, $a[0])
        GUICtrlSetData($g_idY2, $a[1])
    Else
        $sWindow = "N/A"
    EndIf
    ConsoleWrite("Window " & $sWindow & " is active" & @CRLF)
    If IsArray($a) Then ConsoleWrite("Control Id = " & $a[4] & @CRLF)

EndFunc   ;==>GetPos

 

Share this post


Link to post
Share on other sites
Melba23

Bilgus,

The term "current" to describe the GUI in which controls will be created (usually the last created unless changed via GUISwitch) is used throughout the Help file, but I agree it could be clearer. And I concur that the "current" GUI is not reset when you use GUIGetCursorInfo:

#include <GUIConstantsEx.au3>

$hGUI_L = GUICreate("Test_L", 200, 200, 100, 100)

GUISetState()

$hGUI_R = GUICreate("Test_R", 200, 200, 400, 100)

GUISetState()

; Last created is "current" GUI, so controls are created within it
$cLabel_1 = GUICtrlCreateLabel("In Test_R", 10, 10, 150, 30)

; Move mouse to GUI_L
MouseMove(200, 200)

; Get info with no handle
$aInfo = GUIGetCursorInfo()
; And with no handle we get info for "current" GUI - GUI_R
ConsoleWrite($aInfo[0] & @CRLF)

; Get info with handle
$aInfo = GUIGetCursorInfo($hGUI_L)
; And we get from GUI_L
ConsoleWrite($aInfo[0] & @CRLF)

; But which is the current GUI now?
GUICtrlCreateLabel("Is this in Test_L?", 10, 40, 150, 30)

; Set it to GUI_L
GUISwitch($hGUI_L)
GUICtrlCreateLabel("In Test_L now!", 10, 40, 150, 30)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

I will amend the Help file accordingly - thanks for the report.

In future, could you please raise such matters using Trac - it makes it much easier to follow and all the Devs get to see it.

M23

  • Thanks 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


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

×