Jump to content

Does GUIGetCursorInfo array[4] return object?


rdwray
 Share

Recommended Posts

Is this returning an object value and not a real number:

$ID = GUIGetCursorInfo($guiMain)
Because this will cause a crash:
$ID = GUIGetCursorInfo($guiMain)
        $i = $cID[$ID[4]-2]
Or this:
$ID = GUIGetCursorInfo($guiMain)
        $i = $cID[$ID[4]]
        $i -= 2

Thanks....

Edited by rdwray

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

Where is the array $cID getting its values? If you wrote it like the following then $I will equal the control ID if any, note I did say if any because $ID[4] is only a non-zero value if the mouse is over a control that AutoIt can read.

$ID = GUIGetCursorInfo($guiMain)
$i = $ID[4]
$i -= 2

**EDIT: typos

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Where is the array $cID getting its values? If you wrote it like the following then $I will equal the control ID if any, note I did say if any because $ID[4] is only a non-zero value if the mouse is over a control that AutoIt can read.

$ID = GUIGetCursorInfo($guiMain)
$i = $ID[4]
$i -= 2

**EDIT: typos

I double checked all values and they do exist and they are in range. $cID is an array - some vaules will be null. I have got the function working with a "work around", but I am wondering what is going on. I would post the program, but it is not complete.

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

If $ID[4] = 0 then subtracting 2 from it will result in $ID[4] = -2, there's no -2 subscript in your $cID array, that will crash the script. You need to put some error checking in there before trying to use that statement. Check to see if $ID[4] is zero or not, and skip the assignment statement if it is zero.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

If $ID[4] = 0 then subtracting 2 from it will result in $ID[4] = -2, there's no -2 subscript in your $cID array, that will crash the script. You need to put some error checking in there before trying to use that statement. Check to see if $ID[4] is zero or not, and skip the assignment statement if it is zero.

$ID[4] is never less than 3 - the first control ID.

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

What does this say:

ConsoleWrite("$ID[4]: " & $ID[4] & "(" & VarGetType($ID[4]) & ")" & @CRLF)

Cannot run any code that accesses the parameter.

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

In this quote you say:

$ID[4] is never less than 3 - the first control ID.

But here you're saying:

Cannot run any code that accesses the parameter.

So, which is it? Are you able to access the value in $ID[4] and thus you know it's never less than 3, or are you saying you can't access $ID[4] and so you are assuming it's never less than 3? Either way, you need to put some error checking in there to make absolutely sure that the value in $ID[4] is greater than 2 or your script will crash.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

In this quote you say:

But here you're saying:

So, which is it? Are you able to access the value in $ID[4] and thus you know it's never less than 3, or are you saying you can't access $ID[4] and so you are assuming it's never less than 3? Either way, you need to put some error checking in there to make absolutely sure that the value in $ID[4] is greater than 2 or your script will crash.

It crashes as soon as the cursor passes over the window. Here is the actual code. I commented out the failing code - see line 95 through 116.
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so
#cs ----------------------------------------------------------------------------
 AutoIt Version: 3.3.6.1
 Author:         myName

 Script Function:
    Template AutoIt script.
#ce ----------------------------------------------------------------------------

#Include <Misc.au3>
#Include <WinAPI.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Global $x, $i, $aCtrl[27], $moved, $str
Global $dll = DllOpen("user32.dll")
; ==============================================
    $guiMain = GUICreate("ShortCutBar", 24 * 26, 24,-1,-1,BitOR($WS_POPUP,$WS_BORDER))
    GUISetFont(11, 400, 0, "Tahoma")
; ==============================================
    For $i = 1 to 26
        $aCtrl[$i] = GUICtrlCreateButton(Chr($i + 64), $x, 0, 24, 24)
        $x += 24
    Next
    GUISetState()
    $hWnd =WinGetHandle("ShortCutBar","")
; ==============================================
    $guiOpt = GUICreate("Options", 500, 330, (@DesktopWidth / 2) -250, (@DesktopHeight / 2) - 150, $WS_BORDER )
    GUISetFont(11, 400, 0, "Tahoma")
; ==============================================
    GUICtrlCreateLabel("Press Alt+F1 for help...", 20, 10)
    GUICtrlCreateLabel("Enter program path or:", 90, 40)
; ==============================================
    $browse = GUICtrlCreateButton("Browse", 280, 30)
    $file = GUICtrlCreateInput("", 90, 70, 390, 30)
; ==============================================
    GUICtrlCreateLabel("Enter name for shortcut:", 90, 110)
    $alias = GUICtrlCreateInput("", 90, 140, 390, 30)
; ==============================================
    GUICtrlCreateLabel("Select" & @CRLF & "Key", 20, 45)
    $key = GUICtrlCreateList("A", 20, 90, 50, 150)
; ==============================================
    For $i = 66 to 89
        $str &= Chr($i) & "|"
    Next
    $str &= "Z"
    GUICtrlSetData($key, $str, "A")
; ==============================================
    $showbar = GUICtrlCreateCheckbox("Show Shortcut Bar", 90, 170, 390)
    $orient = GUICtrlCreateCheckbox("Checked = Verticle; Uncheck = Horizontal", 90, 200, 390)
; ==============================================
    GUICtrlCreateLabel("Save after each change!", 150, 230)
; ==============================================
    $Save = GUICtrlCreateButton("&Save", 65, 260, 120)
    $close = GUICtrlCreateButton("&Close Options", 189, 260, 120)
    $exit = GUICtrlCreateButton("&Exit Program", 313, 260, 120)

Global $sc[27][3]
    For $i = 1 to 26    ; Must have same value as control ID or tooltip crashes program.
        $sc[$i][1] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i,  "")
        $sc[$i][2] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i,  "")
;       MsgBox(0, "", $sc[$i][1] & " : " & $sc[$i][2])      ; Test point.
    Next

Global $cID[29]
    For $i = 3 to 28    ; Must match control ID or tooltip will crash program.
        $cID[$i] = $i - 2
    Next

LoadData()

Func LoadData()
    $k = Asc(GUICtrlRead ($key)) - 64
;           MsgBox(0, "", $k )      ; Test point.

    GUICtrlSetData($file, $sc[$k][1])
    GUICtrlSetData($alias, $sc[$k][2])
EndFunc

While 1
Local $ID, $ctrl
            $moved = False

    If WinActive("ShortCutBar") Then
        If _IsPressed("01", $dll) Then RunProg()
        if _IsPressed("02", $dll) Then
            movewin($hWnd)
            If $moved = False Then GUISetState(@SW_SHOW, $guiOpt)   ; Open options window if the shortcur bar has not been moved.
        EndIf
        $ID = GUIGetCursorInfo($guiMain)
        $i = $cID[$ID[4]]   ; NO MATH CAN BE DONE ON $ID - $ID[4] is an object and contains the wrong value for the .ini position.
;===========================================
; REPLACE THIS SECTION WITH THE ONE COMMENTED OUT BELOW -->>
        If $ID[4] <> $ctrl then ; If over same button, don't get new tip. - stops flickering.
            If $sc[$i][2] <> "" Then
                ToolTip($sc[$i][2])
            Else
                ToolTip("Right click to open Options window")
            EndIf
            $ctrl = $ID[4]
        EndIf
;======================================

#cs
        If $ID[4] <> $ctrl then ; If over same button, don't get new tip. - stops flickering.
            If $sc[$i][2] <> "" Then
                ToolTip($sc[$ID[4]-2][2])
            Else
                ToolTip("Right click to open Options window")
            EndIf
            $ctrl = $ID[4]
        EndIf
#CE
    EndIf

    Switch GUIGetMsg(0)
        Case $key
            LoadData()
        Case $browse
            GUICtrlSetData($file, FileOpenDialog("Select file for shortcut", @HomeDrive, "All (*.*)", 1 ))
        Case $Save
            WriteFile()
        Case $close
            GUISetState(@SW_HIDE, $guiOpt)
        Case $exit
            GUIDelete()         ; Delete Shortcut window.
            GUISwitch($guiOpt)  ; Delete Options window.
            GUIDelete()
            Exit
    EndSwitch
WEnd

func movewin($hWnd)
Local $MousePos, $WinPos, $PosDiff[2], $WinPos2
    While 1
        $MousePos = MouseGetPos ()
        $WinPos = WinGetPos ($hWnd,"")
        $PosDiff[0] = $WinPos[0] - $MousePos[0]
        $PosDiff[1] = $WinPos[1] - $MousePos[1]
        While _IsPressed ("02", $dll)
            $MousePos = MouseGetPos ()
            WinMove ($hWnd, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
        WEnd
        Sleep (10)
        ExitLoop
    WEnd
    $WinPos2 = WinGetPos ($hWnd,"")
    If $WinPos2[0] < 0 Then WinMove("ShortCutBar", "", 0, $WinPos2[1])
    If $WinPos2[1] < 0 Then WinMove("ShortCutBar", "", $WinPos2[0], 0)

    If ($WinPos[0] <> $WinPos2[0]) Or ($WinPos[1] <> $WinPos2[1])Then
        $moved = True
    Else
        $moved = False
    EndIf
    Sleep (10)
EndFunc

Func WriteFile()

    $k = Asc(GUICtrlRead ($key)) - 64
    $sc[$k][1] = GuiCtrlRead($file)
    $sc[$k][2] = GuiCtrlRead($alias)

    For $i = 1 to 26
        IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Key" & $i,  Chr($i + 64))
        IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i,  $sc[$i][1])
        IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i,  $sc[$i][2])
    Next
EndFunc

; Try working with this one:
Func RunProg()
    $ID = GUIGetCursorInfo($guiMain)
    $i = $cID[$ID[4]]   ; NO MATH CAN BE DONE ON $ID - $ID[4] is an object and contains the wrong value for the .ini position.
    If $sc[$i][1] <> "" then ShellExecuteWait ($sc[$i][1])
EndFunc

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

I just rebooted and this is what happended using bad code.

1. Worked ok at first.

2. Right clicked (hold mouse down) to move - locked up.

3. Closed program.

4. Restarted program and it worked fine.

Time for a relaxer.....................

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

I finally got an error out of this thing:

F:\Backup\AutoItV3\Projects\ShortCutBar.au3 (131) : ==> Array variable subscript badly formatted.:

If $sc[$ID[4]-2][2] <> "" Then

If $sc[^ ERROR

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

That means that $ID[4]-2 is less than 0 or greater than the size of the array.

Add an IF test in there to check :x

If $ID[4] < 2 Or $ID[4] > UBound($a) - 3 Then ; Show an error or something like that

Got it - with the window active and the cursor not over it the value returns -2. Thanks Mat, going to get you more money

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

Mat, while I have you on the line I have a question.

If a window is inactive, a ToolTip can be detected through a window on top of it. I use WinActive to solve this problem, but it causes another problem in that if the window is visable, and not active, the tooltip will not work. How can I solve this? Thanks...

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

I'm not sure what you mean... What window?

If I remove "WinActive("ShortCutBar") And" from the following example, I can place any window in from of "ShortCutBar" and read the tooltips through the window.
If WinActive("ShortCutBar") And $ID[4]-2 <> -2 Then
        If _IsPressed("01", $dll) Then RunProg()
        if _IsPressed("02", $dll) Then
            MoveWin($hWnd)
            If $moved = False Then GUISetState(@SW_SHOW, $guiOpt)   ; Open options window if the shortcur bar has not been moved.
            $ID = GUIGetCursorInfo($guiMain)
            GUICtrlSetData($key, Chr($ID[4] + 62))
        EndIf
;===========================================
        If $ID[4] <> $ctrl then ; If over same button, don't get new tip. - stops flickering.
            If $sc[$ID[4]-2][2] <> "" Then
                ToolTip($sc[$ID[4]-2][2])
            Else
                ToolTip("Right click to open Options window")
            EndIf
            $ctrl = $ID[4]
        EndIf
    Else
        ToolTip("")
    EndIf

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...